{-# LANGUAGE TypeFamilies #-}
module Crypto.Noise.Cipher
(
Cipher(..)
, AssocData
, Plaintext
) where
import Data.ByteArray (ScrubbedBytes, replicate)
import Prelude hiding (replicate)
class Cipher c where
data Ciphertext c :: *
data SymmetricKey c :: *
data Nonce c :: *
cipherName :: proxy c -> ScrubbedBytes
cipherEncrypt :: SymmetricKey c
-> Nonce c
-> AssocData
-> Plaintext
-> Ciphertext c
cipherDecrypt :: SymmetricKey c
-> Nonce c
-> AssocData
-> Ciphertext c
-> Maybe Plaintext
cipherRekey :: SymmetricKey c
-> SymmetricKey c
cipherRekey k = cipherBytesToSym .
cipherTextToBytes $
cipherEncrypt k cipherMaxNonce mempty (replicate 32 0)
cipherZeroNonce :: Nonce c
cipherMaxNonce :: Nonce c
cipherIncNonce :: Nonce c -> Nonce c
cipherNonceEq :: Nonce c -> Nonce c -> Bool
cipherNonceCmp :: Nonce c -> Nonce c -> Ordering
cipherBytesToSym :: ScrubbedBytes -> SymmetricKey c
cipherSymToBytes :: SymmetricKey c -> ScrubbedBytes
cipherTextToBytes :: Ciphertext c -> ScrubbedBytes
cipherBytesToText :: ScrubbedBytes -> Ciphertext c
type AssocData = ScrubbedBytes
type Plaintext = ScrubbedBytes
instance Cipher c => Eq (Nonce c) where
(==) = cipherNonceEq
instance Cipher c => Ord (Nonce c) where
compare = cipherNonceCmp
instance Show (SymmetricKey a) where
show _ = "<symmetric key>"
instance Show (Nonce a) where
show _ = "<nonce>"