apply convertFromBase.

This commit is contained in:
Kei Hibino 2016-06-08 01:05:08 +09:00
parent f9c1aa713f
commit 5e76b8af5f

View File

@ -7,25 +7,22 @@ import Crypto.ConstructHash.MiyaguchiPreneel
import Imports
import Data.Char (digitToInt)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteArray as B
import Data.ByteArray.Encoding (Base (Base16), convertFromBase)
runMP128 :: ByteString -> ByteString
runMP128 s = B.convert (mp s :: MiyaguchiPreneel AES128)
hxs :: String -> ByteString
hxs = BS.pack . rec' where
dtoW8 = fromIntegral . digitToInt
rec' (' ':xs) = rec' xs
rec' (x:y:xs) = dtoW8 x * 16 + dtoW8 y : rec' xs
rec' [_] = error "hxs: invalid hex pattern."
rec' [] = []
hxs = either (error . ("hxs:" ++)) id . convertFromBase Base16
. B8.pack . filter (/= ' ')
gAES128 :: TestTree
gAES128 =
igroup "aes128"
[ runMP128 BS.empty
[ runMP128 B8.empty
@?= hxs "66e94bd4 ef8a2c3b 884cfa59 ca342b2e"
, runMP128 (hxs "01000000 00000000 00000000 00000000")
@?= hxs "46711816 e91d6ff0 59bbbf2b f58e0fd3"