From 9794e2132b7c919e1bf113b01471efa41b48ee3f Mon Sep 17 00:00:00 2001 From: Vincent Hanquez Date: Tue, 19 May 2015 11:50:56 +0100 Subject: [PATCH] [hash] replace scrub by reset reset make more sense as it leave the mutable context in a state where it can be re-used by further update, whereas scrub doesn't. --- Crypto/Hash/IO.hs | 11 +++++++---- Crypto/MAC/HMAC.hs | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) 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