packages feed

ppad-ripemd160 0.1.2 → 0.1.3

raw patch · 3 files changed

+25/−19 lines, 3 files

Files

CHANGELOG view
@@ -1,6 +1,10 @@ # Changelog -- 0.1.2 (2025-10-21)+- 0.1.3 (2025-02-06)+  * Makes a minor optimization to register concatenation (swapping five+    builders for 3) and also refines builder realization by input size.++- 0.1.2 (2025-01-21)   * Improves padding handling for the strict bytestring case, yielding     performance increases for both 'hash' and 'hmac'. 
lib/Crypto/Hash/RIPEMD160.hs view
@@ -100,6 +100,15 @@   WSPair (unsafe_word32le (BI.BS x 4)) (BI.BS (plusForeignPtr x 4) (l - 4)) {-# INLINE unsafe_parseWsPair #-} +-- builder realization strategies++to_strict :: BSB.Builder -> BS.ByteString+to_strict = BL.toStrict . BSB.toLazyByteString++to_strict_small :: BSB.Builder -> BS.ByteString+to_strict_small = BL.toStrict . BE.toLazyByteStringWith+  (BE.safeStrategy 128 BE.smallChunkSize) mempty+ -- message padding and parsing  -- this is the standard padding for merkle-damgård constructions; see e.g.@@ -117,9 +126,9 @@   in  fi (if r < 0 then r + 64 else r)  pad :: BS.ByteString -> BS.ByteString-pad m@(BI.PS _ _ (fi -> l)) =-    BL.toStrict . BE.toLazyByteStringWith-      (BE.safeStrategy 128 BE.smallChunkSize) mempty $ padded+pad m@(BI.PS _ _ (fi -> l))+    | l < 128   = to_strict_small padded+    | otherwise = to_strict padded   where     padded = BSB.byteString m           <> fill (sol l) (BSB.word8 0x80)@@ -202,10 +211,7 @@   padding l k bs     | k == 0 =           pure-        . BL.toStrict-          -- more efficient for small builder-        . BE.toLazyByteStringWith-            (BE.safeStrategy 128 BE.smallChunkSize) mempty+        . to_strict         $ bs <> BSB.word64LE (l * 8)     | otherwise =         let nacc = bs <> BSB.word8 0x00@@ -462,16 +468,12 @@ -- register concatenation cat :: Registers -> BS.ByteString cat Registers {..} =-    BL.toStrict-    -- more efficient for small builder-  . BE.toLazyByteStringWith (BE.safeStrategy 128 BE.smallChunkSize) mempty-  $ mconcat [-        BSB.word32LE h0-      , BSB.word32LE h1-      , BSB.word32LE h2-      , BSB.word32LE h3-      , BSB.word32LE h4-      ]+  let w64_0 = fi h1 `B.shiftL` 32 .|. fi h0+      w64_1 = fi h3 `B.shiftL` 32 .|. fi h2+  in  to_strict_small $+           BSB.word64LE w64_0+        <> BSB.word64LE w64_1+        <> BSB.word32LE h4  -- | Compute a condensed representation of a strict bytestring via --   RIPEMD-160.
ppad-ripemd160.cabal view
@@ -1,6 +1,6 @@ cabal-version:      3.0 name:               ppad-ripemd160-version:            0.1.2+version:            0.1.3 synopsis:           The RIPEMD-160 hashing algorithm. license:            MIT license-file:       LICENSE