packages feed

cacophony-0.7.0: benchmarks/Types.hs

{-# LANGUAGE RankNTypes, KindSignatures, GADTs #-}
module Types where

import Data.ByteString.Char8 (unpack)

import Crypto.Noise.Cipher
import Crypto.Noise.Cipher.ChaChaPoly1305
import Crypto.Noise.Cipher.AESGCM
import Crypto.Noise.DH
import Crypto.Noise.DH.Curve25519
import Crypto.Noise.DH.Curve448
import Crypto.Noise.Hash
import Crypto.Noise.Hash.SHA256
import Crypto.Noise.Hash.SHA512
import Crypto.Noise.Hash.BLAKE2s
import Crypto.Noise.Hash.BLAKE2b
import Data.ByteArray.Extend

data HandshakeType = NoiseNN
                   | NoiseKN
                   | NoiseNK
                   | NoiseKK
                   | NoiseNX
                   | NoiseKX
                   | NoiseXN
                   | NoiseIN
                   | NoiseXK
                   | NoiseIK
                   | NoiseXX
                   | NoiseIX
                   | NoiseN
                   | NoiseK
                   | NoiseX
                   deriving Eq

data CipherType :: * -> * where
  CTChaChaPoly1305 :: CipherType ChaChaPoly1305
  CTAESGCM         :: CipherType AESGCM

data SomeCipherType where
  WrapCipherType :: forall c. Cipher c => CipherType c -> SomeCipherType

data DHType :: * -> * where
  DTCurve25519 :: DHType Curve25519
  DTCurve448   :: DHType Curve448

data SomeDHType where
  WrapDHType :: forall d. DH d => DHType d -> SomeDHType

data HashType :: * -> * where
  HTSHA256  :: HashType SHA256
  HTSHA512  :: HashType SHA512
  HTBLAKE2s :: HashType BLAKE2s
  HTBLAKE2b :: HashType BLAKE2b

data SomeHashType where
  WrapHashType :: forall h. Hash h => HashType h -> SomeHashType

instance Show HandshakeType where
  show NoiseNN = "NN"
  show NoiseKN = "KN"
  show NoiseNK = "NK"
  show NoiseKK = "KK"
  show NoiseNX = "NX"
  show NoiseKX = "KX"
  show NoiseXN = "XN"
  show NoiseIN = "IN"
  show NoiseXK = "XK"
  show NoiseIK = "IK"
  show NoiseXX = "XX"
  show NoiseIX = "IX"
  show NoiseN  = "N"
  show NoiseK  = "K"
  show NoiseX  = "X"

instance Cipher c => Show (CipherType c) where
  show = unpack . convert . cipherName

instance DH d => Show (DHType d) where
  show = unpack . convert . dhName

instance Hash h => Show (HashType h) where
  show = unpack . convert . hashName