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 c832ff090cd2f301d18c8f04886a2124d392a75f
parent a0df63be84a18f10f5676cf1de9f2ffd0046ba67
Author: Jared Tobin <jared@jtobin.io>
Date:   Sun,  1 Feb 2026 14:12:15 +0400

lib: more cleanup

Diffstat:
MREADME.md | 15++++++++-------
Mlib/Crypto/Hash/SHA256/Arm.hs | 21+++++++--------------
2 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/README.md b/README.md @@ -64,16 +64,17 @@ benchmark suite): ``` benchmarking ppad-sha256/SHA256 (32B input)/hash - time 48.14 ns (48.12 ns .. 48.18 ns) - 1.000 R² (1.000 R² .. 1.000 R²) - mean 48.17 ns (48.10 ns .. 48.22 ns) - std dev 196.5 ps (107.8 ps .. 358.1 ps) + time 67.70 ns (66.08 ns .. 71.11 ns) + 0.992 R² (0.979 R² .. 1.000 R²) + mean 66.55 ns (65.91 ns .. 68.79 ns) + std dev 3.919 ns (720.2 ps .. 8.253 ns) + variance introduced by outliers: 78% (severely inflated) benchmarking ppad-sha256/HMAC-SHA256 (32B input)/hmac - time 193.1 ns (192.9 ns .. 193.5 ns) + time 135.7 ns (135.2 ns .. 136.1 ns) 1.000 R² (1.000 R² .. 1.000 R²) - mean 193.4 ns (193.2 ns .. 193.7 ns) - std dev 767.2 ps (507.4 ps .. 1.233 ns) + mean 136.3 ns (135.9 ns .. 136.7 ns) + std dev 1.298 ns (1.141 ns .. 1.474 ns) ``` You should compile with the 'llvm' flag for maximum performance. diff --git a/lib/Crypto/Hash/SHA256/Arm.hs b/lib/Crypto/Hash/SHA256/Arm.hs @@ -12,13 +12,13 @@ -- -- ARM crypto extension support for SHA-256. -module Crypto.Hash.SHA256.Arm -- ( - -- sha256_arm_available - --, hash - --, hash_with - --, hmac - --) where - where +module Crypto.Hash.SHA256.Arm ( + sha256_arm_available + , hash + , hmac + , _hmac_rr + , _hmac_rsb + ) where import qualified Data.ByteString as BS import qualified Data.ByteString.Internal as BI @@ -46,7 +46,6 @@ fi :: (Integral a, Num b) => a -> b fi = fromIntegral {-# INLINE fi #-} - peek_registers :: Ptr Word32 -> Registers @@ -205,8 +204,6 @@ _hmac_bb rp bp k m = do update rp bp inner {-# INLINABLE _hmac_bb #-} --- | HMAC(key, v || sep || data) using ARM crypto extensions. --- Writes result to destination pointer. _hmac_rsb :: Ptr Word32 -- ^ destination (8 Word32s) -> Ptr Word32 -- ^ scratch block buffer (16 Word32s) @@ -226,8 +223,6 @@ _hmac_rsb rp bp k v sep dat = do update rp bp inner {-# INLINABLE _hmac_rsb #-} --- | Hash (v || sep || dat) with ARM crypto extensions. --- Assumes register state already initialized at rp. _hash_vsb :: Ptr Word32 -- ^ register state -> Ptr Word32 -- ^ block buffer @@ -241,11 +236,9 @@ _hash_vsb rp bp el v sep dat@(BI.PS _ _ l) -- first block is complete: v || sep || dat[0:31] let !b0 = parse_vsb v sep dat update rp bp b0 - -- hash remaining complete blocks from dat[31:] let !rest = BU.unsafeDrop 31 dat !restLen = l - 31 hash_blocks rp bp rest - -- handle final padding let !finLen = restLen `rem` 64 !fin = BU.unsafeDrop (restLen - finLen) rest !total = el + 33 + fi l