Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
Change the HMAC type to be the Digest.
Browse files Browse the repository at this point in the history
digest can be recovered using hmacGetDigest
  • Loading branch information
vincenthz committed Sep 29, 2013
1 parent 41af74a commit f04cb7c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Crypto/Hash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,21 @@ hashInitAlg _ = hashInit
-- | Represent an HMAC that is a phantom type with the hash used to produce the mac.
--
-- The Eq instance is constant time.
data HMAC a = HMAC ByteString
newtype HMAC a = HMAC { hmacGetDigest :: Digest a }

instance Byteable (HMAC a) where
toBytes (HMAC b) = b
toBytes (HMAC b) = toBytes b

instance Eq (HMAC a) where
(HMAC b1) == (HMAC b2) = constEqBytes b1 b2
(HMAC b1) == (HMAC b2) = constEqBytes (toBytes b1) (toBytes b2)

-- | compute a MAC using the supplied hashing function
hmac :: HashAlgorithm a
=> a -- ^ Hash algorithm to use
-> ByteString -- ^ Secret key
-> ByteString -- ^ Message to MAC
-> HMAC a
hmac hashAlg secret msg = HMAC $ toBytes $ hashF $ B.append opad (toBytes $ hashF $ B.append ipad msg)
hmac hashAlg secret msg = HMAC $ hashF $ B.append opad (toBytes $ hashF $ B.append ipad msg)
where opad = B.map (xor 0x5c) k'
ipad = B.map (xor 0x36) k'

Expand Down

0 comments on commit f04cb7c

Please sign in to comment.