packages feed

SHA 1.2.0.2 → 1.2.1

raw patch · 4 files changed

+257/−239 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Data/Digest/Pure/SHA.hs view
@@ -14,7 +14,7 @@        , bytestringDigest #ifdef SHA_TEST        , toBigEndianBS, fromBigEndianBS-       , find_k+       , calc_k        , padSHA1, padSHA512 #endif        )@@ -142,19 +142,21 @@ generic_pad a b lSize bs = BS.concat [bs, pad_bytes, pad_length]  where   l = fromIntegral $ BS.length bs * 8-  k = find_k a b l+  k = calc_k a b l   -- INVARIANT: k is necessarily > 0, and (k + 1) is a multiple of 8.-  k_bytes = (k + 1) `div` 8-  pad_bytes = BS.pack $ [0x80] ++ (take (fromIntegral $ k_bytes - 1) [0,0 ..])+  k_bytes    = (k + 1) `div` 8+  pad_bytes  = BS.singleton 0x80 `BS.append` BS.replicate nZeroBytes 0+  nZeroBytes = fromIntegral $ k_bytes - 1   pad_length = toBigEndianBS lSize l --- Given a, b, and l, find a k such that (l + 1 + k) mod b = a. This is an--- astoundingly brain-dead implementation.-find_k :: Word64 -> Word64 -> Word64 -> Word64-find_k a b l = try_k 7+-- Given a, b, and l, calculate the smallest k such that (l + 1 + k) mod b = a.+calc_k :: Word64 -> Word64 -> Word64 -> Word64+calc_k a b l =+  if r <= -1+    then fromIntegral r + b+    else fromIntegral r  where-  try_k k | (l + 1 + k) `mod` b == a = k-          | otherwise                = try_k (k + 8)+  r = toInteger a - toInteger l `mod` toInteger b - 1  toBigEndianBS :: (Integral a, Bits a) => Int -> a -> ByteString toBigEndianBS s val = BS.pack $ map getBits [s - 8, s - 16 .. 0]@@ -163,8 +165,8 @@  #ifdef SHA_TEST fromBigEndianBS :: (Integral a, Bits a) => ByteString -> a-fromBigEndianBS bs =-  BS.foldl (\ acc x -> (acc `shiftL` 8) + (fromIntegral x)) 0 bs+fromBigEndianBS =+  BS.foldl (\ acc x -> (acc `shiftL` 8) + fromIntegral x) 0 #endif  -- --------------------------------------------------------------------------@@ -176,41 +178,43 @@ {-# SPECIALIZE ch :: Word32 -> Word32 -> Word32 -> Word32 #-} {-# SPECIALIZE ch :: Word64 -> Word64 -> Word64 -> Word64 #-} ch :: Bits a => a -> a -> a -> a-ch x y z = (x .&. y) `xor` ((complement x) .&. z)--{-# SPECIALIZE parity :: Word32 -> Word32 -> Word32 -> Word32 #-}-{-# SPECIALIZE parity :: Word64 -> Word64 -> Word64 -> Word64 #-}-parity :: Bits a => a -> a -> a -> a-parity x y z = x `xor` y `xor` z+ch x y z = (x .&. y) `xor` (complement x .&. z)  {-# SPECIALIZE maj :: Word32 -> Word32 -> Word32 -> Word32 #-} {-# SPECIALIZE maj :: Word64 -> Word64 -> Word64 -> Word64 #-} maj :: Bits a => a -> a -> a -> a-maj x y z = (x .&. y) `xor` (x .&. z) `xor` (y .&. z)+maj x y z = (x .&. (y .|. z)) .|. (y .&. z)+-- note:+--   the original functions is (x & y) ^ (x & z) ^ (y & z)+--   if you fire off truth tables, this is equivalent to +--     (x & y) | (x & z) | (y & z)+--   which you can the use distribution on:+--     (x & (y | z)) | (y & z)+--   which saves us one operation.  bsig256_0 :: Word32 -> Word32-bsig256_0 x = (rotate x (-2)) `xor` (rotate x (-13)) `xor` (rotate x (-22))+bsig256_0 x = rotate x (-2) `xor` rotate x (-13) `xor` rotate x (-22)  bsig256_1 :: Word32 -> Word32-bsig256_1 x = (rotate x (-6)) `xor` (rotate x (-11)) `xor` (rotate x (-25))+bsig256_1 x = rotate x (-6) `xor` rotate x (-11) `xor` rotate x (-25)  lsig256_0 :: Word32 -> Word32-lsig256_0 x = (rotate x (-7)) `xor` (rotate x (-18)) `xor` (shiftR x 3)+lsig256_0 x = rotate x (-7) `xor` rotate x (-18) `xor` shiftR x 3  lsig256_1 :: Word32 -> Word32-lsig256_1 x = (rotate x (-17)) `xor` (rotate x (-19)) `xor` (shiftR x 10)+lsig256_1 x = rotate x (-17) `xor` rotate x (-19) `xor` shiftR x 10  bsig512_0 :: Word64 -> Word64-bsig512_0 x = (rotate x (-28)) `xor` (rotate x (-34)) `xor` (rotate x (-39))+bsig512_0 x = rotate x (-28) `xor` rotate x (-34) `xor` rotate x (-39)  bsig512_1 :: Word64 -> Word64-bsig512_1 x = (rotate x (-14)) `xor` (rotate x (-18)) `xor` (rotate x (-41))+bsig512_1 x = rotate x (-14) `xor` rotate x (-18) `xor` rotate x (-41)  lsig512_0 :: Word64 -> Word64-lsig512_0 x = (rotate x (-1)) `xor` (rotate x (-8)) `xor` (shiftR x 7)+lsig512_0 x = rotate x (-1) `xor` rotate x (-8) `xor` shiftR x 7  lsig512_1 :: Word64 -> Word64-lsig512_1 x = (rotate x (-19)) `xor` (rotate x (-61)) `xor` (shiftR x 6)+lsig512_1 x = rotate x (-19) `xor` rotate x (-61) `xor` shiftR x 6  -- -------------------------------------------------------------------------- --@@ -358,54 +362,54 @@   w13 <- getWord32be   w14 <- getWord32be   w15 <- getWord32be-  let w16 = (lsig256_1 w14) + w09 + (lsig256_0 w01) + w00-      w17 = (lsig256_1 w15) + w10 + (lsig256_0 w02) + w01-      w18 = (lsig256_1 w16) + w11 + (lsig256_0 w03) + w02-      w19 = (lsig256_1 w17) + w12 + (lsig256_0 w04) + w03-      w20 = (lsig256_1 w18) + w13 + (lsig256_0 w05) + w04-      w21 = (lsig256_1 w19) + w14 + (lsig256_0 w06) + w05-      w22 = (lsig256_1 w20) + w15 + (lsig256_0 w07) + w06-      w23 = (lsig256_1 w21) + w16 + (lsig256_0 w08) + w07-      w24 = (lsig256_1 w22) + w17 + (lsig256_0 w09) + w08-      w25 = (lsig256_1 w23) + w18 + (lsig256_0 w10) + w09-      w26 = (lsig256_1 w24) + w19 + (lsig256_0 w11) + w10-      w27 = (lsig256_1 w25) + w20 + (lsig256_0 w12) + w11-      w28 = (lsig256_1 w26) + w21 + (lsig256_0 w13) + w12-      w29 = (lsig256_1 w27) + w22 + (lsig256_0 w14) + w13-      w30 = (lsig256_1 w28) + w23 + (lsig256_0 w15) + w14-      w31 = (lsig256_1 w29) + w24 + (lsig256_0 w16) + w15-      w32 = (lsig256_1 w30) + w25 + (lsig256_0 w17) + w16-      w33 = (lsig256_1 w31) + w26 + (lsig256_0 w18) + w17-      w34 = (lsig256_1 w32) + w27 + (lsig256_0 w19) + w18-      w35 = (lsig256_1 w33) + w28 + (lsig256_0 w20) + w19-      w36 = (lsig256_1 w34) + w29 + (lsig256_0 w21) + w20-      w37 = (lsig256_1 w35) + w30 + (lsig256_0 w22) + w21-      w38 = (lsig256_1 w36) + w31 + (lsig256_0 w23) + w22-      w39 = (lsig256_1 w37) + w32 + (lsig256_0 w24) + w23-      w40 = (lsig256_1 w38) + w33 + (lsig256_0 w25) + w24-      w41 = (lsig256_1 w39) + w34 + (lsig256_0 w26) + w25-      w42 = (lsig256_1 w40) + w35 + (lsig256_0 w27) + w26-      w43 = (lsig256_1 w41) + w36 + (lsig256_0 w28) + w27-      w44 = (lsig256_1 w42) + w37 + (lsig256_0 w29) + w28-      w45 = (lsig256_1 w43) + w38 + (lsig256_0 w30) + w29-      w46 = (lsig256_1 w44) + w39 + (lsig256_0 w31) + w30-      w47 = (lsig256_1 w45) + w40 + (lsig256_0 w32) + w31-      w48 = (lsig256_1 w46) + w41 + (lsig256_0 w33) + w32-      w49 = (lsig256_1 w47) + w42 + (lsig256_0 w34) + w33-      w50 = (lsig256_1 w48) + w43 + (lsig256_0 w35) + w34-      w51 = (lsig256_1 w49) + w44 + (lsig256_0 w36) + w35-      w52 = (lsig256_1 w50) + w45 + (lsig256_0 w37) + w36-      w53 = (lsig256_1 w51) + w46 + (lsig256_0 w38) + w37-      w54 = (lsig256_1 w52) + w47 + (lsig256_0 w39) + w38-      w55 = (lsig256_1 w53) + w48 + (lsig256_0 w40) + w39-      w56 = (lsig256_1 w54) + w49 + (lsig256_0 w41) + w40-      w57 = (lsig256_1 w55) + w50 + (lsig256_0 w42) + w41-      w58 = (lsig256_1 w56) + w51 + (lsig256_0 w43) + w42-      w59 = (lsig256_1 w57) + w52 + (lsig256_0 w44) + w43-      w60 = (lsig256_1 w58) + w53 + (lsig256_0 w45) + w44-      w61 = (lsig256_1 w59) + w54 + (lsig256_0 w46) + w45-      w62 = (lsig256_1 w60) + w55 + (lsig256_0 w47) + w46-      w63 = (lsig256_1 w61) + w56 + (lsig256_0 w48) + w47+  let w16 = lsig256_1 w14 + w09 + lsig256_0 w01 + w00+      w17 = lsig256_1 w15 + w10 + lsig256_0 w02 + w01+      w18 = lsig256_1 w16 + w11 + lsig256_0 w03 + w02+      w19 = lsig256_1 w17 + w12 + lsig256_0 w04 + w03+      w20 = lsig256_1 w18 + w13 + lsig256_0 w05 + w04+      w21 = lsig256_1 w19 + w14 + lsig256_0 w06 + w05+      w22 = lsig256_1 w20 + w15 + lsig256_0 w07 + w06+      w23 = lsig256_1 w21 + w16 + lsig256_0 w08 + w07+      w24 = lsig256_1 w22 + w17 + lsig256_0 w09 + w08+      w25 = lsig256_1 w23 + w18 + lsig256_0 w10 + w09+      w26 = lsig256_1 w24 + w19 + lsig256_0 w11 + w10+      w27 = lsig256_1 w25 + w20 + lsig256_0 w12 + w11+      w28 = lsig256_1 w26 + w21 + lsig256_0 w13 + w12+      w29 = lsig256_1 w27 + w22 + lsig256_0 w14 + w13+      w30 = lsig256_1 w28 + w23 + lsig256_0 w15 + w14+      w31 = lsig256_1 w29 + w24 + lsig256_0 w16 + w15+      w32 = lsig256_1 w30 + w25 + lsig256_0 w17 + w16+      w33 = lsig256_1 w31 + w26 + lsig256_0 w18 + w17+      w34 = lsig256_1 w32 + w27 + lsig256_0 w19 + w18+      w35 = lsig256_1 w33 + w28 + lsig256_0 w20 + w19+      w36 = lsig256_1 w34 + w29 + lsig256_0 w21 + w20+      w37 = lsig256_1 w35 + w30 + lsig256_0 w22 + w21+      w38 = lsig256_1 w36 + w31 + lsig256_0 w23 + w22+      w39 = lsig256_1 w37 + w32 + lsig256_0 w24 + w23+      w40 = lsig256_1 w38 + w33 + lsig256_0 w25 + w24+      w41 = lsig256_1 w39 + w34 + lsig256_0 w26 + w25+      w42 = lsig256_1 w40 + w35 + lsig256_0 w27 + w26+      w43 = lsig256_1 w41 + w36 + lsig256_0 w28 + w27+      w44 = lsig256_1 w42 + w37 + lsig256_0 w29 + w28+      w45 = lsig256_1 w43 + w38 + lsig256_0 w30 + w29+      w46 = lsig256_1 w44 + w39 + lsig256_0 w31 + w30+      w47 = lsig256_1 w45 + w40 + lsig256_0 w32 + w31+      w48 = lsig256_1 w46 + w41 + lsig256_0 w33 + w32+      w49 = lsig256_1 w47 + w42 + lsig256_0 w34 + w33+      w50 = lsig256_1 w48 + w43 + lsig256_0 w35 + w34+      w51 = lsig256_1 w49 + w44 + lsig256_0 w36 + w35+      w52 = lsig256_1 w50 + w45 + lsig256_0 w37 + w36+      w53 = lsig256_1 w51 + w46 + lsig256_0 w38 + w37+      w54 = lsig256_1 w52 + w47 + lsig256_0 w39 + w38+      w55 = lsig256_1 w53 + w48 + lsig256_0 w40 + w39+      w56 = lsig256_1 w54 + w49 + lsig256_0 w41 + w40+      w57 = lsig256_1 w55 + w50 + lsig256_0 w42 + w41+      w58 = lsig256_1 w56 + w51 + lsig256_0 w43 + w42+      w59 = lsig256_1 w57 + w52 + lsig256_0 w44 + w43+      w60 = lsig256_1 w58 + w53 + lsig256_0 w45 + w44+      w61 = lsig256_1 w59 + w54 + lsig256_0 w46 + w45+      w62 = lsig256_1 w60 + w55 + lsig256_0 w47 + w46+      w63 = lsig256_1 w61 + w56 + lsig256_0 w48 + w47   return $ SHA256Sched w00 w01 w02 w03 w04 w05 w06 w07 w08 w09                        w10 w11 w12 w13 w14 w15 w16 w17 w18 w19                        w20 w21 w22 w23 w24 w25 w26 w27 w28 w29@@ -449,70 +453,70 @@   w13 <- getWord64be   w14 <- getWord64be   w15 <- getWord64be-  let w16 = (lsig512_1 w14) + w09 + (lsig512_0 w01) + w00-      w17 = (lsig512_1 w15) + w10 + (lsig512_0 w02) + w01-      w18 = (lsig512_1 w16) + w11 + (lsig512_0 w03) + w02-      w19 = (lsig512_1 w17) + w12 + (lsig512_0 w04) + w03-      w20 = (lsig512_1 w18) + w13 + (lsig512_0 w05) + w04-      w21 = (lsig512_1 w19) + w14 + (lsig512_0 w06) + w05-      w22 = (lsig512_1 w20) + w15 + (lsig512_0 w07) + w06-      w23 = (lsig512_1 w21) + w16 + (lsig512_0 w08) + w07-      w24 = (lsig512_1 w22) + w17 + (lsig512_0 w09) + w08-      w25 = (lsig512_1 w23) + w18 + (lsig512_0 w10) + w09-      w26 = (lsig512_1 w24) + w19 + (lsig512_0 w11) + w10-      w27 = (lsig512_1 w25) + w20 + (lsig512_0 w12) + w11-      w28 = (lsig512_1 w26) + w21 + (lsig512_0 w13) + w12-      w29 = (lsig512_1 w27) + w22 + (lsig512_0 w14) + w13-      w30 = (lsig512_1 w28) + w23 + (lsig512_0 w15) + w14-      w31 = (lsig512_1 w29) + w24 + (lsig512_0 w16) + w15-      w32 = (lsig512_1 w30) + w25 + (lsig512_0 w17) + w16-      w33 = (lsig512_1 w31) + w26 + (lsig512_0 w18) + w17-      w34 = (lsig512_1 w32) + w27 + (lsig512_0 w19) + w18-      w35 = (lsig512_1 w33) + w28 + (lsig512_0 w20) + w19-      w36 = (lsig512_1 w34) + w29 + (lsig512_0 w21) + w20-      w37 = (lsig512_1 w35) + w30 + (lsig512_0 w22) + w21-      w38 = (lsig512_1 w36) + w31 + (lsig512_0 w23) + w22-      w39 = (lsig512_1 w37) + w32 + (lsig512_0 w24) + w23-      w40 = (lsig512_1 w38) + w33 + (lsig512_0 w25) + w24-      w41 = (lsig512_1 w39) + w34 + (lsig512_0 w26) + w25-      w42 = (lsig512_1 w40) + w35 + (lsig512_0 w27) + w26-      w43 = (lsig512_1 w41) + w36 + (lsig512_0 w28) + w27-      w44 = (lsig512_1 w42) + w37 + (lsig512_0 w29) + w28-      w45 = (lsig512_1 w43) + w38 + (lsig512_0 w30) + w29-      w46 = (lsig512_1 w44) + w39 + (lsig512_0 w31) + w30-      w47 = (lsig512_1 w45) + w40 + (lsig512_0 w32) + w31-      w48 = (lsig512_1 w46) + w41 + (lsig512_0 w33) + w32-      w49 = (lsig512_1 w47) + w42 + (lsig512_0 w34) + w33-      w50 = (lsig512_1 w48) + w43 + (lsig512_0 w35) + w34-      w51 = (lsig512_1 w49) + w44 + (lsig512_0 w36) + w35-      w52 = (lsig512_1 w50) + w45 + (lsig512_0 w37) + w36-      w53 = (lsig512_1 w51) + w46 + (lsig512_0 w38) + w37-      w54 = (lsig512_1 w52) + w47 + (lsig512_0 w39) + w38-      w55 = (lsig512_1 w53) + w48 + (lsig512_0 w40) + w39-      w56 = (lsig512_1 w54) + w49 + (lsig512_0 w41) + w40-      w57 = (lsig512_1 w55) + w50 + (lsig512_0 w42) + w41-      w58 = (lsig512_1 w56) + w51 + (lsig512_0 w43) + w42-      w59 = (lsig512_1 w57) + w52 + (lsig512_0 w44) + w43-      w60 = (lsig512_1 w58) + w53 + (lsig512_0 w45) + w44-      w61 = (lsig512_1 w59) + w54 + (lsig512_0 w46) + w45-      w62 = (lsig512_1 w60) + w55 + (lsig512_0 w47) + w46-      w63 = (lsig512_1 w61) + w56 + (lsig512_0 w48) + w47-      w64 = (lsig512_1 w62) + w57 + (lsig512_0 w49) + w48-      w65 = (lsig512_1 w63) + w58 + (lsig512_0 w50) + w49-      w66 = (lsig512_1 w64) + w59 + (lsig512_0 w51) + w50-      w67 = (lsig512_1 w65) + w60 + (lsig512_0 w52) + w51-      w68 = (lsig512_1 w66) + w61 + (lsig512_0 w53) + w52-      w69 = (lsig512_1 w67) + w62 + (lsig512_0 w54) + w53-      w70 = (lsig512_1 w68) + w63 + (lsig512_0 w55) + w54-      w71 = (lsig512_1 w69) + w64 + (lsig512_0 w56) + w55-      w72 = (lsig512_1 w70) + w65 + (lsig512_0 w57) + w56-      w73 = (lsig512_1 w71) + w66 + (lsig512_0 w58) + w57-      w74 = (lsig512_1 w72) + w67 + (lsig512_0 w59) + w58-      w75 = (lsig512_1 w73) + w68 + (lsig512_0 w60) + w59-      w76 = (lsig512_1 w74) + w69 + (lsig512_0 w61) + w60-      w77 = (lsig512_1 w75) + w70 + (lsig512_0 w62) + w61-      w78 = (lsig512_1 w76) + w71 + (lsig512_0 w63) + w62-      w79 = (lsig512_1 w77) + w72 + (lsig512_0 w64) + w63+  let w16 = lsig512_1 w14 + w09 + lsig512_0 w01 + w00+      w17 = lsig512_1 w15 + w10 + lsig512_0 w02 + w01+      w18 = lsig512_1 w16 + w11 + lsig512_0 w03 + w02+      w19 = lsig512_1 w17 + w12 + lsig512_0 w04 + w03+      w20 = lsig512_1 w18 + w13 + lsig512_0 w05 + w04+      w21 = lsig512_1 w19 + w14 + lsig512_0 w06 + w05+      w22 = lsig512_1 w20 + w15 + lsig512_0 w07 + w06+      w23 = lsig512_1 w21 + w16 + lsig512_0 w08 + w07+      w24 = lsig512_1 w22 + w17 + lsig512_0 w09 + w08+      w25 = lsig512_1 w23 + w18 + lsig512_0 w10 + w09+      w26 = lsig512_1 w24 + w19 + lsig512_0 w11 + w10+      w27 = lsig512_1 w25 + w20 + lsig512_0 w12 + w11+      w28 = lsig512_1 w26 + w21 + lsig512_0 w13 + w12+      w29 = lsig512_1 w27 + w22 + lsig512_0 w14 + w13+      w30 = lsig512_1 w28 + w23 + lsig512_0 w15 + w14+      w31 = lsig512_1 w29 + w24 + lsig512_0 w16 + w15+      w32 = lsig512_1 w30 + w25 + lsig512_0 w17 + w16+      w33 = lsig512_1 w31 + w26 + lsig512_0 w18 + w17+      w34 = lsig512_1 w32 + w27 + lsig512_0 w19 + w18+      w35 = lsig512_1 w33 + w28 + lsig512_0 w20 + w19+      w36 = lsig512_1 w34 + w29 + lsig512_0 w21 + w20+      w37 = lsig512_1 w35 + w30 + lsig512_0 w22 + w21+      w38 = lsig512_1 w36 + w31 + lsig512_0 w23 + w22+      w39 = lsig512_1 w37 + w32 + lsig512_0 w24 + w23+      w40 = lsig512_1 w38 + w33 + lsig512_0 w25 + w24+      w41 = lsig512_1 w39 + w34 + lsig512_0 w26 + w25+      w42 = lsig512_1 w40 + w35 + lsig512_0 w27 + w26+      w43 = lsig512_1 w41 + w36 + lsig512_0 w28 + w27+      w44 = lsig512_1 w42 + w37 + lsig512_0 w29 + w28+      w45 = lsig512_1 w43 + w38 + lsig512_0 w30 + w29+      w46 = lsig512_1 w44 + w39 + lsig512_0 w31 + w30+      w47 = lsig512_1 w45 + w40 + lsig512_0 w32 + w31+      w48 = lsig512_1 w46 + w41 + lsig512_0 w33 + w32+      w49 = lsig512_1 w47 + w42 + lsig512_0 w34 + w33+      w50 = lsig512_1 w48 + w43 + lsig512_0 w35 + w34+      w51 = lsig512_1 w49 + w44 + lsig512_0 w36 + w35+      w52 = lsig512_1 w50 + w45 + lsig512_0 w37 + w36+      w53 = lsig512_1 w51 + w46 + lsig512_0 w38 + w37+      w54 = lsig512_1 w52 + w47 + lsig512_0 w39 + w38+      w55 = lsig512_1 w53 + w48 + lsig512_0 w40 + w39+      w56 = lsig512_1 w54 + w49 + lsig512_0 w41 + w40+      w57 = lsig512_1 w55 + w50 + lsig512_0 w42 + w41+      w58 = lsig512_1 w56 + w51 + lsig512_0 w43 + w42+      w59 = lsig512_1 w57 + w52 + lsig512_0 w44 + w43+      w60 = lsig512_1 w58 + w53 + lsig512_0 w45 + w44+      w61 = lsig512_1 w59 + w54 + lsig512_0 w46 + w45+      w62 = lsig512_1 w60 + w55 + lsig512_0 w47 + w46+      w63 = lsig512_1 w61 + w56 + lsig512_0 w48 + w47+      w64 = lsig512_1 w62 + w57 + lsig512_0 w49 + w48+      w65 = lsig512_1 w63 + w58 + lsig512_0 w50 + w49+      w66 = lsig512_1 w64 + w59 + lsig512_0 w51 + w50+      w67 = lsig512_1 w65 + w60 + lsig512_0 w52 + w51+      w68 = lsig512_1 w66 + w61 + lsig512_0 w53 + w52+      w69 = lsig512_1 w67 + w62 + lsig512_0 w54 + w53+      w70 = lsig512_1 w68 + w63 + lsig512_0 w55 + w54+      w71 = lsig512_1 w69 + w64 + lsig512_0 w56 + w55+      w72 = lsig512_1 w70 + w65 + lsig512_0 w57 + w56+      w73 = lsig512_1 w71 + w66 + lsig512_0 w58 + w57+      w74 = lsig512_1 w72 + w67 + lsig512_0 w59 + w58+      w75 = lsig512_1 w73 + w68 + lsig512_0 w60 + w59+      w76 = lsig512_1 w74 + w69 + lsig512_0 w61 + w60+      w77 = lsig512_1 w75 + w70 + lsig512_0 w62 + w61+      w78 = lsig512_1 w76 + w71 + lsig512_0 w63 + w62+      w79 = lsig512_1 w77 + w72 + lsig512_0 w64 + w63   return $ SHA512Sched w00 w01 w02 w03 w04 w05 w06 w07 w08 w09                        w10 w11 w12 w13 w14 w15 w16 w17 w18 w19                        w20 w21 w22 w23 w24 w25 w26 w27 w28 w29@@ -538,100 +542,117 @@              w50 w51 w52 w53 w54 w55 w56 w57 w58 w59              w60 w61 w62 w63 w64 w65 w66 w67 w68 w69              w70 w71 w72 w73 w74 w75 w76 w77 w78 w79) <- getSHA1Sched-  let s01 = step1 s00 0x5a827999     ch w00-      s02 = step1 s01 0x5a827999     ch w01-      s03 = step1 s02 0x5a827999     ch w02-      s04 = step1 s03 0x5a827999     ch w03-      s05 = step1 s04 0x5a827999     ch w04-      s06 = step1 s05 0x5a827999     ch w05-      s07 = step1 s06 0x5a827999     ch w06-      s08 = step1 s07 0x5a827999     ch w07-      s09 = step1 s08 0x5a827999     ch w08-      s10 = step1 s09 0x5a827999     ch w09-      s11 = step1 s10 0x5a827999     ch w10-      s12 = step1 s11 0x5a827999     ch w11-      s13 = step1 s12 0x5a827999     ch w12-      s14 = step1 s13 0x5a827999     ch w13-      s15 = step1 s14 0x5a827999     ch w14-      s16 = step1 s15 0x5a827999     ch w15-      s17 = step1 s16 0x5a827999     ch w16-      s18 = step1 s17 0x5a827999     ch w17-      s19 = step1 s18 0x5a827999     ch w18-      s20 = step1 s19 0x5a827999     ch w19-      s21 = step1 s20 0x6ed9eba1 parity w20-      s22 = step1 s21 0x6ed9eba1 parity w21-      s23 = step1 s22 0x6ed9eba1 parity w22-      s24 = step1 s23 0x6ed9eba1 parity w23-      s25 = step1 s24 0x6ed9eba1 parity w24-      s26 = step1 s25 0x6ed9eba1 parity w25-      s27 = step1 s26 0x6ed9eba1 parity w26-      s28 = step1 s27 0x6ed9eba1 parity w27-      s29 = step1 s28 0x6ed9eba1 parity w28-      s30 = step1 s29 0x6ed9eba1 parity w29-      s31 = step1 s30 0x6ed9eba1 parity w30-      s32 = step1 s31 0x6ed9eba1 parity w31-      s33 = step1 s32 0x6ed9eba1 parity w32-      s34 = step1 s33 0x6ed9eba1 parity w33-      s35 = step1 s34 0x6ed9eba1 parity w34-      s36 = step1 s35 0x6ed9eba1 parity w35-      s37 = step1 s36 0x6ed9eba1 parity w36-      s38 = step1 s37 0x6ed9eba1 parity w37-      s39 = step1 s38 0x6ed9eba1 parity w38-      s40 = step1 s39 0x6ed9eba1 parity w39-      s41 = step1 s40 0x8f1bbcdc    maj w40-      s42 = step1 s41 0x8f1bbcdc    maj w41-      s43 = step1 s42 0x8f1bbcdc    maj w42-      s44 = step1 s43 0x8f1bbcdc    maj w43-      s45 = step1 s44 0x8f1bbcdc    maj w44-      s46 = step1 s45 0x8f1bbcdc    maj w45-      s47 = step1 s46 0x8f1bbcdc    maj w46-      s48 = step1 s47 0x8f1bbcdc    maj w47-      s49 = step1 s48 0x8f1bbcdc    maj w48-      s50 = step1 s49 0x8f1bbcdc    maj w49-      s51 = step1 s50 0x8f1bbcdc    maj w50-      s52 = step1 s51 0x8f1bbcdc    maj w51-      s53 = step1 s52 0x8f1bbcdc    maj w52-      s54 = step1 s53 0x8f1bbcdc    maj w53-      s55 = step1 s54 0x8f1bbcdc    maj w54-      s56 = step1 s55 0x8f1bbcdc    maj w55-      s57 = step1 s56 0x8f1bbcdc    maj w56-      s58 = step1 s57 0x8f1bbcdc    maj w57-      s59 = step1 s58 0x8f1bbcdc    maj w58-      s60 = step1 s59 0x8f1bbcdc    maj w59-      s61 = step1 s60 0xca62c1d6 parity w60-      s62 = step1 s61 0xca62c1d6 parity w61-      s63 = step1 s62 0xca62c1d6 parity w62-      s64 = step1 s63 0xca62c1d6 parity w63-      s65 = step1 s64 0xca62c1d6 parity w64-      s66 = step1 s65 0xca62c1d6 parity w65-      s67 = step1 s66 0xca62c1d6 parity w66-      s68 = step1 s67 0xca62c1d6 parity w67-      s69 = step1 s68 0xca62c1d6 parity w68-      s70 = step1 s69 0xca62c1d6 parity w69-      s71 = step1 s70 0xca62c1d6 parity w70-      s72 = step1 s71 0xca62c1d6 parity w71-      s73 = step1 s72 0xca62c1d6 parity w72-      s74 = step1 s73 0xca62c1d6 parity w73-      s75 = step1 s74 0xca62c1d6 parity w74-      s76 = step1 s75 0xca62c1d6 parity w75-      s77 = step1 s76 0xca62c1d6 parity w76-      s78 = step1 s77 0xca62c1d6 parity w77-      s79 = step1 s78 0xca62c1d6 parity w78-      s80 = step1 s79 0xca62c1d6 parity w79+  let s01 = step1_ch  s00 0x5a827999 w00+      s02 = step1_ch  s01 0x5a827999 w01+      s03 = step1_ch  s02 0x5a827999 w02+      s04 = step1_ch  s03 0x5a827999 w03+      s05 = step1_ch  s04 0x5a827999 w04+      s06 = step1_ch  s05 0x5a827999 w05+      s07 = step1_ch  s06 0x5a827999 w06+      s08 = step1_ch  s07 0x5a827999 w07+      s09 = step1_ch  s08 0x5a827999 w08+      s10 = step1_ch  s09 0x5a827999 w09+      s11 = step1_ch  s10 0x5a827999 w10+      s12 = step1_ch  s11 0x5a827999 w11+      s13 = step1_ch  s12 0x5a827999 w12+      s14 = step1_ch  s13 0x5a827999 w13+      s15 = step1_ch  s14 0x5a827999 w14+      s16 = step1_ch  s15 0x5a827999 w15+      s17 = step1_ch  s16 0x5a827999 w16+      s18 = step1_ch  s17 0x5a827999 w17+      s19 = step1_ch  s18 0x5a827999 w18+      s20 = step1_ch  s19 0x5a827999 w19+      s21 = step1_par s20 0x6ed9eba1 w20+      s22 = step1_par s21 0x6ed9eba1 w21+      s23 = step1_par s22 0x6ed9eba1 w22+      s24 = step1_par s23 0x6ed9eba1 w23+      s25 = step1_par s24 0x6ed9eba1 w24+      s26 = step1_par s25 0x6ed9eba1 w25+      s27 = step1_par s26 0x6ed9eba1 w26+      s28 = step1_par s27 0x6ed9eba1 w27+      s29 = step1_par s28 0x6ed9eba1 w28+      s30 = step1_par s29 0x6ed9eba1 w29+      s31 = step1_par s30 0x6ed9eba1 w30+      s32 = step1_par s31 0x6ed9eba1 w31+      s33 = step1_par s32 0x6ed9eba1 w32+      s34 = step1_par s33 0x6ed9eba1 w33+      s35 = step1_par s34 0x6ed9eba1 w34+      s36 = step1_par s35 0x6ed9eba1 w35+      s37 = step1_par s36 0x6ed9eba1 w36+      s38 = step1_par s37 0x6ed9eba1 w37+      s39 = step1_par s38 0x6ed9eba1 w38+      s40 = step1_par s39 0x6ed9eba1 w39+      s41 = step1_maj s40 0x8f1bbcdc w40+      s42 = step1_maj s41 0x8f1bbcdc w41+      s43 = step1_maj s42 0x8f1bbcdc w42+      s44 = step1_maj s43 0x8f1bbcdc w43+      s45 = step1_maj s44 0x8f1bbcdc w44+      s46 = step1_maj s45 0x8f1bbcdc w45+      s47 = step1_maj s46 0x8f1bbcdc w46+      s48 = step1_maj s47 0x8f1bbcdc w47+      s49 = step1_maj s48 0x8f1bbcdc w48+      s50 = step1_maj s49 0x8f1bbcdc w49+      s51 = step1_maj s50 0x8f1bbcdc w50+      s52 = step1_maj s51 0x8f1bbcdc w51+      s53 = step1_maj s52 0x8f1bbcdc w52+      s54 = step1_maj s53 0x8f1bbcdc w53+      s55 = step1_maj s54 0x8f1bbcdc w54+      s56 = step1_maj s55 0x8f1bbcdc w55+      s57 = step1_maj s56 0x8f1bbcdc w56+      s58 = step1_maj s57 0x8f1bbcdc w57+      s59 = step1_maj s58 0x8f1bbcdc w58+      s60 = step1_maj s59 0x8f1bbcdc w59+      s61 = step1_par s60 0xca62c1d6 w60+      s62 = step1_par s61 0xca62c1d6 w61+      s63 = step1_par s62 0xca62c1d6 w62+      s64 = step1_par s63 0xca62c1d6 w63+      s65 = step1_par s64 0xca62c1d6 w64+      s66 = step1_par s65 0xca62c1d6 w65+      s67 = step1_par s66 0xca62c1d6 w66+      s68 = step1_par s67 0xca62c1d6 w67+      s69 = step1_par s68 0xca62c1d6 w68+      s70 = step1_par s69 0xca62c1d6 w69+      s71 = step1_par s70 0xca62c1d6 w70+      s72 = step1_par s71 0xca62c1d6 w71+      s73 = step1_par s72 0xca62c1d6 w72+      s74 = step1_par s73 0xca62c1d6 w73+      s75 = step1_par s74 0xca62c1d6 w74+      s76 = step1_par s75 0xca62c1d6 w75+      s77 = step1_par s76 0xca62c1d6 w76+      s78 = step1_par s77 0xca62c1d6 w77+      s79 = step1_par s78 0xca62c1d6 w78+      s80 = step1_par s79 0xca62c1d6 w79       SHA1S a80 b80 c80 d80 e80 = s80   return $ SHA1S (a00 + a80) (b00 + b80) (c00 + c80) (d00 + d80) (e00 + e80) -{-# INLINE step1 #-}-step1 :: SHA1State -> Word32 ->-         (Word32 -> Word32 -> Word32 -> Word32) -> Word32 ->-         SHA1State-step1 !(SHA1S a b c d e) k !f w = SHA1S a' b' c' d' e'- where a' = (rotate a 5) + (f b c d) + e + k + w+{-# INLINE step1_ch #-}+step1_ch :: SHA1State -> Word32 -> Word32 -> SHA1State+step1_ch !(SHA1S a b c d e) k w = SHA1S a' b' c' d' e'+ where a' = rotate a 5 + ((b .&. c) `xor` (complement b .&. d)) + e + k + w        b' = a        c' = rotate b 30        d' = c        e' = d +{-# INLINE step1_par #-}+step1_par :: SHA1State -> Word32 -> Word32 -> SHA1State+step1_par !(SHA1S a b c d e) k w = SHA1S a' b' c' d' e'+ where a' = rotate a 5 + (b `xor` c `xor` d) + e + k + w+       b' = a+       c' = rotate b 30+       d' = c+       e' = d++{-# INLINE step1_maj #-}+step1_maj :: SHA1State -> Word32 -> Word32 -> SHA1State+step1_maj !(SHA1S a b c d e) k w = SHA1S a' b' c' d' e'+ where a' = rotate a 5 + ((b .&. (c .|. d)) .|. (c .&. d)) + e + k + w+       b' = a+       c' = rotate b 30+       d' = c+       e' = d+-- See the note on maj, above+ processSHA256Block :: SHA256State -> Get SHA256State processSHA256Block !s00@(SHA256S a00 b00 c00 d00 e00 f00 g00 h00) = do   (SHA256Sched w00 w01 w02 w03 w04 w05 w06 w07 w08 w09@@ -846,8 +867,7 @@     done <- isEmpty     if done       then return s_in-      else do s_out <- nextChunk s_in-              getAll s_out+      else nextChunk s_in >>= getAll  -- |Compute the SHA-1 hash of the given ByteString. The output is guaranteed -- to be exactly 160 bits, or 20 bytes, long. This is a good default for
Main.hs view
@@ -12,11 +12,9 @@   case args of     [] -> do       inconts <- BS.getContents-      putStrLn $ show $ ALGORITHM inconts+      print $ ALGORITHM inconts       exitSuccess-    xs -> do-      exit_code <- foldM (sha_file bname) ExitSuccess xs-      exitWith exit_code +    xs -> foldM (sha_file bname) ExitSuccess xs >>= exitWith  sha_file :: String -> ExitCode -> String -> IO ExitCode sha_file bname prevEC fname = do
SHA.cabal view
@@ -1,6 +1,6 @@ name:       SHA category:   Cryptography, Codec-version:    1.2.0.2+version:    1.2.1 license:    BSD3 license-file: LICENSE author:     Adam Wick <awick@galois.com>@@ -15,7 +15,7 @@              functions have been tested against most of the NIST test vectors              for the various functions. While some attention has been paid to              performance, these do not presently reach the speed of-             well-tuned libraries, like OpenSSL.  +             well-tuned libraries, like OpenSSL.  Flag Test  Description: Build the SHA test suite.@@ -28,12 +28,12 @@ Library  build-depends: base >= 3, bytestring, binary, array  exposed-modules: Data.Digest.Pure.SHA- GHC-Options: -O2 -Wall -fno-ignore-asserts -funbox-strict-fields+ GHC-Options: -O2 -Wall -fno-ignore-asserts -funbox-strict-fields -fwarn-tabs  extensions: CPP, BangPatterns  Executable test_sha   build-depends: base >= 3, bytestring, binary, array-  GHC-Options: -O2 -Wall -fno-ignore-asserts -fno-warn-orphans -funbox-strict-fields+  GHC-Options: -O2 -Wall -fno-ignore-asserts -fno-warn-orphans -funbox-strict-fields -fwarn-tabs   cpp-options: -DSHA_TEST   Main-Is: Test.hs   Other-Modules: Data.Digest.Pure.SHA@@ -45,7 +45,7 @@  Executable sha1   build-depends: base >= 3, bytestring, binary, array-  GHC-Options: -O2 -Wall -fno-ignore-asserts -funbox-strict-fields+  GHC-Options: -O2 -Wall -fno-ignore-asserts -funbox-strict-fields -fwarn-tabs   Main-Is: Main.hs   extensions: CPP, BangPatterns   cpp-options: -DALGORITHM=sha1@@ -56,7 +56,7 @@  Executable sha384   build-depends: base >= 3, bytestring, binary, array-  GHC-Options: -O2 -Wall -fno-ignore-asserts -funbox-strict-fields+  GHC-Options: -O2 -Wall -fno-ignore-asserts -funbox-strict-fields -fwarn-tabs   Main-Is: Main.hs   extensions: CPP, BangPatterns   cpp-options: -DALGORITHM=sha384@@ -66,5 +66,5 @@     build-depends: directory  source-repository head-  type:		git-  location:	git://code.haskell.org/SHA.git+  type:     git+  location: git://code.haskell.org/SHA.git
Test.hs view

file too large to diff