module Crypto.Hash.SHA512t
( Ctx(..)
, init
, update
, finalize
, hash
, hashlazy
) where
import Prelude hiding (init)
import Data.List (foldl')
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L
import qualified Crypto.Hash.SHA512 as SHA512
data Ctx = Ctx !Int !SHA512.Ctx
init :: Int -> Ctx
init t = Ctx t (SHA512.init_t t)
update :: Ctx -> ByteString -> Ctx
update (Ctx t ctx) d = Ctx t (SHA512.update ctx d)
finalize :: Ctx -> ByteString
finalize (Ctx sz ctx) = B.take (sz `div` 8) (SHA512.finalize ctx)
hash :: Int -> ByteString -> ByteString
hash t = finalize . update (init t)
hashlazy :: Int -> L.ByteString -> ByteString
hashlazy t = finalize . foldl' update (init t) . L.toChunks