sha512

Pure Haskell SHA-512, HMAC-SHA512 (docs.ppad.tech/sha512).
git clone git://git.ppad.tech/sha512.git
Log | Files | Refs | README | LICENSE

commit 292d7eea71e9e6c070dfcc4f4403136e091e8bca
parent c728bf0f555605fcd93dffe7288342678f908b13
Author: Jared Tobin <jared@jtobin.io>
Date:   Thu,  8 Jan 2026 18:18:41 +0400

bench: add weigh suite

Diffstat:
Abench/Weight.hs | 41+++++++++++++++++++++++++++++++++++++++++
Mppad-sha512.cabal | 18++++++++++++++++++
2 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/bench/Weight.hs b/bench/Weight.hs @@ -0,0 +1,41 @@ +{-# OPTIONS_GHC -fno-warn-incomplete-uni-patterns -fno-warn-type-defaults #-} +{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE OverloadedStrings #-} + +module Main where + +import qualified Crypto.Hash.SHA512 as SHA512 +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 + !bs3 = BS.replicate 12288 0 + in wgroup "hash" $ do + func' "hash (32B input)" SHA512.hash bs0 + func' "hash (64B input)" SHA512.hash bs1 + func' "hash (128B input)" SHA512.hash bs2 + func' "hash (12288B input)" SHA512.hash bs3 + +hmac :: Weigh () +hmac = + let !key = BS.replicate 32 9 + !bs0 = BS.replicate 32 0 + !bs1 = BS.replicate 64 0 + !bs2 = BS.replicate 128 0 + !bs3 = BS.replicate 12288 0 + in wgroup "hmac" $ do + func' "hmac (32B input)" (SHA512.hmac key) bs0 + func' "hmac (64B input)" (SHA512.hmac key) bs1 + func' "hmac (128B input)" (SHA512.hmac key) bs2 + func' "hmac (12288B input)" (SHA512.hmac key) bs3 + diff --git a/ppad-sha512.cabal b/ppad-sha512.cabal @@ -80,3 +80,21 @@ benchmark sha512-bench , ppad-sha512 , SHA +benchmark sha512-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-sha512 + , weigh +