[Fencommits] fenserve: better error reporting in SHA1.hs
Benja Fallenstein
benja.fallenstein at gmail.com
Sun Apr 1 21:06:35 EEST 2007
Sun Apr 1 21:06:17 EEST 2007 Benja Fallenstein <benja.fallenstein at gmail.com>
* better error reporting in SHA1.hs
diff -rN -u old-fenserve/SHA1.hs new-fenserve/SHA1.hs
--- old-fenserve/SHA1.hs 2007-04-01 21:06:35.000000000 +0300
+++ new-fenserve/SHA1.hs 2007-04-01 21:06:35.000000000 +0300
@@ -84,7 +84,7 @@
sha1_step_1_2_pad_length bytes = B.append bytes (B.pack (padding ++ lenBytes)) where
padding = 128:replicate' (shiftR (fromIntegral $ (440-len) `mod` 512) 3) 0
lenBytes = map fromIntegral $ size_split 8 len
- len = fromInteger ((toInteger $ 8 * B.length bytes) `mod` (2^64))
+ len = fromInteger ((8 * toInteger (B.length bytes)) `mod` (2^64))
replicate' :: Word16 -> a -> [a]
replicate' 0 _ = []
@@ -104,14 +104,15 @@
st = newArray (0,79) 0 >>= sha1_step_4_work abcde s 0
sha1_step_4_work :: ABCDE -> ByteString -> Int -> Arr s -> ST s ABCDE
-sha1_step_4_work abcde s offs arr | offs >= B.length s = return abcde
+sha1_step_4_work abcde s offs arr | offs == B.length s = return abcde
+ | offs > B.length s = error "SHA1: bug"
sha1_step_4_work abcde0 s offs arr = do
sha1_ws 0 s offs arr
sha1_add_ws 16 arr
let f1 x y z = (x .&. y) .|. ((complement x) .&. z)
f2 x y z = x `xor` y `xor` z
f3 x y z = (x .&. y) .|. (x .&. z) .|. (y .&. z)
- abcde1 <- fold_arr (doit f1 0x5a827999) abcde0 arr 0 19
+ abcde1 <- fold_arr (doit f1 0x5a827999) abcde0 arr 0 19
abcde2 <- fold_arr (doit f2 0x6ed9eba1) abcde1 arr 20 39
abcde3 <- fold_arr (doit f3 0x8f1bbcdc) abcde2 arr 40 59
abcde4 <- fold_arr (doit f2 0xca62c1d6) abcde3 arr 60 79
More information about the Fencommits
mailing list