packages feed

crypton-2.3.1 / tests / ConstructHash / MiyaguchiPreneelSpec.hs

module ConstructHash.MiyaguchiPreneelSpec (spec) whereimport Crypto.Cipher.AES (AES128)import Crypto.ConstructHash.MiyaguchiPreneel as MiyaguchiPreneelimport Importsimport qualified Data.ByteArray as Bimport Data.ByteArray.Encoding (Base (Base16), convertFromBase)import qualified Data.ByteString.Char8 as B8runMP128 :: ByteString -> ByteStringrunMP128 s = B.convert (MiyaguchiPreneel.compute s :: MiyaguchiPreneel AES128)hxs :: String -> ByteStringhxs =    either (error . ("hxs:" ++)) id        . convertFromBase Base16        . B8.pack        . filter (/= ' ')-- | Values from pycryptodome's AES, chained by hand with 0x80 padding.gAES128 :: SpecgAES128 =    igroup        "aes128"        [ runMP128 B8.empty            `shouldBe` hxs "bad78e72 6c1ec02b 7ebfe92b 23d9ec34"        , runMP128 (hxs "01000000 00000000 00000000 00000000")            `shouldBe` hxs "ef161f2b d4ce9bcd 8a771570 a8fa51c9"        , runMP128 (hxs "00000000 00000000 00000000 00000001")            `shouldBe` hxs "a7206541 44a17514 cdb1a563 05420a8c"        , runMP128            ( hxs $                "00000000 00000000 00000000 00000000"                    ++ "01"            )            `shouldBe` hxs "fc2553f0 50b5fcdb 1bc589ce 811a7b43"        , runMP128 (hxs "00000000 00000000 00000000 000000")            `shouldBe` hxs "ff49b8df 4a97cbe0 3833e661 97620d2d"        , runMP128 (B8.pack "a")            `shouldBe` hxs "f4899ebc 761071fe fe85dcc2 4354711e"        ]-- | Zero padding made these pairs collide.collisions :: Speccollisions =    describe "trailing zeros" $ do        it "\"a\" and \"a\\0\" differ" $            runMP128 (B8.pack "a") `shouldNotBe` runMP128 (B8.pack "a\0")        it "empty and a zero block differ" $            runMP128 B8.empty `shouldNotBe` runMP128 (B.replicate 16 0)igroup :: String -> [Expectation] -> Specigroup nm = describe nm . sequence_ . zipWith (flip ($)) [1 ..] . map icase  where    icase c i = it (show (i :: Int)) cvectors :: Specvectors =    describe "KATs" $ do        gAES128spec :: Specspec = do    vectors    collisions