SHA 1.2.1 → 1.4.0
raw patch · 3 files changed
+75/−11 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Digest.Pure.SHA: hmacSha1 :: ByteString -> ByteString -> Digest
+ Data.Digest.Pure.SHA: hmacSha224 :: ByteString -> ByteString -> Digest
+ Data.Digest.Pure.SHA: hmacSha256 :: ByteString -> ByteString -> Digest
+ Data.Digest.Pure.SHA: hmacSha384 :: ByteString -> ByteString -> Digest
+ Data.Digest.Pure.SHA: hmacSha512 :: ByteString -> ByteString -> Digest
Files
- Data/Digest/Pure/SHA.hs +67/−4
- SHA.cabal +8/−7
- Test.hs too large to diff
Data/Digest/Pure/SHA.hs view
@@ -3,15 +3,23 @@ -- is basically an unoptimized translation of FIPS 180-2 into Haskell. If you're -- looking for performance, you probably won't find it here. module Data.Digest.Pure.SHA- ( Digest+ ( -- * 'Digest' and related functions+ Digest+ , showDigest+ , integerDigest+ , bytestringDigest+ -- * Calculating hashes , sha1 , sha224 , sha256 , sha384 , sha512- , showDigest- , integerDigest- , bytestringDigest+ -- * Calculating message authentication codes (MACs)+ , hmacSha1+ , hmacSha224+ , hmacSha256+ , hmacSha384+ , hmacSha512 #ifdef SHA_TEST , toBigEndianBS, fromBigEndianBS , calc_k@@ -919,6 +927,61 @@ bs_pad = padSHA512 bs_in fstate = runSHA initialSHA512State processSHA512Block bs_pad bs_out = runPut $ synthesizeSHA512 fstate++-- --------------------------------------------------------------------------++-- | Compute an HMAC using SHA-1.+hmacSha1+ :: ByteString -- ^ secret key+ -> ByteString -- ^ message+ -> Digest -- ^ SHA-1 MAC+hmacSha1 = hmac sha1 64++-- | Compute an HMAC using SHA-224.+hmacSha224+ :: ByteString -- ^ secret key+ -> ByteString -- ^ message+ -> Digest -- ^ SHA-224 MAC+hmacSha224 = hmac sha224 64++-- | Compute an HMAC using SHA-256.+hmacSha256+ :: ByteString -- ^ secret key+ -> ByteString -- ^ message+ -> Digest -- ^ SHA-256 MAC+hmacSha256 = hmac sha256 64++-- | Compute an HMAC using SHA-384.+hmacSha384+ :: ByteString -- ^ secret key+ -> ByteString -- ^ message+ -> Digest -- ^ SHA-384 MAC+hmacSha384 = hmac sha384 128++-- | Compute an HMAC using SHA-512.+hmacSha512+ :: ByteString -- ^ secret key+ -> ByteString -- ^ message+ -> Digest -- ^ SHA-512 MAC+hmacSha512 = hmac sha512 128++-- --------------------------------------------------------------------------++hmac :: (ByteString -> Digest) -> Int -> ByteString -> ByteString -> Digest+hmac f bl k m = f (BS.append opad (bytestringDigest (f (BS.append ipad m))))+ where+ opad = BS.map (xor ov) k'+ ipad = BS.map (xor iv) k'+ ov = 0x5c :: Word8+ iv = 0x36 :: Word8++ k' = BS.append kt pad+ where+ kt = if kn > bn then bytestringDigest (f k) else k+ pad = BS.replicate (bn - ktn) 0+ kn = fromIntegral (BS.length k)+ ktn = fromIntegral (BS.length kt)+ bn = fromIntegral bl -- -------------------------------------------------------------------------- --
SHA.cabal view
@@ -1,9 +1,9 @@ name: SHA category: Cryptography, Codec-version: 1.2.1+version: 1.4.0 license: BSD3 license-file: LICENSE-author: Adam Wick <awick@galois.com>+author: Adam Wick <awick@galois.com>, Brian Lewis <brian@lorf.org> maintainer: Adam Wick <awick@galois.com> stability: stable build-type: Simple@@ -11,11 +11,12 @@ tested-with: GHC ==6.8.0 synopsis: Implementations of the SHA suite of message digest functions description: This library implements the SHA suite of message digest functions,- according to NIST FIPS 180-2 (with the SHA-224 addendum). The- 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.+ according to NIST FIPS 180-2 (with the SHA-224 addendum), as well+ as the SHA-based HMAC routines. The functions have been tested + against most of the NIST and RFC 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. Flag Test Description: Build the SHA test suite.
Test.hs view
file too large to diff