ppad-ripemd160 0.1.1 → 0.1.2
raw patch · 3 files changed
+81/−7 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG +4/−0
- lib/Crypto/Hash/RIPEMD160.hs +76/−6
- ppad-ripemd160.cabal +1/−1
CHANGELOG view
@@ -1,5 +1,9 @@ # Changelog +- 0.1.2 (2025-10-21)+ * Improves padding handling for the strict bytestring case, yielding+ performance increases for both 'hash' and 'hmac'.+ - 0.1.1 (2025-01-07) * Minor bytestring-handling optimisation.
lib/Crypto/Hash/RIPEMD160.hs view
@@ -113,15 +113,85 @@ -- k such that (l + 1 + k) mod 64 = 56 sol :: Word64 -> Word64 sol l =- let r = 56 - fi l `mod` 64 - 1 :: Integer -- fi prevents underflow+ let r = 56 - fi l `rem` 64 - 1 :: Integer -- fi prevents underflow in fi (if r < 0 then r + 64 else r) pad :: BS.ByteString -> BS.ByteString-pad m@(BI.PS _ _ (fi -> l)) = BL.toStrict . BSB.toLazyByteString $ padded where- padded = BSB.byteString m <> fill (sol l) (BSB.word8 0x80)- fill j !acc- | j == 0 = acc <> BSB.word64LE (l * 8)- | otherwise = fill (pred j) (acc <> BSB.word8 0x00)+pad m@(BI.PS _ _ (fi -> l)) =+ BL.toStrict . BE.toLazyByteStringWith+ (BE.safeStrategy 128 BE.smallChunkSize) mempty $ padded+ where+ padded = BSB.byteString m+ <> fill (sol l) (BSB.word8 0x80)+ <> BSB.word64LE (l * 8)++ fill j !acc+ | j `rem` 8 == 0 =+ loop64 j acc+ | (j - 7) `rem` 8 == 0 =+ loop64 (j - 7) acc+ <> BSB.word32LE 0x00+ <> BSB.word16LE 0x00+ <> BSB.word8 0x00+ | (j - 6) `rem` 8 == 0 =+ loop64 (j - 6) acc+ <> BSB.word32LE 0x00+ <> BSB.word16LE 0x00+ | (j - 5) `rem` 8 == 0 =+ loop64 (j - 5) acc+ <> BSB.word32LE 0x00+ <> BSB.word8 0x00+ | (j - 4) `rem` 8 == 0 =+ loop64 (j - 4) acc+ <> BSB.word32LE 0x00+ | (j - 3) `rem` 8 == 0 =+ loop64 (j - 3) acc+ <> BSB.word16LE 0x00+ <> BSB.word8 0x00+ | (j - 2) `rem` 8 == 0 =+ loop64 (j - 2) acc+ <> BSB.word16LE 0x00+ | (j - 1) `rem` 8 == 0 =+ loop64 (j - 1) acc+ <> BSB.word8 0x00++ | j `rem` 4 == 0 =+ loop32 j acc+ | (j - 3) `rem` 4 == 0 =+ loop32 (j - 3) acc+ <> BSB.word16LE 0x00+ <> BSB.word8 0x00+ | (j - 2) `rem` 4 == 0 =+ loop32 (j - 2) acc+ <> BSB.word16LE 0x00+ | (j - 1) `rem` 4 == 0 =+ loop32 (j - 1) acc+ <> BSB.word8 0x00++ | j `rem` 2 == 0 =+ loop16 j acc+ | (j - 1) `rem` 2 == 0 =+ loop16 (j - 1) acc+ <> BSB.word8 0x00++ | otherwise =+ loop8 j acc++ loop64 j !acc+ | j == 0 = acc+ | otherwise = loop64 (j - 8) (acc <> BSB.word64LE 0x00)++ loop32 j !acc+ | j == 0 = acc+ | otherwise = loop32 (j - 4) (acc <> BSB.word32LE 0x00)++ loop16 j !acc+ | j == 0 = acc+ | otherwise = loop16 (j - 2) (acc <> BSB.word16LE 0x00)++ loop8 j !acc+ | j == 0 = acc+ | otherwise = loop8 (pred j) (acc <> BSB.word8 0x00) pad_lazy :: BL.ByteString -> BL.ByteString pad_lazy (BL.toChunks -> m) = BL.fromChunks (walk 0 m) where
ppad-ripemd160.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: ppad-ripemd160-version: 0.1.1+version: 0.1.2 synopsis: The RIPEMD-160 hashing algorithm. license: MIT license-file: LICENSE