Weight.hs (1296B)
1 {-# OPTIONS_GHC -fno-warn-incomplete-uni-patterns -fno-warn-type-defaults #-} 2 {-# OPTIONS_GHC -fno-warn-orphans #-} 3 {-# LANGUAGE BangPatterns #-} 4 {-# LANGUAGE OverloadedStrings #-} 5 6 module Main where 7 8 import Control.DeepSeq 9 import qualified Crypto.Hash.SHA256 as SHA256 10 import qualified Data.ByteString as BS 11 import Weigh 12 13 instance NFData SHA256.MAC where 14 rnf (SHA256.MAC b) = rnf b 15 16 -- note that 'weigh' doesn't work properly in a repl 17 main :: IO () 18 main = mainWith $ do 19 hash 20 hmac 21 22 hash :: Weigh () 23 hash = 24 let !bs0 = BS.replicate 32 0 25 !bs1 = BS.replicate 64 0 26 !bs2 = BS.replicate 128 0 27 !bs3 = BS.replicate 12288 0 28 in wgroup "hash" $ do 29 func "hash (32B input)" SHA256.hash bs0 30 func "hash (64B input)" SHA256.hash bs1 31 func "hash (128B input)" SHA256.hash bs2 32 func "hash (12288B input)" SHA256.hash bs3 33 34 hmac :: Weigh () 35 hmac = 36 let !key = BS.replicate 32 9 37 !bs0 = BS.replicate 32 0 38 !bs1 = BS.replicate 64 0 39 !bs2 = BS.replicate 128 0 40 !bs3 = BS.replicate 12288 0 41 in wgroup "hmac" $ do 42 func "hmac (32B input)" (SHA256.hmac key) bs0 43 func "hmac (64B input)" (SHA256.hmac key) bs1 44 func "hmac (128B input)" (SHA256.hmac key) bs2 45 func "hmac (12288B input)" (SHA256.hmac key) bs3 46