cryptopals

Matasano's cryptopals challenges (cryptopals.com).
git clone git://git.jtobin.io/cryptopals.git
Log | Files | Refs | README | LICENSE

MAC.hs (762B)


      1 module Cryptopals.MAC (
      2     sha1mac
      3   , verifysha1mac
      4 
      5   , md4mac
      6   , verifymd4mac
      7   ) where
      8 
      9 import qualified Data.ByteString.Lazy.Char8 as BL8
     10 import qualified Data.ByteString.Lazy as BSL
     11 import qualified Cryptopals.Digest.Pure.MD4 as M
     12 import qualified Cryptopals.Digest.Pure.SHA as S
     13 
     14 sha1mac :: BSL.ByteString -> BSL.ByteString -> BSL.ByteString
     15 sha1mac k m = S.bytestringDigest . S.sha1 $ k <> m
     16 
     17 verifysha1mac :: BSL.ByteString -> BSL.ByteString -> BSL.ByteString -> Bool
     18 verifysha1mac key mac message = sha1mac key message == mac
     19 
     20 md4mac :: BSL.ByteString -> BSL.ByteString -> BSL.ByteString
     21 md4mac k m = M.md4 $ k <> m
     22 
     23 verifymd4mac :: BSL.ByteString -> BSL.ByteString -> BSL.ByteString -> Bool
     24 verifymd4mac key mac message = md4mac key message == mac
     25