{-# LANGUAGE PackageImports #-}
module Crypto.Hash.Whirlpool
( Ctx(..)
, init
, update
, updates
, finalize
, hash
, hashlazy
) where
import Prelude hiding (init)
import qualified Data.ByteString.Lazy as L
import Data.ByteString (ByteString)
import Crypto.Hash.Internal (digestToByteString, digestToByteStringWitness)
import qualified "cryptonite" Crypto.Hash as H
newtype Ctx = Ctx (H.Context H.Whirlpool)
init :: Ctx
init :: Ctx
init = Context Whirlpool -> Ctx
Ctx Context Whirlpool
forall a. HashAlgorithm a => Context a
H.hashInit
update :: Ctx -> ByteString -> Ctx
update :: Ctx -> ByteString -> Ctx
update (Ctx ctx :: Context Whirlpool
ctx) d :: ByteString
d = Context Whirlpool -> Ctx
Ctx (Context Whirlpool -> Ctx) -> Context Whirlpool -> Ctx
forall a b. (a -> b) -> a -> b
$ Context Whirlpool -> ByteString -> Context Whirlpool
forall ba a.
(ByteArrayAccess ba, HashAlgorithm a) =>
Context a -> ba -> Context a
H.hashUpdate Context Whirlpool
ctx ByteString
d
updates :: Ctx -> [ByteString] -> Ctx
updates :: Ctx -> [ByteString] -> Ctx
updates (Ctx ctx :: Context Whirlpool
ctx) d :: [ByteString]
d =
Context Whirlpool -> Ctx
Ctx (Context Whirlpool -> Ctx) -> Context Whirlpool -> Ctx
forall a b. (a -> b) -> a -> b
$ Context Whirlpool -> [ByteString] -> Context Whirlpool
forall a ba.
(HashAlgorithm a, ByteArrayAccess ba) =>
Context a -> [ba] -> Context a
H.hashUpdates Context Whirlpool
ctx [ByteString]
d
finalize :: Ctx -> ByteString
finalize :: Ctx -> ByteString
finalize (Ctx ctx :: Context Whirlpool
ctx) = Digest Whirlpool -> ByteString
forall h. HashAlgorithm h => Digest h -> ByteString
digestToByteString (Digest Whirlpool -> ByteString) -> Digest Whirlpool -> ByteString
forall a b. (a -> b) -> a -> b
$ Context Whirlpool -> Digest Whirlpool
forall a. HashAlgorithm a => Context a -> Digest a
H.hashFinalize Context Whirlpool
ctx
hash :: ByteString -> ByteString
hash :: ByteString -> ByteString
hash d :: ByteString
d = Whirlpool -> Digest Whirlpool -> ByteString
forall h. HashAlgorithm h => h -> Digest h -> ByteString
digestToByteStringWitness Whirlpool
H.Whirlpool (Digest Whirlpool -> ByteString) -> Digest Whirlpool -> ByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> Digest Whirlpool
forall ba a.
(ByteArrayAccess ba, HashAlgorithm a) =>
ba -> Digest a
H.hash ByteString
d
hashlazy :: L.ByteString -> ByteString
hashlazy :: ByteString -> ByteString
hashlazy l :: ByteString
l = Whirlpool -> Digest Whirlpool -> ByteString
forall h. HashAlgorithm h => h -> Digest h -> ByteString
digestToByteStringWitness Whirlpool
H.Whirlpool (Digest Whirlpool -> ByteString) -> Digest Whirlpool -> ByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> Digest Whirlpool
forall a. HashAlgorithm a => ByteString -> Digest a
H.hashlazy ByteString
l