hmac-drbg

Pure Haskell HMAC-DRBG (docs.ppad.tech/hmac-drbg).
git clone git://git.ppad.tech/hmac-drbg.git
Log | Files | Refs | README | LICENSE

Main.hs (1470B)


      1 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
      2 {-# LANGUAGE BangPatterns #-}
      3 {-# LANGUAGE OverloadedStrings #-}
      4 
      5 module Main where
      6 
      7 import Criterion.Main
      8 import qualified Crypto.DRBG.HMAC as DRBG
      9 import qualified Crypto.Hash.SHA256 as SHA256
     10 import qualified Crypto.Hash.SHA512 as SHA512
     11 import qualified Data.ByteString as BS
     12 
     13 hmac_sha256 :: BS.ByteString -> BS.ByteString -> BS.ByteString
     14 hmac_sha256 k b = case SHA256.hmac k b of
     15   SHA256.MAC m -> m
     16 
     17 hmac_sha512 :: BS.ByteString -> BS.ByteString -> BS.ByteString
     18 hmac_sha512 k b = case SHA512.hmac k b of
     19   SHA512.MAC m -> m
     20 
     21 main :: IO ()
     22 main = do
     23   !drbg256 <- DRBG.new hmac_sha256 mempty mempty mempty -- no NFData
     24   !drbg512 <- DRBG.new hmac_sha512 mempty mempty mempty -- no NFData
     25   defaultMain [
     26       suite drbg256 drbg512
     27     ]
     28 
     29 suite drbg256 drbg512 =
     30   bgroup "ppad-hmac-drbg" [
     31     bgroup "HMAC-SHA256" [
     32       bench "new" $ whnfAppIO (DRBG.new hmac_sha256 mempty mempty) mempty
     33     , bench "reseed" $ whnfAppIO (DRBG.reseed mempty mempty) drbg256
     34     , bench "gen (32B)"  $ whnfAppIO (DRBG.gen mempty 32) drbg256
     35     , bench "gen (256B)" $ whnfAppIO (DRBG.gen mempty 256) drbg256
     36     ]
     37   , bgroup "HMAC-SHA512" [
     38       bench "new" $ whnfAppIO (DRBG.new hmac_sha512 mempty mempty) mempty
     39     , bench "reseed" $ whnfAppIO (DRBG.reseed mempty mempty) drbg512
     40     , bench "gen (32B)"  $ whnfAppIO (DRBG.gen mempty 32) drbg512
     41     , bench "gen (256B)" $ whnfAppIO (DRBG.gen mempty 256) drbg512
     42     ]
     43   ]
     44