Skip to content

Commit b8d60d4

Browse files
author
Thomas M. DuBuisson
committed
Retab, revert to do notation from 7ab502
1 parent bd286aa commit b8d60d4

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

Data/Digest/Pure/MD5.hs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
-----------------------------------------------------------------------------
2020

2121
module Data.Digest.Pure.MD5
22-
(
22+
(
2323
-- * Types
2424
MD5Context
2525
, MD5Digest
@@ -29,8 +29,8 @@ module Data.Digest.Pure.MD5
2929
, md5
3030
, md5Update
3131
, md5Finalize
32-
-- * Crypto-API interface
33-
, Hash(..)
32+
-- * Crypto-API interface
33+
, Hash(..)
3434
) where
3535

3636
import Data.ByteString.Unsafe (unsafeUseAsCString)
@@ -111,24 +111,24 @@ md5Update :: MD5Context -> B.ByteString -> MD5Context
111111
md5Update ctx bs
112112
| B.length bs `rem` blockSizeBytes /= 0 = error "Invalid use of hash update routine (see crypto-api Hash class semantics)"
113113
| otherwise =
114-
let bs' = if isAligned bs then bs else B.copy bs -- copying has been measured as a net win on my x86 system
115-
new = blockAndDo (mdPartial ctx) bs'
116-
in ctx { mdPartial = new, mdTotalLen = mdTotalLen ctx + fromIntegral (B.length bs) }
114+
let bs' = if isAligned bs then bs else B.copy bs -- copying has been measured as a net win on my x86 system
115+
new = blockAndDo (mdPartial ctx) bs'
116+
in ctx { mdPartial = new, mdTotalLen = mdTotalLen ctx + fromIntegral (B.length bs) }
117117

118118
blockAndDo :: MD5Partial -> B.ByteString -> MD5Partial
119119
blockAndDo !ctx bs
120120
| B.length bs == 0 = ctx
121121
| otherwise =
122-
let !new = performMD5Update ctx bs
123-
in blockAndDo new (unsafeDrop blockSizeBytes bs)
122+
let !new = performMD5Update ctx bs
123+
in blockAndDo new (unsafeDrop blockSizeBytes bs)
124124
{-# INLINE blockAndDo #-}
125125

126126
-- Assumes ByteString length == blockSizeBytes, will fold the
127127
-- context across calls to applyMD5Rounds.
128128
performMD5Update :: MD5Partial -> B.ByteString -> MD5Partial
129129
performMD5Update !par@(MD5Par !a !b !c !d) !bs =
130130
let MD5Par a' b' c' d' = applyMD5Rounds par bs
131-
in MD5Par (a' + a) (b' + b) (c' + c) (d' + d)
131+
in MD5Par (a' + a) (b' + b) (c' + c) (d' + d)
132132
{-# INLINE performMD5Update #-}
133133

134134
isAligned (PS _ off _) = off `rem` 4 == 0
@@ -298,16 +298,21 @@ instance S.Serialize MD5Context where
298298
return $ MD5Ctx p l
299299

300300
instance S.Serialize MD5Partial where
301-
put (MD5Par a b c d) = P.putWord32le a >> P.putWord32le b >> P.putWord32le c >> P.putWord32le d
302-
get = G.getWord32le >>= (\a ->
303-
G.getWord32le >>= (\b ->
304-
G.getWord32le >>= (\c ->
305-
G.getWord32le >>= (\d ->
306-
return (MD5Par a b c d)))))
301+
put (MD5Par a b c d) = do
302+
P.putWord32le a
303+
P.putWord32le b
304+
P.putWord32le c
305+
P.putWord32le d
306+
get = do
307+
a <- G.getWord32le
308+
b <- G.getWord32le
309+
c <- G.getWord32le
310+
d <- G.getWord32le
311+
return (MD5Par a b c d)
307312

308313
instance Hash MD5Context MD5Digest where
309-
outputLength = Tagged 128
310-
blockLength = Tagged 512
311-
initialCtx = md5InitialContext
312-
updateCtx = md5Update
313-
finalize = md5Finalize
314+
outputLength = Tagged 128
315+
blockLength = Tagged 512
316+
initialCtx = md5InitialContext
317+
updateCtx = md5Update
318+
finalize = md5Finalize

Test/Bench.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Data.Digest.Pure.MD5
2-
import Benchmark.Crypto
2+
-- import Benchmark.Crypto
33
import Criterion.Main
44

55
main = defaultMain [benchmarkHash (undefined :: MD5Digest) "pureMD5"]

0 commit comments

Comments
 (0)