From 67c76c126bacc6eb5cd4f510db8d8ca3533c19e9 Mon Sep 17 00:00:00 2001 From: Vincent Hanquez Date: Thu, 9 Apr 2015 07:45:13 +0100 Subject: [PATCH] [Camellia] remove the need to go through a ByteString to make the key schedule --- Crypto/Cipher/Camellia/Primitive.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Crypto/Cipher/Camellia/Primitive.hs b/Crypto/Cipher/Camellia/Primitive.hs index 40db84a..b399c70 100644 --- a/Crypto/Cipher/Camellia/Primitive.hs +++ b/Crypto/Cipher/Camellia/Primitive.hs @@ -124,9 +124,9 @@ data Camellia = Camellia , ke :: Vector Word64 } -setKeyInterim :: B.ByteString -> (Word128, Word128, Word128, Word128) +setKeyInterim :: ByteArray key => key -> (Word128, Word128, Word128, Word128) setKeyInterim keyseed = (w64tow128 kL, w64tow128 kR, w64tow128 kA, w64tow128 kB) - where kL = (w8tow64 $ B.take 8 keyseed, w8tow64 $ B.drop 8 keyseed) + where kL = (byteArrayToW64BE keyseed 0, byteArrayToW64BE keyseed 8) kR = (0, 0) kA = let d1 = (fst kL `xor` fst kR) @@ -155,7 +155,7 @@ initCamellia :: ByteArray key initCamellia key | byteArrayLength key /= 16 = CryptoFailed $ CryptoError_KeySizeInvalid | otherwise = - let (kL, _, kA, _) = setKeyInterim (byteArrayToBS key) in + let (kL, _, kA, _) = setKeyInterim key in let (kw1, kw2) = w128tow64 (kL `rotl128` 0) in let (k1, k2) = w128tow64 (kA `rotl128` 0) in