sha256

Pure Haskell SHA-256, HMAC-SHA256 as specified by RFC's 6234 and 2104.
git clone git://git.ppad.tech/sha256.git
Log | Files | Refs | README | LICENSE

commit d22b69f3c6a134ae347a74afc885a6b2b9b269b7
parent 8afe8eafcae637cce7f7dcc999926e0d11e7f174
Author: Jared Tobin <jared@jtobin.io>
Date:   Thu, 12 Sep 2024 09:16:45 +0400

meta: add hash-large executable for profiling

Diffstat:
MREADME.md | 3++-
Mppad-sha256.cabal | 12++++++++++++
Asrc/HashLarge.hs | 37+++++++++++++++++++++++++++++++++++++
3 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md @@ -51,7 +51,8 @@ Haddocks (API documentation, etc.) are hosted at ## Performance -Our aim is best-in-class performance for pure, highly-auditable Haskell code. +The eventual aim is best-in-class performance for pure, highly-auditable +Haskell code. Benchmark figures at present: diff --git a/ppad-sha256.cabal b/ppad-sha256.cabal @@ -60,3 +60,15 @@ benchmark sha256-bench , bytestring , criterion , ppad-sha256 + +executable hash-large + main-is: HashLarge.hs + ghc-options: -rtsopts -Wall -O2 + default-language: Haskell2010 + hs-source-dirs: src + build-depends: + base + , base16-bytestring + , bytestring + , ppad-sha256 + diff --git a/src/HashLarge.hs b/src/HashLarge.hs @@ -0,0 +1,37 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Main where + +import qualified Crypto.Hash.SHA256 as SHA256 +import qualified Data.ByteString.Lazy as BL +import qualified Data.ByteString.Builder as BSB +import qualified Data.ByteString.Base16 as B16 +import System.Environment + +main :: IO () +main = do + args <- getArgs + case args of + mode:[] -> + if mode == "make" + then make + else hash + _ -> error "incorrect args" + +hash :: IO () +hash = do + input <- BL.readFile "ppad-sha256-large.dat" + let digest = B16.encode $ SHA256.hash_lazy input + print digest + +make :: IO () +make = BL.writeFile "ppad-sha256-large.dat" big_input where + big_input :: BL.ByteString + big_input = go (16777216 :: Int) mempty where + go j acc + | j == 0 = BSB.toLazyByteString acc + | otherwise = + let nacc = acc <> BSB.lazyByteString + "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno" + in go (pred j) nacc +