commit d4da6477f90cc70fada0b4fb89fab70b0365826f
parent 5a1ca64d2f55a5dcb16b1f97d09152c998b862ae
Author: Jared Tobin <jared@jtobin.io>
Date: Tue, 10 Sep 2024 01:21:07 +0400
lib: bring 'parse' into algebra
Diffstat:
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/Crypto/Hash/SHA256.hs b/lib/Crypto/Hash/SHA256.hs
@@ -1,4 +1,5 @@
{-# OPTIONS_GHC -funbox-small-strict-fields #-}
+{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ViewPatterns #-}
@@ -257,7 +258,7 @@ prepare_schedule Block {..} = Schedule {..} where
-- 6.2 steps 2, 3
block_hash :: Registers -> Schedule -> Registers
block_hash r@Registers {..} s = loop 0 r where
- loop t (Registers a b c d e f g h)
+ loop t !(Registers a b c d e f g h)
| t == 64 = Registers {
h0 = a + h0, h1 = b + h1, h2 = c + h2, h3 = d + h3
, h4 = e + h4, h5 = f + h5, h6 = g + h6, h7 = h + h7
@@ -287,9 +288,8 @@ hash :: BS.ByteString -> BS.ByteString
hash =
cat
. L.foldl' alg iv
- . fmap parse
. chunks 64
. pad
where
- alg acc = block_hash acc . prepare_schedule
+ alg acc = block_hash acc . prepare_schedule . parse