module Botan.Cipher.ChaCha20Poly1305
( ChaCha20Poly1305(..)
, ChaCha20Poly1305SecretKey(..)
, ChaCha20Poly1305Nonce(..)
, ChaCha20Poly1305Ciphertext(..)
, ChaCha20Poly1305LazyCiphertext(..)
, chaCha20Poly1305Encrypt
, chaCha20Poly1305Decrypt
, chaCha20Poly1305EncryptLazy
, chaCha20Poly1305DecryptLazy
) where

import qualified Data.ByteString as ByteString
import qualified Data.ByteString.Lazy as Lazy
import qualified Data.Text as Text

import qualified Botan.Cipher as Botan
import qualified Botan.Utility as Botan

import Botan.Prelude hiding (Ciphertext, LazyCiphertext)

import Botan.Cipher.Class
import Botan.Types.Class
import Botan.RNG


-- ChaCha20Poly1305 type

data ChaCha20Poly1305

newtype instance SecretKey ChaCha20Poly1305 = MkChaCha20Poly1305SecretKey GSecretKey
    deriving newtype (SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305 -> Bool
(SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305 -> Bool)
-> (SecretKey ChaCha20Poly1305
    -> SecretKey ChaCha20Poly1305 -> Bool)
-> Eq (SecretKey ChaCha20Poly1305)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305 -> Bool
== :: SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305 -> Bool
$c/= :: SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305 -> Bool
/= :: SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305 -> Bool
Eq, Eq (SecretKey ChaCha20Poly1305)
Eq (SecretKey ChaCha20Poly1305) =>
(SecretKey ChaCha20Poly1305
 -> SecretKey ChaCha20Poly1305 -> Ordering)
-> (SecretKey ChaCha20Poly1305
    -> SecretKey ChaCha20Poly1305 -> Bool)
-> (SecretKey ChaCha20Poly1305
    -> SecretKey ChaCha20Poly1305 -> Bool)
-> (SecretKey ChaCha20Poly1305
    -> SecretKey ChaCha20Poly1305 -> Bool)
-> (SecretKey ChaCha20Poly1305
    -> SecretKey ChaCha20Poly1305 -> Bool)
-> (SecretKey ChaCha20Poly1305
    -> SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305)
-> (SecretKey ChaCha20Poly1305
    -> SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305)
-> Ord (SecretKey ChaCha20Poly1305)
SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305 -> Bool
SecretKey ChaCha20Poly1305
-> SecretKey ChaCha20Poly1305 -> Ordering
SecretKey ChaCha20Poly1305
-> SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SecretKey ChaCha20Poly1305
-> SecretKey ChaCha20Poly1305 -> Ordering
compare :: SecretKey ChaCha20Poly1305
-> SecretKey ChaCha20Poly1305 -> Ordering
$c< :: SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305 -> Bool
< :: SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305 -> Bool
$c<= :: SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305 -> Bool
<= :: SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305 -> Bool
$c> :: SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305 -> Bool
> :: SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305 -> Bool
$c>= :: SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305 -> Bool
>= :: SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305 -> Bool
$cmax :: SecretKey ChaCha20Poly1305
-> SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305
max :: SecretKey ChaCha20Poly1305
-> SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305
$cmin :: SecretKey ChaCha20Poly1305
-> SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305
min :: SecretKey ChaCha20Poly1305
-> SecretKey ChaCha20Poly1305 -> SecretKey ChaCha20Poly1305
Ord, Int -> SecretKey ChaCha20Poly1305 -> ShowS
[SecretKey ChaCha20Poly1305] -> ShowS
SecretKey ChaCha20Poly1305 -> String
(Int -> SecretKey ChaCha20Poly1305 -> ShowS)
-> (SecretKey ChaCha20Poly1305 -> String)
-> ([SecretKey ChaCha20Poly1305] -> ShowS)
-> Show (SecretKey ChaCha20Poly1305)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SecretKey ChaCha20Poly1305 -> ShowS
showsPrec :: Int -> SecretKey ChaCha20Poly1305 -> ShowS
$cshow :: SecretKey ChaCha20Poly1305 -> String
show :: SecretKey ChaCha20Poly1305 -> String
$cshowList :: [SecretKey ChaCha20Poly1305] -> ShowS
showList :: [SecretKey ChaCha20Poly1305] -> ShowS
Show, ByteString -> Maybe (SecretKey ChaCha20Poly1305)
SecretKey ChaCha20Poly1305 -> ByteString
(SecretKey ChaCha20Poly1305 -> ByteString)
-> (ByteString -> Maybe (SecretKey ChaCha20Poly1305))
-> Encodable (SecretKey ChaCha20Poly1305)
forall a.
(a -> ByteString) -> (ByteString -> Maybe a) -> Encodable a
$cencode :: SecretKey ChaCha20Poly1305 -> ByteString
encode :: SecretKey ChaCha20Poly1305 -> ByteString
$cdecode :: ByteString -> Maybe (SecretKey ChaCha20Poly1305)
decode :: ByteString -> Maybe (SecretKey ChaCha20Poly1305)
Encodable)

