diff options
Diffstat (limited to 'Crypto/Cipher/ThomasToVincent.hs')
-rw-r--r-- | Crypto/Cipher/ThomasToVincent.hs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/Crypto/Cipher/ThomasToVincent.hs b/Crypto/Cipher/ThomasToVincent.hs index 5a68cf3..cf5cdee 100644 --- a/Crypto/Cipher/ThomasToVincent.hs +++ b/Crypto/Cipher/ThomasToVincent.hs | |||
@@ -5,7 +5,12 @@ module Crypto.Cipher.ThomasToVincent where | |||
5 | import qualified Data.ByteString as S | 5 | import qualified Data.ByteString as S |
6 | import Crypto.Cipher.Types | 6 | import Crypto.Cipher.Types |
7 | import Crypto.Cipher.Cast5 | 7 | import Crypto.Cipher.Cast5 |
8 | #if defined(VERSION_cryptonite) | ||
9 | import qualified Data.ByteArray as Bytes | ||
10 | import Crypto.Error | ||
11 | #else | ||
8 | import Data.Byteable | 12 | import Data.Byteable |
13 | #endif | ||
9 | 14 | ||
10 | import Data.Tagged | 15 | import Data.Tagged |
11 | {- | 16 | {- |
@@ -19,9 +24,14 @@ endif | |||
19 | type ThomasToVincent b = b | 24 | type ThomasToVincent b = b |
20 | 25 | ||
21 | instance Cast5Bits size => Cipher (Cast5 size) where | 26 | instance Cast5Bits size => Cipher (Cast5 size) where |
22 | cipherName _ = "CAST-5" | 27 | cipherName _ = "CAST-"++show (cast5bits (undefined :: size)) |
28 | #if defined(VERSION_cryptonite) | ||
29 | cipherInit k = CryptoPassed b | ||
30 | where Just b = buildKey (Bytes.convert k) | ||
31 | #else | ||
23 | cipherInit k = b | 32 | cipherInit k = b |
24 | where Just b = buildKey (toBytes k) | 33 | where Just b = buildKey (toBytes k) |
34 | #endif | ||
25 | cipherKeySize _ = KeySizeFixed (bitlen `div` 8) | 35 | cipherKeySize _ = KeySizeFixed (bitlen `div` 8) |
26 | where Tagged bitlen = keyLength :: Tagged (Cast5 size) Int | 36 | where Tagged bitlen = keyLength :: Tagged (Cast5 size) Int |
27 | 37 | ||
@@ -42,14 +52,25 @@ instance Cast5Bits size => BlockCipher (Cast5 size) where | |||
42 | blockSize _ = bitlen `div` 8 | 52 | blockSize _ = bitlen `div` 8 |
43 | where Tagged bitlen = Crypto.Cipher.Cast5.blockSize :: Tagged (Cast5 size) Int | 53 | where Tagged bitlen = Crypto.Cipher.Cast5.blockSize :: Tagged (Cast5 size) Int |
44 | 54 | ||
55 | -- ecbEncrypt :: (BlockCipher cipher, ByteArray ba) => cipher -> ba -> ba | ||
45 | -- modeEcb' :: BlockCipher k => k -> B.ByteString -> B.ByteString | 56 | -- modeEcb' :: BlockCipher k => k -> B.ByteString -> B.ByteString |
46 | ecbEncrypt k msg = | 57 | ecbEncrypt k msg = |
47 | let chunks = chunkFor' k msg | 58 | #if defined(VERSION_cryptonite) |
59 | let chunks = chunkFor' k $ Bytes.convert msg | ||
60 | in Bytes.convert $ S.concat $ map (encryptBlock k) chunks | ||
61 | #else | ||
62 | let chunks = chunkFor' k $ msg | ||
48 | in S.concat $ map (encryptBlock k) chunks | 63 | in S.concat $ map (encryptBlock k) chunks |
64 | #endif | ||
49 | 65 | ||
50 | ecbDecrypt k ct = | 66 | ecbDecrypt k ct = |
67 | #if defined(VERSION_cryptonite) | ||
68 | let chunks = chunkFor' k $ Bytes.convert ct | ||
69 | in Bytes.convert $ S.concat $ map (decryptBlock k) chunks | ||
70 | #else | ||
51 | let chunks = chunkFor' k ct | 71 | let chunks = chunkFor' k ct |
52 | in S.concat $ map (decryptBlock k) chunks | 72 | in S.concat $ map (decryptBlock k) chunks |
73 | #endif | ||
53 | 74 | ||
54 | 75 | ||
55 | {- | 76 | {- |