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

commit abe61aab2315f33f41c0c83e73436f6926a3d8a5
parent c6487458ef620c4f83bdbc7494f5f48c989133b6
Author: Jared Tobin <jared@jtobin.io>
Date:   Sun, 11 Jan 2026 23:08:02 +0400

bench: add basic weigh suite

Diffstat:
Abench/Weight.hs | 48++++++++++++++++++++++++++++++++++++++++++++++++
Mflake.lock | 16++++++++--------
Mppad-hmac-drbg.cabal | 18++++++++++++++++++
3 files changed, 74 insertions(+), 8 deletions(-)

diff --git a/bench/Weight.hs b/bench/Weight.hs @@ -0,0 +1,48 @@ +{-# OPTIONS_GHC -fno-warn-missing-signatures #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE OverloadedStrings #-} + +module Main where + +import Control.DeepSeq +import qualified Crypto.DRBG.HMAC as DRBG +import qualified Crypto.Hash.SHA256 as SHA256 +import qualified Crypto.Hash.SHA512 as SHA512 +import qualified Data.ByteString as BS +import Weigh + +instance NFData (DRBG.DRBG s) where + rnf d = d `seq` () + +instance NFData DRBG.Error where + rnf e = e `seq` () + +hmac_sha256 :: BS.ByteString -> BS.ByteString -> BS.ByteString +hmac_sha256 k b = case SHA256.hmac k b of + SHA256.MAC m -> m + +hmac_sha512 :: BS.ByteString -> BS.ByteString -> BS.ByteString +hmac_sha512 k b = case SHA512.hmac k b of + SHA512.MAC m -> m + +-- note that 'weigh' doesn't work properly in a repl +main :: IO () +main = do + !drbg256 <- DRBG.new hmac_sha256 mempty mempty mempty + !drbg512 <- DRBG.new hmac_sha512 mempty mempty mempty + mainWith $ do + sha256 drbg256 + sha512 drbg512 + +sha256 drbg = wgroup "HMAC-SHA256" $ do + io "new" (DRBG.new hmac_sha256 mempty mempty) mempty + io "reseed" (DRBG.reseed mempty mempty) drbg + io "gen (32B)" (DRBG.gen mempty 32) drbg + io "gen (256B)" (DRBG.gen mempty 256) drbg + +sha512 drbg = wgroup "HMAC-SHA512" $ do + io "new" (DRBG.new hmac_sha512 mempty mempty) mempty + io "reseed" (DRBG.reseed mempty mempty) drbg + io "gen (32B)" (DRBG.gen mempty 32) drbg + io "gen (256B)" (DRBG.gen mempty 256) drbg diff --git a/flake.lock b/flake.lock @@ -105,11 +105,11 @@ ] }, "locked": { - "lastModified": 1768045644, - "narHash": "sha256-8+jLaYRN8iX6NmyotE7DvjfjUIT8I0KOchgcP7uq7Vo=", + "lastModified": 1768121850, + "narHash": "sha256-RxgAI88nZi4o4xYj1v+GC0X5E9adae12dDSmv/GFu2Y=", "ref": "master", - "rev": "4716cd5b4e673e9cb66e4e5e427e5464a7c10977", - "revCount": 116, + "rev": "916595b21319ca270ce8beb9c742bf7e632cccc9", + "revCount": 118, "type": "git", "url": "git://git.ppad.tech/sha256.git" }, @@ -139,11 +139,11 @@ ] }, "locked": { - "lastModified": 1768045869, - "narHash": "sha256-ySqv5fQRz+/9X54yXCuck2QnGyuIqRLpRzanh+Ehl88=", + "lastModified": 1768122380, + "narHash": "sha256-edXb64mZPIIsmgZtX2d98QhR6FmXLDh4emThfoufgz0=", "ref": "master", - "rev": "0fbaba3c091692622744d30016e36ca6b726a819", - "revCount": 42, + "rev": "fd2a1341627c4eaf048613474d4f8e97477f6d09", + "revCount": 44, "type": "git", "url": "git://git.ppad.tech/sha512.git" }, diff --git a/ppad-hmac-drbg.cabal b/ppad-hmac-drbg.cabal @@ -74,3 +74,21 @@ benchmark hmac-drbg-bench , ppad-sha256 >= 0.3 && < 0.4 , ppad-sha512 >= 0.2 && < 0.4 +benchmark hmac-drbg-weigh + type: exitcode-stdio-1.0 + default-language: Haskell2010 + hs-source-dirs: bench + main-is: Weight.hs + + ghc-options: + -rtsopts -O2 -Wall + + build-depends: + base + , bytestring + , deepseq + , ppad-hmac-drbg + , ppad-sha256 >= 0.3 && < 0.4 + , ppad-sha512 >= 0.2 && < 0.4 + , weigh +