pattern ChaCha20Poly1305SecretKey :: ByteString -> SecretKey ChaCha20Poly1305
pattern $mChaCha20Poly1305SecretKey :: forall {r}.
SecretKey ChaCha20Poly1305
-> (ByteString -> r) -> ((# #) -> r) -> r
$bChaCha20Poly1305SecretKey :: ByteString -> SecretKey ChaCha20Poly1305
ChaCha20Poly1305SecretKey bytes = MkChaCha20Poly1305SecretKey (MkGSecretKey bytes)

getChaCha20Poly1305SecretKey :: SecretKey ChaCha20Poly1305 -> ByteString
getChaCha20Poly1305SecretKey :: SecretKey ChaCha20Poly1305 -> ByteString
getChaCha20Poly1305SecretKey (ChaCha20Poly1305SecretKey ByteString
bs) = ByteString
bs

type ChaCha20Poly1305SecretKey = SecretKey ChaCha20Poly1305

newtype instance Nonce ChaCha20Poly1305 = MkChaCha20Poly1305Nonce GNonce
    deriving newtype (Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Bool
(Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Bool)
-> (Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Bool)
-> Eq (Nonce ChaCha20Poly1305)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Bool
== :: Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Bool
$c/= :: Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Bool
/= :: Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Bool
Eq, Eq (Nonce ChaCha20Poly1305)
Eq (Nonce ChaCha20Poly1305) =>
(Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Ordering)
-> (Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Bool)
-> (Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Bool)
-> (Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Bool)
-> (Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Bool)
-> (Nonce ChaCha20Poly1305
    -> Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305)
-> (Nonce ChaCha20Poly1305
    -> Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305)
-> Ord (Nonce ChaCha20Poly1305)
Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Bool
Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Ordering
Nonce ChaCha20Poly1305
-> Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Ordering
compare :: Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Ordering
$c< :: Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Bool
< :: Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Bool
$c<= :: Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Bool
<= :: Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Bool
$c> :: Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Bool
> :: Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Bool
$c>= :: Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Bool
>= :: Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Bool
$cmax :: Nonce ChaCha20Poly1305
-> Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305
max :: Nonce ChaCha20Poly1305
-> Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305
$cmin :: Nonce ChaCha20Poly1305
-> Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305
min :: Nonce ChaCha20Poly1305
-> Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305
Ord, Int -> Nonce ChaCha20Poly1305 -> ShowS
[Nonce ChaCha20Poly1305] -> ShowS
Nonce ChaCha20Poly1305 -> String
(Int -> Nonce ChaCha20Poly1305 -> ShowS)
-> (Nonce ChaCha20Poly1305 -> String)
-> ([Nonce ChaCha20Poly1305] -> ShowS)
-> Show (Nonce ChaCha20Poly1305)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Nonce ChaCha20Poly1305 -> ShowS
showsPrec :: Int -> Nonce ChaCha20Poly1305 -> ShowS
$cshow :: Nonce ChaCha20Poly1305 -> String
show :: Nonce ChaCha20Poly1305 -> String
$cshowList :: [Nonce ChaCha20Poly1305] -> ShowS
showList :: [Nonce ChaCha20Poly1305] -> ShowS
Show, ByteString -> Maybe (Nonce ChaCha20Poly1305)
Nonce ChaCha20Poly1305 -> ByteString
(Nonce ChaCha20Poly1305 -> ByteString)
-> (ByteString -> Maybe (Nonce ChaCha20Poly1305))
-> Encodable (Nonce ChaCha20Poly1305)
forall a.
(a -> ByteString) -> (ByteString -> Maybe a) -> Encodable a
$cencode :: Nonce ChaCha20Poly1305 -> ByteString
encode :: Nonce ChaCha20Poly1305 -> ByteString
$cdecode :: ByteString -> Maybe (Nonce ChaCha20Poly1305)
decode :: ByteString -> Maybe (Nonce ChaCha20Poly1305)
Encodable, Eq (Nonce ChaCha20Poly1305)
Ord (Nonce ChaCha20Poly1305)
Encodable (Nonce ChaCha20Poly1305)
(Eq (Nonce ChaCha20Poly1305), Ord (Nonce ChaCha20Poly1305),
 Encodable (Nonce ChaCha20Poly1305)) =>
(Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305)
-> IsNonce (Nonce ChaCha20Poly1305)
Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305
forall n. (Eq n, Ord n, Encodable n) => (n -> n) -> IsNonce n
$cnudge :: Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305
nudge :: Nonce ChaCha20Poly1305 -> Nonce ChaCha20Poly1305
IsNonce)

pattern ChaCha20Poly1305Nonce :: ByteString -> Nonce ChaCha20Poly1305
pattern $mChaCha20Poly1305Nonce :: forall {r}.
Nonce ChaCha20Poly1305 -> (ByteString -> r) -> ((# #) -> r) -> r
$bChaCha20Poly1305Nonce :: ByteString -> Nonce ChaCha20Poly1305
ChaCha20Poly1305Nonce bytes = MkChaCha20Poly1305Nonce (MkGNonce bytes)

getChaCha20Poly1305Nonce :: Nonce ChaCha20Poly1305 -> ByteString
getChaCha20Poly1305Nonce :: Nonce ChaCha20Poly1305 -> ByteString
getChaCha20Poly1305Nonce (ChaCha20Poly1305Nonce ByteString
bs) = ByteString
bs

type ChaCha20Poly1305Nonce = Nonce ChaCha20Poly1305

newtype instance Ciphertext ChaCha20Poly1305 = MkChaCha20Poly1305Ciphertext GCiphertext
    deriving newtype (Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305 -> Bool
(Ciphertext ChaCha20Poly1305
 -> Ciphertext ChaCha20Poly1305 -> Bool)
-> (Ciphertext ChaCha20Poly1305
    -> Ciphertext ChaCha20Poly1305 -> Bool)
-> Eq (Ciphertext ChaCha20Poly1305)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305 -> Bool
== :: Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305 -> Bool
$c/= :: Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305 -> Bool
/= :: Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305 -> Bool
Eq, Eq (Ciphertext ChaCha20Poly1305)
Eq (Ciphertext ChaCha20Poly1305) =>
(Ciphertext ChaCha20Poly1305
 -> Ciphertext ChaCha20Poly1305 -> Ordering)
-> (Ciphertext ChaCha20Poly1305
    -> Ciphertext ChaCha20Poly1305 -> Bool)
-> (Ciphertext ChaCha20Poly1305
    -> Ciphertext ChaCha20Poly1305 -> Bool)
-> (Ciphertext ChaCha20Poly1305
    -> Ciphertext ChaCha20Poly1305 -> Bool)
-> (Ciphertext ChaCha20Poly1305
    -> Ciphertext ChaCha20Poly1305 -> Bool)
-> (Ciphertext ChaCha20Poly1305
    -> Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305)
-> (Ciphertext ChaCha20Poly1305
    -> Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305)
-> Ord (Ciphertext ChaCha20Poly1305)
Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305 -> Bool
Ciphertext ChaCha20Poly1305
-> Ciphertext ChaCha20Poly1305 -> Ordering
Ciphertext ChaCha20Poly1305
-> Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Ciphertext ChaCha20Poly1305
-> Ciphertext ChaCha20Poly1305 -> Ordering
compare :: Ciphertext ChaCha20Poly1305
-> Ciphertext ChaCha20Poly1305 -> Ordering
$c< :: Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305 -> Bool
< :: Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305 -> Bool
$c<= :: Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305 -> Bool
<= :: Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305 -> Bool
$c> :: Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305 -> Bool
> :: Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305 -> Bool
$c>= :: Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305 -> Bool
>= :: Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305 -> Bool
$cmax :: Ciphertext ChaCha20Poly1305
-> Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305
max :: Ciphertext ChaCha20Poly1305
-> Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305
$cmin :: Ciphertext ChaCha20Poly1305
-> Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305
min :: Ciphertext ChaCha20Poly1305
-> Ciphertext ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305
Ord, Int -> Ciphertext ChaCha20Poly1305 -> ShowS
[Ciphertext ChaCha20Poly1305] -> ShowS
Ciphertext ChaCha20Poly1305 -> String
(Int -> Ciphertext ChaCha20Poly1305 -> ShowS)
-> (Ciphertext ChaCha20Poly1305 -> String)
-> ([Ciphertext ChaCha20Poly1305] -> ShowS)
-> Show (Ciphertext ChaCha20Poly1305)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Ciphertext ChaCha20Poly1305 -> ShowS
showsPrec :: Int -> Ciphertext ChaCha20Poly1305 -> ShowS
$cshow :: Ciphertext ChaCha20Poly1305 -> String
show :: Ciphertext ChaCha20Poly1305 -> String
$cshowList :: [Ciphertext ChaCha20Poly1305] -> ShowS
showList :: [Ciphertext ChaCha20Poly1305] -> ShowS
Show, ByteString -> Maybe (Ciphertext ChaCha20Poly1305)
Ciphertext ChaCha20Poly1305 -> ByteString
(Ciphertext ChaCha20Poly1305 -> ByteString)
-> (ByteString -> Maybe (Ciphertext ChaCha20Poly1305))
-> Encodable (Ciphertext ChaCha20Poly1305)
forall a.
(a -> ByteString) -> (ByteString -> Maybe a) -> Encodable a
$cencode :: Ciphertext ChaCha20Poly1305 -> ByteString
encode :: Ciphertext ChaCha20Poly1305 -> ByteString
$cdecode :: ByteString -> Maybe (Ciphertext ChaCha20Poly1305)
decode :: ByteString -> Maybe (Ciphertext ChaCha20Poly1305)
Encodable)

pattern ChaCha20Poly1305Ciphertext :: ByteString -> Ciphertext ChaCha20Poly1305
pattern $mChaCha20Poly1305Ciphertext :: forall {r}.
Ciphertext ChaCha20Poly1305
-> (ByteString -> r) -> ((# #) -> r) -> r
$bChaCha20Poly1305Ciphertext :: ByteString -> Ciphertext ChaCha20Poly1305
ChaCha20Poly1305Ciphertext bs = MkChaCha20Poly1305Ciphertext (MkGCiphertext bs)

getChaCha20Poly1305Ciphertext :: Ciphertext ChaCha20Poly1305 -> ByteString
getChaCha20Poly1305Ciphertext :: Ciphertext ChaCha20Poly1305 -> ByteString
getChaCha20Poly1305Ciphertext (ChaCha20Poly1305Ciphertext ByteString
bs) = ByteString
bs

type ChaCha20Poly1305Ciphertext = Ciphertext ChaCha20Poly1305

newtype instance LazyCiphertext ChaCha20Poly1305 = MkChaCha20Poly1305LazyCiphertext GLazyCiphertext
    deriving newtype (LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305 -> Bool
(LazyCiphertext ChaCha20Poly1305
 -> LazyCiphertext ChaCha20Poly1305 -> Bool)
-> (LazyCiphertext ChaCha20Poly1305
    -> LazyCiphertext ChaCha20Poly1305 -> Bool)
-> Eq (LazyCiphertext ChaCha20Poly1305)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305 -> Bool
== :: LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305 -> Bool
$c/= :: LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305 -> Bool
/= :: LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305 -> Bool
Eq, Eq (LazyCiphertext ChaCha20Poly1305)
Eq (LazyCiphertext ChaCha20Poly1305) =>
(LazyCiphertext ChaCha20Poly1305
 -> LazyCiphertext ChaCha20Poly1305 -> Ordering)
-> (LazyCiphertext ChaCha20Poly1305
    -> LazyCiphertext ChaCha20Poly1305 -> Bool)
-> (LazyCiphertext ChaCha20Poly1305
    -> LazyCiphertext ChaCha20Poly1305 -> Bool)
-> (LazyCiphertext ChaCha20Poly1305
    -> LazyCiphertext ChaCha20Poly1305 -> Bool)
-> (LazyCiphertext ChaCha20Poly1305
    -> LazyCiphertext ChaCha20Poly1305 -> Bool)
-> (LazyCiphertext ChaCha20Poly1305
    -> LazyCiphertext ChaCha20Poly1305
    -> LazyCiphertext ChaCha20Poly1305)
-> (LazyCiphertext ChaCha20Poly1305
    -> LazyCiphertext ChaCha20Poly1305
    -> LazyCiphertext ChaCha20Poly1305)
-> Ord (LazyCiphertext ChaCha20Poly1305)
LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305 -> Bool
LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305 -> Ordering
LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305 -> Ordering
compare :: LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305 -> Ordering
$c< :: LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305 -> Bool
< :: LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305 -> Bool
$c<= :: LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305 -> Bool
<= :: LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305 -> Bool
$c> :: LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305 -> Bool
> :: LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305 -> Bool
$c>= :: LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305 -> Bool
>= :: LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305 -> Bool
$cmax :: LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305
max :: LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305
$cmin :: LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305
min :: LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305
Ord, Int -> LazyCiphertext ChaCha20Poly1305 -> ShowS
[LazyCiphertext ChaCha20Poly1305] -> ShowS
LazyCiphertext ChaCha20Poly1305 -> String
(Int -> LazyCiphertext ChaCha20Poly1305 -> ShowS)
-> (LazyCiphertext ChaCha20Poly1305 -> String)
-> ([LazyCiphertext ChaCha20Poly1305] -> ShowS)
-> Show (LazyCiphertext ChaCha20Poly1305)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LazyCiphertext ChaCha20Poly1305 -> ShowS
showsPrec :: Int -> LazyCiphertext ChaCha20Poly1305 -> ShowS
$cshow :: LazyCiphertext ChaCha20Poly1305 -> String
show :: LazyCiphertext ChaCha20Poly1305 -> String
$cshowList :: [LazyCiphertext ChaCha20Poly1305] -> ShowS
showList :: [LazyCiphertext ChaCha20Poly1305] -> ShowS
Show, ByteString -> Maybe (LazyCiphertext ChaCha20Poly1305)
LazyCiphertext ChaCha20Poly1305 -> ByteString
(LazyCiphertext ChaCha20Poly1305 -> ByteString)
-> (ByteString -> Maybe (LazyCiphertext ChaCha20Poly1305))
-> Encodable (LazyCiphertext ChaCha20Poly1305)
forall a.
(a -> ByteString) -> (ByteString -> Maybe a) -> Encodable a
$cencode :: LazyCiphertext ChaCha20Poly1305 -> ByteString
encode :: LazyCiphertext ChaCha20Poly1305 -> ByteString
$cdecode :: ByteString -> Maybe (LazyCiphertext ChaCha20Poly1305)
decode :: ByteString -> Maybe (LazyCiphertext ChaCha20Poly1305)
Encodable, Encodable (LazyCiphertext ChaCha20Poly1305)
ByteString -> Maybe (LazyCiphertext ChaCha20Poly1305)
LazyCiphertext ChaCha20Poly1305 -> ByteString
Encodable (LazyCiphertext ChaCha20Poly1305) =>
(LazyCiphertext ChaCha20Poly1305 -> ByteString)
-> (ByteString -> Maybe (LazyCiphertext ChaCha20Poly1305))
-> LazyEncodable (LazyCiphertext ChaCha20Poly1305)
forall a.
Encodable a =>
(a -> ByteString) -> (ByteString -> Maybe a) -> LazyEncodable a
$cencodeLazy :: LazyCiphertext ChaCha20Poly1305 -> ByteString
encodeLazy :: LazyCiphertext ChaCha20Poly1305 -> ByteString
$cdecodeLazy :: ByteString -> Maybe (LazyCiphertext ChaCha20Poly1305)
decodeLazy :: ByteString -> Maybe (LazyCiphertext ChaCha20Poly1305)
LazyEncodable)

pattern ChaCha20Poly1305LazyCiphertext :: Lazy.ByteString -> LazyCiphertext ChaCha20Poly1305
pattern $mChaCha20Poly1305LazyCiphertext :: forall {r}.
LazyCiphertext ChaCha20Poly1305
-> (ByteString -> r) -> ((# #) -> r) -> r
$bChaCha20Poly1305LazyCiphertext :: ByteString -> LazyCiphertext ChaCha20Poly1305
ChaCha20Poly1305LazyCiphertext lbs = MkChaCha20Poly1305LazyCiphertext (MkGLazyCiphertext lbs)

getChaCha20Poly1305LazyCiphertext :: LazyCiphertext ChaCha20Poly1305 -> Lazy.ByteString
getChaCha20Poly1305LazyCiphertext :: LazyCiphertext ChaCha20Poly1305 -> ByteString
getChaCha20Poly1305LazyCiphertext (ChaCha20Poly1305LazyCiphertext ByteString
bs) = ByteString
bs

type ChaCha20Poly1305LazyCiphertext = LazyCiphertext ChaCha20Poly1305

instance HasSecretKey ChaCha20Poly1305 where
    
    secretKeySpec :: SizeSpecifier (SecretKey ChaCha20Poly1305)
    secretKeySpec :: SizeSpecifier (SecretKey ChaCha20Poly1305)
secretKeySpec = SizeSpecifier () -> SizeSpecifier (SecretKey ChaCha20Poly1305)
forall a b. SizeSpecifier a -> SizeSpecifier b
coerceSizeSpec (SizeSpecifier () -> SizeSpecifier (SecretKey ChaCha20Poly1305))
-> SizeSpecifier () -> SizeSpecifier (SecretKey ChaCha20Poly1305)
forall a b. (a -> b) -> a -> b
$ Cipher -> SizeSpecifier ()
Botan.cipherKeySpec Cipher
Botan.chaCha20Poly1305

instance (MonadRandomIO m )=> SecretKeyGen ChaCha20Poly1305 m where

    newSecretKey :: MonadRandomIO m => m (SecretKey ChaCha20Poly1305)
    newSecretKey :: MonadRandomIO m => m (SecretKey ChaCha20Poly1305)
newSecretKey = ByteString -> SecretKey ChaCha20Poly1305
ChaCha20Poly1305SecretKey (ByteString -> SecretKey ChaCha20Poly1305)
-> m ByteString -> m (SecretKey ChaCha20Poly1305)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SizeSpecifier (SecretKey ChaCha20Poly1305) -> m ByteString
forall (m :: * -> *) a.
MonadRandomIO m =>
SizeSpecifier a -> m ByteString
newSized (forall alg. HasSecretKey alg => SizeSpecifier (SecretKey alg)
secretKeySpec @ChaCha20Poly1305)
    
    newSecretKeyMaybe :: MonadRandomIO m => Int -> m (Maybe (SecretKey ChaCha20Poly1305))
    newSecretKeyMaybe :: MonadRandomIO m => Int -> m (Maybe (SecretKey ChaCha20Poly1305))
newSecretKeyMaybe Int
i = (ByteString -> SecretKey ChaCha20Poly1305)
-> Maybe ByteString -> Maybe (SecretKey ChaCha20Poly1305)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> SecretKey ChaCha20Poly1305
ChaCha20Poly1305SecretKey (Maybe ByteString -> Maybe (SecretKey ChaCha20Poly1305))
-> m (Maybe ByteString) -> m (Maybe (SecretKey ChaCha20Poly1305))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SizeSpecifier (SecretKey ChaCha20Poly1305)
-> Int -> m (Maybe ByteString)
forall (m :: * -> *) a.
MonadRandomIO m =>
SizeSpecifier a -> Int -> m (Maybe ByteString)
newSizedMaybe (forall alg. HasSecretKey alg => SizeSpecifier (SecretKey alg)
secretKeySpec @ChaCha20Poly1305) Int
i

instance HasNonce ChaCha20Poly1305 where
    
    nonceSpec :: SizeSpecifier (Nonce ChaCha20Poly1305)
    -- nonceSpec = coerceSizeSpec $ Botan.cipherNonce Botan.chaCha20Poly1305
    -- Taken from: cipherNonceSizeIsValid n (AEAD ChaCha20Poly1305) = n `elem` [ 8, 12, 24 ]
    -- We should be moving algo-specific stuff here anyway.
    nonceSpec :: SizeSpecifier (Nonce ChaCha20Poly1305)
nonceSpec = [Int] -> SizeSpecifier (Nonce ChaCha20Poly1305)
forall a. [Int] -> SizeSpecifier a
SizeEnum [ Int
8, Int
12, Int
24 ]

instance (MonadRandomIO m )=> NonceGen ChaCha20Poly1305 m where

    newNonce :: MonadRandomIO m => m (Nonce ChaCha20Poly1305)
    newNonce :: MonadRandomIO m => m (Nonce ChaCha20Poly1305)
newNonce = ByteString -> Nonce ChaCha20Poly1305
ChaCha20Poly1305Nonce (ByteString -> Nonce ChaCha20Poly1305)
-> m ByteString -> m (Nonce ChaCha20Poly1305)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SizeSpecifier (Nonce ChaCha20Poly1305) -> m ByteString
forall (m :: * -> *) a.
MonadRandomIO m =>
SizeSpecifier a -> m ByteString
newSized (forall alg. HasNonce alg => SizeSpecifier (Nonce alg)
nonceSpec @ChaCha20Poly1305)
    
    newNonceMaybe :: MonadRandomIO m => Int -> m (Maybe (Nonce ChaCha20Poly1305))
    newNonceMaybe :: MonadRandomIO m => Int -> m (Maybe (Nonce ChaCha20Poly1305))
newNonceMaybe Int
i = (ByteString -> Nonce ChaCha20Poly1305)
-> Maybe ByteString -> Maybe (Nonce ChaCha20Poly1305)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Nonce ChaCha20Poly1305
ChaCha20Poly1305Nonce (Maybe ByteString -> Maybe (Nonce ChaCha20Poly1305))
-> m (Maybe ByteString) -> m (Maybe (Nonce ChaCha20Poly1305))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SizeSpecifier (Nonce ChaCha20Poly1305)
-> Int -> m (Maybe ByteString)
forall (m :: * -> *) a.
MonadRandomIO m =>
SizeSpecifier a -> Int -> m (Maybe ByteString)
newSizedMaybe (forall alg. HasNonce alg => SizeSpecifier (Nonce alg)
nonceSpec @ChaCha20Poly1305) Int
i

instance HasCiphertext ChaCha20Poly1305 where
instance HasLazyCiphertext ChaCha20Poly1305 where

instance Cipher ChaCha20Poly1305 where

    cipherEncrypt :: SecretKey ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> ByteString -> Ciphertext ChaCha20Poly1305
    cipherEncrypt :: SecretKey ChaCha20Poly1305
-> Nonce ChaCha20Poly1305
-> ByteString
-> Ciphertext ChaCha20Poly1305
cipherEncrypt (ChaCha20Poly1305SecretKey ByteString
k) (ChaCha20Poly1305Nonce ByteString
n) = ByteString -> Ciphertext ChaCha20Poly1305
ChaCha20Poly1305Ciphertext (ByteString -> Ciphertext ChaCha20Poly1305)
-> (ByteString -> ByteString)
-> ByteString
-> Ciphertext ChaCha20Poly1305
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Cipher -> ByteString -> ByteString -> ByteString -> ByteString
Botan.cipherEncrypt Cipher
Botan.chaCha20Poly1305 ByteString
k ByteString
n

    cipherDecrypt :: SecretKey ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Ciphertext ChaCha20Poly1305 -> Maybe ByteString
    cipherDecrypt :: SecretKey ChaCha20Poly1305
-> Nonce ChaCha20Poly1305
-> Ciphertext ChaCha20Poly1305
-> Maybe ByteString
cipherDecrypt (ChaCha20Poly1305SecretKey ByteString
k) (ChaCha20Poly1305Nonce ByteString
n) (ChaCha20Poly1305Ciphertext ByteString
ct) = Cipher
-> ByteString -> ByteString -> ByteString -> Maybe ByteString
Botan.cipherDecrypt Cipher
Botan.chaCha20Poly1305 ByteString
k ByteString
n ByteString
ct

instance IncrementalCipher ChaCha20Poly1305 where

    cipherEncryptLazy :: SecretKey ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Lazy.ByteString -> LazyCiphertext ChaCha20Poly1305
    cipherEncryptLazy :: SecretKey ChaCha20Poly1305
-> Nonce ChaCha20Poly1305
-> ByteString
-> LazyCiphertext ChaCha20Poly1305
cipherEncryptLazy (ChaCha20Poly1305SecretKey ByteString
k) (ChaCha20Poly1305Nonce ByteString
n) = ByteString -> LazyCiphertext ChaCha20Poly1305
ChaCha20Poly1305LazyCiphertext (ByteString -> LazyCiphertext ChaCha20Poly1305)
-> (ByteString -> ByteString)
-> ByteString
-> LazyCiphertext ChaCha20Poly1305
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Cipher -> ByteString -> ByteString -> ByteString -> ByteString
Botan.cipherEncryptLazy Cipher
Botan.chaCha20Poly1305 ByteString
k ByteString
n

    cipherDecryptLazy :: SecretKey ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> LazyCiphertext ChaCha20Poly1305 -> Maybe Lazy.ByteString
    cipherDecryptLazy :: SecretKey ChaCha20Poly1305
-> Nonce ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305
-> Maybe ByteString
cipherDecryptLazy (ChaCha20Poly1305SecretKey ByteString
k) (ChaCha20Poly1305Nonce ByteString
n) (ChaCha20Poly1305LazyCiphertext ByteString
ct) = Cipher
-> ByteString -> ByteString -> ByteString -> Maybe ByteString
Botan.cipherDecryptLazy Cipher
Botan.chaCha20Poly1305 ByteString
k ByteString
n ByteString
ct

-- ChaCha20Poly1305 cipher

chaCha20Poly1305Encrypt :: SecretKey ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> ByteString -> ChaCha20Poly1305Ciphertext
chaCha20Poly1305Encrypt :: SecretKey ChaCha20Poly1305
-> Nonce ChaCha20Poly1305
-> ByteString
-> Ciphertext ChaCha20Poly1305
chaCha20Poly1305Encrypt = SecretKey ChaCha20Poly1305
-> Nonce ChaCha20Poly1305
-> ByteString
-> Ciphertext ChaCha20Poly1305
forall c.
Cipher c =>
SecretKey c -> Nonce c -> ByteString -> Ciphertext c
cipherEncrypt

chaCha20Poly1305Decrypt :: SecretKey ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> ChaCha20Poly1305Ciphertext -> Maybe ByteString
chaCha20Poly1305Decrypt :: SecretKey ChaCha20Poly1305
-> Nonce ChaCha20Poly1305
-> Ciphertext ChaCha20Poly1305
-> Maybe ByteString
chaCha20Poly1305Decrypt = SecretKey ChaCha20Poly1305
-> Nonce ChaCha20Poly1305
-> Ciphertext ChaCha20Poly1305
-> Maybe ByteString
forall c.
Cipher c =>
SecretKey c -> Nonce c -> Ciphertext c -> Maybe ByteString
cipherDecrypt

chaCha20Poly1305EncryptLazy :: SecretKey ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> Lazy.ByteString -> ChaCha20Poly1305LazyCiphertext
chaCha20Poly1305EncryptLazy :: SecretKey ChaCha20Poly1305
-> Nonce ChaCha20Poly1305
-> ByteString
-> LazyCiphertext ChaCha20Poly1305
chaCha20Poly1305EncryptLazy = SecretKey ChaCha20Poly1305
-> Nonce ChaCha20Poly1305
-> ByteString
-> LazyCiphertext ChaCha20Poly1305
forall c.
IncrementalCipher c =>
SecretKey c -> Nonce c -> ByteString -> LazyCiphertext c
cipherEncryptLazy

chaCha20Poly1305DecryptLazy :: SecretKey ChaCha20Poly1305 -> Nonce ChaCha20Poly1305 -> ChaCha20Poly1305LazyCiphertext -> Maybe Lazy.ByteString
chaCha20Poly1305DecryptLazy :: SecretKey ChaCha20Poly1305
-> Nonce ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305
-> Maybe ByteString
chaCha20Poly1305DecryptLazy = SecretKey ChaCha20Poly1305
-> Nonce ChaCha20Poly1305
-> LazyCiphertext ChaCha20Poly1305
-> Maybe ByteString
forall c.
IncrementalCipher c =>
SecretKey c -> Nonce c -> LazyCiphertext c -> Maybe ByteString
cipherDecryptLazy