diff options
Diffstat (limited to 'Crypto/Cipher/ThomasToVincent.hs')
-rw-r--r-- | Crypto/Cipher/ThomasToVincent.hs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Crypto/Cipher/ThomasToVincent.hs b/Crypto/Cipher/ThomasToVincent.hs new file mode 100644 index 0000000..11cede3 --- /dev/null +++ b/Crypto/Cipher/ThomasToVincent.hs | |||
@@ -0,0 +1,35 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
2 | {-# LANGUAGE ScopedTypeVariables #-} | ||
3 | module Crypto.Cipher.ThomasToVincent where | ||
4 | |||
5 | import Crypto.Cipher.Types | ||
6 | import Data.Byteable | ||
7 | |||
8 | import Data.Tagged | ||
9 | import qualified Crypto.Classes as Thomas | ||
10 | #if ! MIN_VERSION_crypto_api(0,11,0) | ||
11 | import qualified Crypto.Modes as Thomas | ||
12 | #endif | ||
13 | |||
14 | |||
15 | newtype ThomasToVincent b = ThomasToVincent b | ||
16 | |||
17 | instance Thomas.BlockCipher b => Cipher (ThomasToVincent b) where | ||
18 | cipherName _ = "ThomasToVincent" | ||
19 | cipherInit k = ThomasToVincent b | ||
20 | where Just b = Thomas.buildKey (toBytes k) | ||
21 | cipherKeySize _ = KeySizeFixed (bitlen `div` 8) | ||
22 | where Tagged bitlen = Thomas.keyLength :: Tagged b Int | ||
23 | |||
24 | instance Thomas.BlockCipher b => BlockCipher (ThomasToVincent b) where | ||
25 | blockSize _ = bitlen `div` 8 | ||
26 | where Tagged bitlen = Thomas.blockSize :: Tagged b Int | ||
27 | #if ! MIN_VERSION_crypto_api(0,11,0) | ||
28 | ecbEncrypt (ThomasToVincent k) = Thomas.ecb' k | ||
29 | ecbDecrypt (ThomasToVincent k) = Thomas.unEcb' k | ||
30 | #else | ||
31 | ecbEncrypt (ThomasToVincent k) = Thomas.ecb k | ||
32 | ecbDecrypt (ThomasToVincent k) = Thomas.unEcb k | ||
33 | #endif | ||
34 | |||
35 | |||