blob: 11cede346162948df366b180852fcfc6c7331fa3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
{-# LANGUAGE CPP #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Crypto.Cipher.ThomasToVincent where
import Crypto.Cipher.Types
import Data.Byteable
import Data.Tagged
import qualified Crypto.Classes as Thomas
#if ! MIN_VERSION_crypto_api(0,11,0)
import qualified Crypto.Modes as Thomas
#endif
newtype ThomasToVincent b = ThomasToVincent b
instance Thomas.BlockCipher b => Cipher (ThomasToVincent b) where
cipherName _ = "ThomasToVincent"
cipherInit k = ThomasToVincent b
where Just b = Thomas.buildKey (toBytes k)
cipherKeySize _ = KeySizeFixed (bitlen `div` 8)
where Tagged bitlen = Thomas.keyLength :: Tagged b Int
instance Thomas.BlockCipher b => BlockCipher (ThomasToVincent b) where
blockSize _ = bitlen `div` 8
where Tagged bitlen = Thomas.blockSize :: Tagged b Int
#if ! MIN_VERSION_crypto_api(0,11,0)
ecbEncrypt (ThomasToVincent k) = Thomas.ecb' k
ecbDecrypt (ThomasToVincent k) = Thomas.unEcb' k
#else
ecbEncrypt (ThomasToVincent k) = Thomas.ecb k
ecbDecrypt (ThomasToVincent k) = Thomas.unEcb k
#endif
|