sha256

Pure Haskell SHA-256, HMAC-SHA256 (docs.ppad.tech/sha256).
git clone git://git.ppad.tech/sha256.git
Log | Files | Refs | README | LICENSE

commit a8cc368e231be532ae3053ec9586e5e63d68d792
parent cad73ada9423c24ba80796335b1d3d8e0d1bbb88
Author: Jared Tobin <jared@jtobin.io>
Date:   Sat,  3 Jan 2026 19:40:47 -0330

bench: add weigh suite

Diffstat:
Abench/Weight.hs | 37+++++++++++++++++++++++++++++++++++++
Mppad-sha256.cabal | 18++++++++++++++++++
2 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/bench/Weight.hs b/bench/Weight.hs @@ -0,0 +1,37 @@ +{-# OPTIONS_GHC -fno-warn-incomplete-uni-patterns -fno-warn-type-defaults #-} +{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE OverloadedStrings #-} + +module Main where + +import qualified Crypto.Hash.SHA256 as SHA256 +import qualified Data.ByteString as BS +import Weigh + +-- note that 'weigh' doesn't work properly in a repl +main :: IO () +main = mainWith $ do + hash + hmac + +hash :: Weigh () +hash = + let !bs0 = BS.replicate 32 0 + !bs1 = BS.replicate 64 0 + !bs2 = BS.replicate 128 0 + in wgroup "hash" $ do + func' "hash (32B input)" SHA256.hash bs0 + func' "hash (64B input)" SHA256.hash bs1 + func' "hash (128B input)" SHA256.hash bs2 + +hmac :: Weigh () +hmac = + let !key = BS.replicate 32 9 + !bs0 = BS.replicate 32 0 + !bs1 = BS.replicate 64 0 + !bs2 = BS.replicate 128 0 + in wgroup "hmac" $ do + func' "hmac (32B input)" (SHA256.hmac key) bs0 + func' "hmac (64B input)" (SHA256.hmac key) bs1 + func' "hmac (128B input)" (SHA256.hmac key) bs2 + diff --git a/ppad-sha256.cabal b/ppad-sha256.cabal @@ -73,3 +73,21 @@ benchmark sha256-bench , ppad-sha256 , SHA +benchmark sha256-weigh + type: exitcode-stdio-1.0 + default-language: Haskell2010 + hs-source-dirs: bench + main-is: Weight.hs + + ghc-options: + -rtsopts -O2 -Wall -fno-warn-orphans + if flag(llvm) + ghc-options: -fllvm + + build-depends: + base + , bytestring + , deepseq + , ppad-sha256 + , weigh +