From 5d96c804aeda06819dc34af183cb7551bb8821ae Mon Sep 17 00:00:00 2001 From: Kei Hibino Date: Fri, 8 Apr 2016 16:43:55 +0900 Subject: [PATCH] Add infered cipher version. --- Crypto/ConstructHash/MiyaguchiPreneel.hs | 22 +++++++++++++++------- tests/KAT_MiyaguchiPreneel.hs | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Crypto/ConstructHash/MiyaguchiPreneel.hs b/Crypto/ConstructHash/MiyaguchiPreneel.hs index e7f14b8..0ca83fc 100644 --- a/Crypto/ConstructHash/MiyaguchiPreneel.hs +++ b/Crypto/ConstructHash/MiyaguchiPreneel.hs @@ -10,7 +10,7 @@ -- {-# LANGUAGE GeneralizedNewtypeDeriving #-} module Crypto.ConstructHash.MiyaguchiPreneel - ( mp + ( mp, mp' , MiyaguchiPreneel(..) , cipherInit' ) where @@ -31,12 +31,11 @@ instance Eq (MiyaguchiPreneel a) where -- | Compute Miyaguchi-Preneel one way compress using the supplied block cipher. --- Simple usage /mp (cipherInit' :: ByteString -> AES128) msg/ -mp :: (ByteArrayAccess bin, ByteArray ba, BlockCipher cipher) - => (ba -> cipher) -- ^ key build function to compute Miyaguchi-Preneel - -> bin -- ^ input message - -> MiyaguchiPreneel cipher -- ^ output tag -mp g = MP . foldl' (step $ g . B.convert) (B.replicate bsz 0) . chunks . B.convert +mp' :: (ByteArrayAccess bin, BlockCipher cipher) + => (Bytes -> cipher) -- ^ key build function to compute Miyaguchi-Preneel. care about block-size and key-size + -> bin -- ^ input message + -> MiyaguchiPreneel cipher -- ^ output tag +mp' g = MP . foldl' (step $ g) (B.replicate bsz 0) . chunks . B.convert where bsz = blockSize ( g B.empty {- dummy to get block size -} ) chunks msg @@ -49,6 +48,15 @@ mp g = MP . foldl' (step $ g . B.convert) (B.replicate bsz 0) . chunks . B.conve cipherInit' :: (ByteArray ba, Cipher k) => ba -> k cipherInit' = either (error . show) id . eitherCryptoError . cipherInit +-- | Compute Miyaguchi-Preneel one way compress using the infered block cipher. +-- Only safe when KEY-SIZE equals to BLOCK-SIZE. +-- +-- Simple usage /mp' msg :: MiyaguchiPreneel AES128/ +mp :: (ByteArrayAccess bin, BlockCipher cipher) + => bin -- ^ input message + -> MiyaguchiPreneel cipher -- ^ output tag +mp = mp' cipherInit' + -- | computation step of Miyaguchi-Preneel step :: (ByteArray ba, BlockCipher k) => (ba -> k) diff --git a/tests/KAT_MiyaguchiPreneel.hs b/tests/KAT_MiyaguchiPreneel.hs index 24bfd35..70fc389 100644 --- a/tests/KAT_MiyaguchiPreneel.hs +++ b/tests/KAT_MiyaguchiPreneel.hs @@ -12,7 +12,7 @@ import qualified Data.ByteArray as B runMP128 :: ByteString -> ByteString -runMP128 s = B.convert $ mp (cipherInit' :: ByteString -> AES128) s +runMP128 s = B.convert (mp s :: MiyaguchiPreneel AES128) hxs :: String -> ByteString hxs = BS.pack . rec' where