ppad-ripemd160 0.1.0 → 0.1.1
raw patch · 3 files changed
+33/−30 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG +9/−0
- lib/Crypto/Hash/RIPEMD160.hs +23/−29
- ppad-ripemd160.cabal +1/−1
CHANGELOG view
@@ -0,0 +1,9 @@+# Changelog++- 0.1.1 (2025-01-07)+ * Minor bytestring-handling optimisation.++- 0.1.0 (2024-11-12)+ * Initial release, supporting RIPEMD-160 and HMAC-RIPEMD160 on strict+ and lazy bytestrings.+
lib/Crypto/Hash/RIPEMD160.hs view
@@ -80,14 +80,14 @@ splitAt64 :: BL.ByteString -> SLPair splitAt64 = splitAt' (64 :: Int) where splitAt' _ BLI.Empty = SLPair mempty BLI.Empty- splitAt' n (BLI.Chunk c cs) =- if n < BS.length c+ splitAt' n (BLI.Chunk c@(BI.PS _ _ l) cs) =+ if n < l then -- n < BS.length c, so unsafe_splitAt is safe let !(SSPair c0 c1) = unsafe_splitAt n c in SLPair c0 (BLI.Chunk c1 cs) else- let SLPair cs' cs'' = splitAt' (n - BS.length c) cs+ let SLPair cs' cs'' = splitAt' (n - l) cs in SLPair (c <> cs') cs'' -- variant of Data.ByteString.splitAt that behaves like an incremental@@ -117,10 +117,8 @@ in fi (if r < 0 then r + 64 else r) pad :: BS.ByteString -> BS.ByteString-pad m = BL.toStrict . BSB.toLazyByteString $ padded where- l = fi (BS.length m)+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)@@ -195,7 +193,7 @@ f0, f1, f2, f3, f4 :: Word32 -> Word32 -> Word32 -> Word32 f0 x y z = x `B.xor` y `B.xor` z {-# INLINE f0 #-}-f1 x y z = (x .&. y) .|. ((B.complement x) .&. z)+f1 x y z = (x .&. y) .|. (B.complement x .&. z) {-# INLINE f1 #-} f2 x y z = (x .|. B.complement y) `B.xor` z {-# INLINE f2 #-}@@ -227,37 +225,37 @@ Word32 -> Word32 -> Registers -> Registers -> Int -> Int -> Pair round1 x x' (Registers a b c d e) (Registers a' b' c' d' e') s s' =- let t = (B.rotateL (a + f0 b c d + x + k0) s) + e+ let t = B.rotateL (a + f0 b c d + x + k0) s + e r0 = Registers e t b (B.rotateL c 10) d- t' = (B.rotateL (a' + f4 b' c' d' + x' + k0') s') + e'+ t' = B.rotateL (a' + f4 b' c' d' + x' + k0') s' + e' r1 = Registers e' t' b' (B.rotateL c' 10) d' in Pair r0 r1 round2 x x' (Registers a b c d e) (Registers a' b' c' d' e') s s' =- let t = (B.rotateL (a + f1 b c d + x + k1) s) + e+ let t = B.rotateL (a + f1 b c d + x + k1) s + e r0 = Registers e t b (B.rotateL c 10) d- t' = (B.rotateL (a' + f3 b' c' d' + x' + k1') s') + e'+ t' = B.rotateL (a' + f3 b' c' d' + x' + k1') s' + e' r1 = Registers e' t' b' (B.rotateL c' 10) d' in Pair r0 r1 round3 x x' (Registers a b c d e) (Registers a' b' c' d' e') s s' =- let t = (B.rotateL (a + f2 b c d + x + k2) s) + e+ let t = B.rotateL (a + f2 b c d + x + k2) s + e r0 = Registers e t b (B.rotateL c 10) d- t' = (B.rotateL (a' + f2 b' c' d' + x' + k2') s') + e'+ t' = B.rotateL (a' + f2 b' c' d' + x' + k2') s' + e' r1 = Registers e' t' b' (B.rotateL c' 10) d' in Pair r0 r1 round4 x x' (Registers a b c d e) (Registers a' b' c' d' e') s s' =- let t = (B.rotateL (a + f3 b c d + x + k3) s) + e+ let t = B.rotateL (a + f3 b c d + x + k3) s + e r0 = Registers e t b (B.rotateL c 10) d- t' = (B.rotateL (a' + f1 b' c' d' + x' + k3') s') + e'+ t' = B.rotateL (a' + f1 b' c' d' + x' + k3') s' + e' r1 = Registers e' t' b' (B.rotateL c' 10) d' in Pair r0 r1 round5 x x' (Registers a b c d e) (Registers a' b' c' d' e') s s' =- let t = (B.rotateL (a + f4 b c d + x + k4) s) + e+ let t = B.rotateL (a + f4 b c d + x + k4) s + e r0 = Registers e t b (B.rotateL c 10) d- t' = (B.rotateL (a' + f0 b' c' d' + x' + k4') s') + e'+ t' = B.rotateL (a' + f0 b' c' d' + x' + k4') s' + e' r1 = Registers e' t' b' (B.rotateL c' 10) d' in Pair r0 r1 @@ -456,7 +454,7 @@ :: BS.ByteString -- ^ key -> BS.ByteString -- ^ text -> BS.ByteString-hmac mk text =+hmac mk@(BI.PS _ _ l) text = let step1 = k <> BS.replicate (64 - lk) 0x00 step2 = BS.map (B.xor 0x36) step1 step3 = step2 <> text@@ -465,11 +463,9 @@ step6 = step5 <> step4 in hash step6 where- !(KeyAndLen k lk) =- let l = BS.length mk- in if l > 64- then KeyAndLen (hash mk) 20- else KeyAndLen mk l+ !(KeyAndLen k lk)+ | l > 64 = KeyAndLen (hash mk) 20+ | otherwise = KeyAndLen mk l -- | Produce a message authentication code for a lazy bytestring, based -- on the provided (strict, bytestring) key, via RIPEMD-160.@@ -485,7 +481,7 @@ :: BS.ByteString -- ^ key -> BL.ByteString -- ^ text -> BS.ByteString-hmac_lazy mk text =+hmac_lazy mk@(BI.PS _ _ l) text = let step1 = k <> BS.replicate (64 - lk) 0x00 step2 = BS.map (B.xor 0x36) step1 step3 = BL.fromStrict step2 <> text@@ -494,9 +490,7 @@ step6 = step5 <> step4 in hash step6 where- !(KeyAndLen k lk) =- let l = BS.length mk- in if l > 64- then KeyAndLen (hash mk) 20- else KeyAndLen mk l+ !(KeyAndLen k lk)+ | l > 64 = KeyAndLen (hash mk) 20+ | otherwise = KeyAndLen mk l
ppad-ripemd160.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: ppad-ripemd160-version: 0.1.0+version: 0.1.1 synopsis: The RIPEMD-160 hashing algorithm. license: MIT license-file: LICENSE