module Botan.BlockCipher.DES
( DES(..)
, DESSecretKey(..)
, pattern DESSecretKey
, getDESSecretKey
, DESCiphertext(..)
, desEncrypt
, desDecrypt
, desEncryptLazy
, desDecryptLazy
, TripleDES(..)
, TripleDESSecretKey(..)
, pattern TripleDESSecretKey
, getTripleDESSecretKey
, TripleDESCiphertext(..)
, tripleDESEncrypt
, tripleDESDecrypt
, tripleDESEncryptLazy
, tripleDESDecryptLazy
) where

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

import qualified Botan.BlockCipher as Botan
import qualified Botan.Utility as Botan

import Botan.Prelude hiding (Ciphertext, LazyCiphertext)

import Botan.BlockCipher.Class
import Botan.Types.Class
import Botan.RNG

-- DES type

data DES

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

pattern DESSecretKey :: ByteString -> SecretKey DES
pattern $mDESSecretKey :: forall {r}. SecretKey DES -> (ByteString -> r) -> ((# #) -> r) -> r
$bDESSecretKey :: ByteString -> SecretKey DES
DESSecretKey bytes = MkDESSecretKey (MkGSecretKey bytes)

getDESSecretKey :: SecretKey DES -> ByteString
getDESSecretKey :: SecretKey DES -> ByteString
getDESSecretKey (DESSecretKey ByteString
bs) = ByteString
bs

type DESSecretKey = SecretKey DES

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

pattern DESCiphertext :: ByteString -> Ciphertext DES
pattern $mDESCiphertext :: forall {r}.
Ciphertext DES -> (ByteString -> r) -> ((# #) -> r) -> r
$bDESCiphertext :: ByteString -> Ciphertext DES
DESCiphertext bs = MkDESCiphertext (MkGCiphertext bs)

getDESCiphertext :: Ciphertext DES -> ByteString
getDESCiphertext :: Ciphertext DES -> ByteString
getDESCiphertext (DESCiphertext ByteString
bs) = ByteString
bs

type DESCiphertext = Ciphertext DES

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

pattern DESLazyCiphertext :: Lazy.ByteString -> LazyCiphertext DES
pattern $mDESLazyCiphertext :: forall {r}.
LazyCiphertext DES -> (ByteString -> r) -> ((# #) -> r) -> r
$bDESLazyCiphertext :: ByteString -> LazyCiphertext DES
DESLazyCiphertext lbs = MkDESLazyCiphertext (MkGLazyCiphertext lbs)

getDESLazyCiphertext :: LazyCiphertext DES -> Lazy.ByteString
getDESLazyCiphertext :: LazyCiphertext DES -> ByteString
getDESLazyCiphertext (DESLazyCiphertext ByteString
bs) = ByteString
bs

type DESLazyCiphertext = LazyCiphertext DES

instance HasSecretKey DES where
    
    secretKeySpec :: SizeSpecifier (SecretKey DES)
    secretKeySpec :: SizeSpecifier (SecretKey DES)
secretKeySpec = SizeSpecifier () -> SizeSpecifier (SecretKey DES)
forall a b. SizeSpecifier a -> SizeSpecifier b
coerceSizeSpec (SizeSpecifier () -> SizeSpecifier (SecretKey DES))
-> SizeSpecifier () -> SizeSpecifier (SecretKey DES)
forall a b. (a -> b) -> a -> b
$ BlockCipher -> SizeSpecifier ()
Botan.blockCipherKeySpec BlockCipher
Botan.des

instance (MonadRandomIO m )=> SecretKeyGen DES m where

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

instance HasCiphertext DES where

instance BlockCipher DES where

    blockCipherEncrypt :: SecretKey DES -> ByteString -> Maybe (Ciphertext DES)
    blockCipherEncrypt :: SecretKey DES -> ByteString -> Maybe (Ciphertext DES)
blockCipherEncrypt (DESSecretKey ByteString
k) = (ByteString -> Ciphertext DES)
-> Maybe ByteString -> Maybe (Ciphertext DES)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Ciphertext DES
DESCiphertext (Maybe ByteString -> Maybe (Ciphertext DES))
-> (ByteString -> Maybe ByteString)
-> ByteString
-> Maybe (Ciphertext DES)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BlockCipher -> ByteString -> ByteString -> Maybe ByteString
Botan.blockCipherEncrypt BlockCipher
Botan.des ByteString
k

    blockCipherDecrypt :: SecretKey DES -> Ciphertext DES -> Maybe ByteString
    blockCipherDecrypt :: SecretKey DES -> Ciphertext DES -> Maybe ByteString
blockCipherDecrypt (DESSecretKey ByteString
k) (DESCiphertext ByteString
ct) = BlockCipher -> ByteString -> ByteString -> Maybe ByteString
Botan.blockCipherDecrypt BlockCipher
Botan.des ByteString
k ByteString
ct

instance HasLazyCiphertext DES where

instance IncrementalBlockCipher DES where

    blockCipherEncryptLazy :: SecretKey DES -> Lazy.ByteString -> Maybe (LazyCiphertext DES)
    blockCipherEncryptLazy :: SecretKey DES -> ByteString -> Maybe (LazyCiphertext DES)
blockCipherEncryptLazy (DESSecretKey ByteString
k) = (ByteString -> LazyCiphertext DES)
-> Maybe ByteString -> Maybe (LazyCiphertext DES)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> LazyCiphertext DES
DESLazyCiphertext (Maybe ByteString -> Maybe (LazyCiphertext DES))
-> (ByteString -> Maybe ByteString)
-> ByteString
-> Maybe (LazyCiphertext DES)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BlockCipher -> ByteString -> ByteString -> Maybe ByteString
Botan.blockCipherEncryptLazy BlockCipher
Botan.des ByteString
k

    blockCipherDecryptLazy :: SecretKey DES -> LazyCiphertext DES -> Maybe Lazy.ByteString
    blockCipherDecryptLazy :: SecretKey DES -> LazyCiphertext DES -> Maybe ByteString
blockCipherDecryptLazy (DESSecretKey ByteString
k) (DESLazyCiphertext ByteString
ct) = BlockCipher -> ByteString -> ByteString -> Maybe ByteString
Botan.blockCipherDecryptLazy BlockCipher
Botan.des ByteString
k ByteString
ct

-- DES blockCipher

desEncrypt :: SecretKey DES -> ByteString -> Maybe DESCiphertext
desEncrypt :: SecretKey DES -> ByteString -> Maybe (Ciphertext DES)
desEncrypt = SecretKey DES -> ByteString -> Maybe (Ciphertext DES)
forall bc.
BlockCipher bc =>
SecretKey bc -> ByteString -> Maybe (Ciphertext bc)
blockCipherEncrypt

desDecrypt :: SecretKey DES -> DESCiphertext -> Maybe ByteString
desDecrypt :: SecretKey DES -> Ciphertext DES -> Maybe ByteString
desDecrypt = SecretKey DES -> Ciphertext DES -> Maybe ByteString
forall bc.
BlockCipher bc =>
SecretKey bc -> Ciphertext bc -> Maybe ByteString
blockCipherDecrypt

desEncryptLazy :: SecretKey DES -> Lazy.ByteString -> Maybe DESLazyCiphertext
desEncryptLazy :: SecretKey DES -> ByteString -> Maybe (LazyCiphertext DES)
desEncryptLazy = SecretKey DES -> ByteString -> Maybe (LazyCiphertext DES)
forall bc.
IncrementalBlockCipher bc =>
SecretKey bc -> ByteString -> Maybe (LazyCiphertext bc)
blockCipherEncryptLazy

desDecryptLazy :: SecretKey DES -> DESLazyCiphertext -> Maybe Lazy.ByteString
desDecryptLazy :: SecretKey DES -> LazyCiphertext DES -> Maybe ByteString
desDecryptLazy = SecretKey DES -> LazyCiphertext DES -> Maybe ByteString
forall bc.
IncrementalBlockCipher bc =>
SecretKey bc -> LazyCiphertext bc -> Maybe ByteString
blockCipherDecryptLazy


-- Triple DES type

data TripleDES

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

pattern TripleDESSecretKey :: ByteString -> SecretKey TripleDES
pattern $mTripleDESSecretKey :: forall {r}.
SecretKey TripleDES -> (ByteString -> r) -> ((# #) -> r) -> r
$bTripleDESSecretKey :: ByteString -> SecretKey TripleDES
TripleDESSecretKey bytes = MkTripleDESSecretKey (MkGSecretKey bytes)

getTripleDESSecretKey :: SecretKey TripleDES -> ByteString
getTripleDESSecretKey :: SecretKey TripleDES -> ByteString
getTripleDESSecretKey (TripleDESSecretKey ByteString
bs) = ByteString
bs

type TripleDESSecretKey = SecretKey TripleDES

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

pattern TripleDESCiphertext :: ByteString -> Ciphertext TripleDES
pattern $mTripleDESCiphertext :: forall {r}.
Ciphertext TripleDES -> (ByteString -> r) -> ((# #) -> r) -> r
$bTripleDESCiphertext :: ByteString -> Ciphertext TripleDES
TripleDESCiphertext bs = MkTripleDESCiphertext (MkGCiphertext bs)

getTripleDESCiphertext :: Ciphertext TripleDES -> ByteString
getTripleDESCiphertext :: Ciphertext TripleDES -> ByteString
getTripleDESCiphertext (TripleDESCiphertext ByteString
bs) = ByteString
bs

type TripleDESCiphertext = Ciphertext TripleDES

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

pattern TripleDESLazyCiphertext :: Lazy.ByteString -> LazyCiphertext TripleDES
pattern $mTripleDESLazyCiphertext :: forall {r}.
LazyCiphertext TripleDES -> (ByteString -> r) -> ((# #) -> r) -> r
$bTripleDESLazyCiphertext :: ByteString -> LazyCiphertext TripleDES
TripleDESLazyCiphertext lbs = MkTripleDESLazyCiphertext (MkGLazyCiphertext lbs)

getTripleDESLazyCiphertext :: LazyCiphertext TripleDES -> Lazy.ByteString
getTripleDESLazyCiphertext :: LazyCiphertext TripleDES -> ByteString
getTripleDESLazyCiphertext (TripleDESLazyCiphertext ByteString
bs) = ByteString
bs

type TripleDESLazyCiphertext = LazyCiphertext TripleDES

instance HasSecretKey TripleDES where
    
    secretKeySpec :: SizeSpecifier (SecretKey TripleDES)
    secretKeySpec :: SizeSpecifier (SecretKey TripleDES)
secretKeySpec = SizeSpecifier () -> SizeSpecifier (SecretKey TripleDES)
forall a b. SizeSpecifier a -> SizeSpecifier b
coerceSizeSpec (SizeSpecifier () -> SizeSpecifier (SecretKey TripleDES))
-> SizeSpecifier () -> SizeSpecifier (SecretKey TripleDES)
forall a b. (a -> b) -> a -> b
$ BlockCipher -> SizeSpecifier ()
Botan.blockCipherKeySpec BlockCipher
Botan.tripleDES

instance (MonadRandomIO m )=> SecretKeyGen TripleDES m where

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

instance HasCiphertext TripleDES where

instance BlockCipher TripleDES where

    blockCipherEncrypt :: SecretKey TripleDES -> ByteString -> Maybe (Ciphertext TripleDES)
    blockCipherEncrypt :: SecretKey TripleDES -> ByteString -> Maybe (Ciphertext TripleDES)
blockCipherEncrypt (TripleDESSecretKey ByteString
k) = (ByteString -> Ciphertext TripleDES)
-> Maybe ByteString -> Maybe (Ciphertext TripleDES)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Ciphertext TripleDES
TripleDESCiphertext (Maybe ByteString -> Maybe (Ciphertext TripleDES))
-> (ByteString -> Maybe ByteString)
-> ByteString
-> Maybe (Ciphertext TripleDES)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BlockCipher -> ByteString -> ByteString -> Maybe ByteString
Botan.blockCipherEncrypt BlockCipher
Botan.tripleDES ByteString
k

    blockCipherDecrypt :: SecretKey TripleDES -> Ciphertext TripleDES -> Maybe ByteString
    blockCipherDecrypt :: SecretKey TripleDES -> Ciphertext TripleDES -> Maybe ByteString
blockCipherDecrypt (TripleDESSecretKey ByteString
k) (TripleDESCiphertext ByteString
ct) = BlockCipher -> ByteString -> ByteString -> Maybe ByteString
Botan.blockCipherDecrypt BlockCipher
Botan.tripleDES ByteString
k ByteString
ct

instance HasLazyCiphertext TripleDES where

instance IncrementalBlockCipher TripleDES where

    blockCipherEncryptLazy :: SecretKey TripleDES -> Lazy.ByteString -> Maybe (LazyCiphertext TripleDES)
    blockCipherEncryptLazy :: SecretKey TripleDES
-> ByteString -> Maybe (LazyCiphertext TripleDES)
blockCipherEncryptLazy (TripleDESSecretKey ByteString
k) = (ByteString -> LazyCiphertext TripleDES)
-> Maybe ByteString -> Maybe (LazyCiphertext TripleDES)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> LazyCiphertext TripleDES
TripleDESLazyCiphertext (Maybe ByteString -> Maybe (LazyCiphertext TripleDES))
-> (ByteString -> Maybe ByteString)
-> ByteString
-> Maybe (LazyCiphertext TripleDES)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BlockCipher -> ByteString -> ByteString -> Maybe ByteString
Botan.blockCipherEncryptLazy BlockCipher
Botan.tripleDES ByteString
k

    blockCipherDecryptLazy :: SecretKey TripleDES -> LazyCiphertext TripleDES -> Maybe Lazy.ByteString
    blockCipherDecryptLazy :: SecretKey TripleDES -> LazyCiphertext TripleDES -> Maybe ByteString
blockCipherDecryptLazy (TripleDESSecretKey ByteString
k) (TripleDESLazyCiphertext ByteString
ct) = BlockCipher -> ByteString -> ByteString -> Maybe ByteString
Botan.blockCipherDecryptLazy BlockCipher
Botan.tripleDES ByteString
k ByteString
ct

-- TripleDES blockCipher

tripleDESEncrypt :: SecretKey TripleDES -> ByteString -> Maybe TripleDESCiphertext
tripleDESEncrypt :: SecretKey TripleDES -> ByteString -> Maybe (Ciphertext TripleDES)
tripleDESEncrypt = SecretKey TripleDES -> ByteString -> Maybe (Ciphertext TripleDES)
forall bc.
BlockCipher bc =>
SecretKey bc -> ByteString -> Maybe (Ciphertext bc)
blockCipherEncrypt

tripleDESDecrypt :: SecretKey TripleDES -> TripleDESCiphertext -> Maybe ByteString
tripleDESDecrypt :: SecretKey TripleDES -> Ciphertext TripleDES -> Maybe ByteString
tripleDESDecrypt = SecretKey TripleDES -> Ciphertext TripleDES -> Maybe ByteString
forall bc.
BlockCipher bc =>
SecretKey bc -> Ciphertext bc -> Maybe ByteString
blockCipherDecrypt

tripleDESEncryptLazy :: SecretKey TripleDES -> Lazy.ByteString -> Maybe TripleDESLazyCiphertext
tripleDESEncryptLazy :: SecretKey TripleDES
-> ByteString -> Maybe (LazyCiphertext TripleDES)
tripleDESEncryptLazy = SecretKey TripleDES
-> ByteString -> Maybe (LazyCiphertext TripleDES)
forall bc.
IncrementalBlockCipher bc =>
SecretKey bc -> ByteString -> Maybe (LazyCiphertext bc)
blockCipherEncryptLazy

tripleDESDecryptLazy :: SecretKey TripleDES -> TripleDESLazyCiphertext -> Maybe Lazy.ByteString
tripleDESDecryptLazy :: SecretKey TripleDES -> LazyCiphertext TripleDES -> Maybe ByteString
tripleDESDecryptLazy = SecretKey TripleDES -> LazyCiphertext TripleDES -> Maybe ByteString
forall bc.
IncrementalBlockCipher bc =>
SecretKey bc -> LazyCiphertext bc -> Maybe ByteString
blockCipherDecryptLazy