hkdf

Pure Haskell HMAC-based KDF (docs.ppad.tech/hkdf).
git clone git://git.ppad.tech/hkdf.git
Log | Files | Refs | README | LICENSE

commit 6a3a9f7875aead4ea1a247b4683d99854fe6818a
parent e7e77bfbbca84e4ae9bae364173207400a417caf
Author: Jared Tobin <jared@jtobin.io>
Date:   Sun, 11 Jan 2026 10:21:59 +0400

lib: use new hmac api

Diffstat:
Mbench/Main.hs | 13+++++++++++--
Mflake.lock | 16++++++++--------
Mppad-hkdf.cabal | 10+++++-----
Mtest/Main.hs | 6+++---
4 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/bench/Main.hs b/bench/Main.hs @@ -6,22 +6,31 @@ import Criterion.Main import qualified Crypto.KDF.HMAC as KDF import qualified Crypto.Hash.SHA256 as SHA256 import qualified Crypto.Hash.SHA512 as SHA512 +import qualified Data.ByteString as BS main :: IO () main = defaultMain [ suite ] +hmac_sha256 :: BS.ByteString -> BS.ByteString -> BS.ByteString +hmac_sha256 k b = case SHA256.hmac k b of + SHA256.MAC mac -> mac + +hmac_sha512 :: BS.ByteString -> BS.ByteString -> BS.ByteString +hmac_sha512 k b = case SHA512.hmac k b of + SHA512.MAC mac -> mac + suite :: Benchmark suite = bgroup "ppad-hkdf" [ bgroup "HKDF-SHA256" [ bench "derive (outlen 32)" $ - nf (KDF.derive SHA256.hmac "muh salt" "muh info" 32) "muh secret" + nf (KDF.derive hmac_sha256 "muh salt" "muh info" 32) "muh secret" ] , bgroup "HKDF-SHA512" [ bench "derive (outlen 32)" $ - nf (KDF.derive SHA512.hmac "muh salt" "muh info" 32) "muh secret" + nf (KDF.derive hmac_sha512 "muh salt" "muh info" 32) "muh secret" ] ] diff --git a/flake.lock b/flake.lock @@ -105,11 +105,11 @@ ] }, "locked": { - "lastModified": 1767897559, - "narHash": "sha256-UabcPqE4O+h1HHv02LjanjuorRS91OODqk0ek55VrmQ=", + "lastModified": 1768045644, + "narHash": "sha256-8+jLaYRN8iX6NmyotE7DvjfjUIT8I0KOchgcP7uq7Vo=", "ref": "master", - "rev": "528d9cf07ca756fb5422cab174849fe0708620d0", - "revCount": 111, + "rev": "4716cd5b4e673e9cb66e4e5e427e5464a7c10977", + "revCount": 116, "type": "git", "url": "git://git.ppad.tech/sha256.git" }, @@ -139,11 +139,11 @@ ] }, "locked": { - "lastModified": 1767897585, - "narHash": "sha256-QxLlHu8+tGKZ9aOKFnVOqNwEn+LCuNF27kY2dxOCYxo=", + "lastModified": 1768045869, + "narHash": "sha256-ySqv5fQRz+/9X54yXCuck2QnGyuIqRLpRzanh+Ehl88=", "ref": "master", - "rev": "428e2e09c345a0cb255d9aab432606308872c014", - "revCount": 38, + "rev": "0fbaba3c091692622744d30016e36ca6b726a819", + "revCount": 42, "type": "git", "url": "git://git.ppad.tech/sha512.git" }, diff --git a/ppad-hkdf.cabal b/ppad-hkdf.cabal @@ -1,6 +1,6 @@ cabal-version: 3.0 name: ppad-hkdf -version: 0.3.1 +version: 0.3.2 synopsis: A HMAC-based key derivation function license: MIT license-file: LICENSE @@ -53,8 +53,8 @@ test-suite hkdf-tests , bytestring , ppad-base16 , ppad-hkdf - , ppad-sha256 - , ppad-sha512 + , ppad-sha256 >= 0.3 && < 0.4 + , ppad-sha512 >= 0.2 && < 0.3 , tasty , tasty-hunit , text @@ -73,6 +73,6 @@ benchmark hkdf-bench , bytestring , criterion , ppad-hkdf - , ppad-sha256 - , ppad-sha512 + , ppad-sha256 >= 0.3 && < 0.4 + , ppad-sha512 >= 0.2 && < 0.3 diff --git a/test/Main.hs b/test/Main.hs @@ -56,8 +56,8 @@ execute h W.HkdfTest {..} = testCase t_msg $ do | ht_result == "invalid" -> assertBool "invalid" (pec /= out) | otherwise -> assertEqual mempty pec out where - hmac = case h of - SHA256 -> SHA256.hmac - SHA512 -> SHA512.hmac + hmac k b = case h of + SHA256 -> let SHA256.MAC mac = SHA256.hmac k b in mac + SHA512 -> let SHA512.MAC mac = SHA512.hmac k b in mac t_msg = "test " <> show ht_tcId -- XX embellish