diff --git a/Crypto/Hash/IO.hs b/Crypto/Hash/IO.hs index ad73ae9..50cd8b9 100644 --- a/Crypto/Hash/IO.hs +++ b/Crypto/Hash/IO.hs @@ -16,7 +16,7 @@ module Crypto.Hash.IO , hashMutableInitWith , hashMutableUpdate , hashMutableFinalize - , hashMutableScrub + , hashMutableReset ) where import Crypto.Hash.Types @@ -56,6 +56,9 @@ hashMutableFinalize mc = doFinalize undefined (B.withByteArray mc) B.alloc hashInternalFinalize ctx dig return $ Digest b --- FIXME not implemented just yet. -hashMutableScrub :: HashAlgorithm a => MutableContext a -> IO () -hashMutableScrub (MutableContext _) = return () +-- | Reset the mutable context to the initial state of the hash +hashMutableReset :: HashAlgorithm a => MutableContext a -> IO () +hashMutableReset mc = doReset mc (B.withByteArray mc) + where + doReset :: HashAlgorithm a => MutableContext a -> ((Ptr (Context a) -> IO ()) -> IO ()) -> IO () + doReset _ withCtx = withCtx hashInternalInit diff --git a/Crypto/MAC/HMAC.hs b/Crypto/MAC/HMAC.hs index 860e866..6686067 100644 --- a/Crypto/MAC/HMAC.hs +++ b/Crypto/MAC/HMAC.hs @@ -69,7 +69,7 @@ initialize secret = unsafeDoIO (doHashAlg undefined) ctx <- hashMutableInitWith alg hashMutableUpdate ctx secret digest <- hashMutableFinalize ctx - hashMutableScrub ctx + hashMutableReset ctx -- pad it if necessary if digestSize < blockSize then do