just like poly1305, add a way to mac multiple inputs

This commit is contained in:
Vincent Hanquez 2014-11-09 09:59:35 +00:00
parent 022f16eeef
commit bd1c010df9

View File

@ -16,6 +16,7 @@ module Crypto.MAC.HMAC
, Context(..)
, initialize
, update
, updates
, finalize
) where
@ -54,7 +55,7 @@ hmac secret msg = doHMAC hashInit
hashF = hashFinalize . hashUpdate ctxInit
blockSize = hashBlockSize ctxInit
-- | Represent an ongoing HMAC state, that can be appended with 'hmacUpdate'
-- | Represent an ongoing HMAC state, that can be appended with 'update'
-- and finalize to an HMAC with 'hmacFinalize'
data Context hashalg = Context !(Hash.Context hashalg) !(Hash.Context hashalg)
@ -78,11 +79,19 @@ initialize secret = Context octx ictx
-- | Incrementally update a HMAC context
update :: HashAlgorithm a
=> Context a -- ^ Current HMAC context
-> ByteString -- ^ Message to Mac
-> ByteString -- ^ Message to append to the MAC
-> Context a -- ^ Updated HMAC context
update (Context octx ictx) msg =
Context octx (hashUpdate ictx msg)
-- | Increamentally update a HMAC context with multiple inputs
updates :: HashAlgorithm a
=> Context a -- ^ Current HMAC context
-> [ByteString] -- ^ Messages to append to the MAC
-> Context a -- ^ Updated HMAC context
updates (Context octx ictx) msgs =
Context octx (hashUpdates ictx msgs)
-- | Finalize a HMAC context and return the HMAC.
finalize :: HashAlgorithm a
=> Context a