1
2module KAT_MiyaguchiPreneel (tests) where
3
4import           Crypto.Cipher.AES (AES128)
5import           Crypto.ConstructHash.MiyaguchiPreneel as MiyaguchiPreneel
6
7import           Imports
8
9import qualified Data.ByteString.Char8 as B8
10import qualified Data.ByteArray as B
11import Data.ByteArray.Encoding (Base (Base16), convertFromBase)
12
13
14runMP128 :: ByteString -> ByteString
15runMP128 s = B.convert (MiyaguchiPreneel.compute s :: MiyaguchiPreneel AES128)
16
17hxs :: String -> ByteString
18hxs = either (error . ("hxs:" ++)) id . convertFromBase Base16
19      . B8.pack . filter (/= ' ')
20
21gAES128 :: TestTree
22gAES128 =
23  igroup "aes128"
24  [ runMP128  B8.empty
25    @?=       hxs "66e94bd4 ef8a2c3b 884cfa59 ca342b2e"
26  , runMP128 (hxs "01000000 00000000 00000000 00000000")
27    @?=       hxs "46711816 e91d6ff0 59bbbf2b f58e0fd3"
28  , runMP128 (hxs "00000000 00000000 00000000 00000001")
29    @?=       hxs "58e2fcce fa7e3061 367f1d57 a4e7455b"
30  , runMP128     (hxs $
31                  "00000000 00000000 00000000 00000000" ++
32                  "01")
33    @?=       hxs "a5ff35ae 097adf5d 646abf5e bf4c16f4"
34  ]
35
36igroup :: TestName -> [Assertion] -> TestTree
37igroup nm = testGroup nm . zipWith (flip ($)) [1..] . map icase
38  where
39    icase c i = testCase (show (i :: Int)) c
40
41vectors :: TestTree
42vectors =
43  testGroup "KATs"
44  [ gAES128 ]
45
46tests :: TestTree
47tests =
48    testGroup "MiyaguchiPreneel"
49    [ vectors ]
50