[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.
This commit is contained in:
parent
987f9e7bb6
commit
9794e2132b
@ -16,7 +16,7 @@ module Crypto.Hash.IO
|
|||||||
, hashMutableInitWith
|
, hashMutableInitWith
|
||||||
, hashMutableUpdate
|
, hashMutableUpdate
|
||||||
, hashMutableFinalize
|
, hashMutableFinalize
|
||||||
, hashMutableScrub
|
, hashMutableReset
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Crypto.Hash.Types
|
import Crypto.Hash.Types
|
||||||
@ -56,6 +56,9 @@ hashMutableFinalize mc = doFinalize undefined (B.withByteArray mc) B.alloc
|
|||||||
hashInternalFinalize ctx dig
|
hashInternalFinalize ctx dig
|
||||||
return $ Digest b
|
return $ Digest b
|
||||||
|
|
||||||
-- FIXME not implemented just yet.
|
-- | Reset the mutable context to the initial state of the hash
|
||||||
hashMutableScrub :: HashAlgorithm a => MutableContext a -> IO ()
|
hashMutableReset :: HashAlgorithm a => MutableContext a -> IO ()
|
||||||
hashMutableScrub (MutableContext _) = return ()
|
hashMutableReset mc = doReset mc (B.withByteArray mc)
|
||||||
|
where
|
||||||
|
doReset :: HashAlgorithm a => MutableContext a -> ((Ptr (Context a) -> IO ()) -> IO ()) -> IO ()
|
||||||
|
doReset _ withCtx = withCtx hashInternalInit
|
||||||
|
|||||||
@ -69,7 +69,7 @@ initialize secret = unsafeDoIO (doHashAlg undefined)
|
|||||||
ctx <- hashMutableInitWith alg
|
ctx <- hashMutableInitWith alg
|
||||||
hashMutableUpdate ctx secret
|
hashMutableUpdate ctx secret
|
||||||
digest <- hashMutableFinalize ctx
|
digest <- hashMutableFinalize ctx
|
||||||
hashMutableScrub ctx
|
hashMutableReset ctx
|
||||||
-- pad it if necessary
|
-- pad it if necessary
|
||||||
if digestSize < blockSize
|
if digestSize < blockSize
|
||||||
then do
|
then do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user