hkdf

Pure Haskell HKDF (docs.ppad.tech/hkdf).
git clone git://git.ppad.tech/hkdf.git
Log | Files | Refs | README | LICENSE

commit 23aa0854422478c55449a46847b4988390a2bed8
parent 30944b3aade937c10f3ece555c982a4f1fb85a34
Author: Jared Tobin <jared@jtobin.io>
Date:   Fri, 10 Jan 2025 15:00:05 +0400

bench: add suite

Diffstat:
Mbench/Main.hs | 22+++++++++++++++++++++-
Mlib/Crypto/KDF/HMAC.hs | 2++
2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/bench/Main.hs b/bench/Main.hs @@ -1,5 +1,25 @@ +{-# LANGUAGE OverloadedStrings #-} module Main where +import Criterion.Main +import qualified Crypto.KDF.HMAC as K +import qualified Crypto.Hash.SHA256 as SHA256 +import qualified Crypto.Hash.SHA512 as SHA512 + main :: IO () -main = pure () +main = defaultMain [ + suite + ] + +suite :: Benchmark +suite = + bgroup "ppad-hkdf" [ + bgroup "HKDF-SHA256" [ + bench "32" $ nf (K.hkdf SHA256.hmac "muh salt" "muh info" 32) "muh secret" + ] + , bgroup "HKDF-SHA512" [ + bench "32" $ nf (K.hkdf SHA512.hmac "muh salt" "muh info" 32) "muh secret" + ] + ] + diff --git a/lib/Crypto/KDF/HMAC.hs b/lib/Crypto/KDF/HMAC.hs @@ -56,6 +56,7 @@ extract extract (HMACEnv hmac hashlen) salt@(BI.PS _ _ l) ikm | l == 0 = hmac (BS.replicate hashlen 0x00) ikm | otherwise = hmac salt ikm +{-# INLINE extract #-} expand :: HMACEnv @@ -73,6 +74,7 @@ expand (HMACEnv hmac hashlen) info (fi -> len) prk | otherwise = let nt = hmac prk (tl <> info <> BS.singleton (fi j)) in go (succ j) (t <> BSB.byteString nt) nt +{-# INLINE expand #-} -- | HMAC-based key derivation function. --