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 :: Int -> Ctx
init Int
t = Int -> Ctx -> Ctx
Ctx Int
t (Int -> Ctx
SHA512.init_t Int
t)
update :: Ctx -> ByteString -> Ctx
update :: Ctx -> ByteString -> Ctx
update (Ctx Int
t Ctx
ctx) ByteString
d = Int -> Ctx -> Ctx
Ctx Int
t (Ctx -> ByteString -> Ctx
SHA512.update Ctx
ctx ByteString
d)
finalize :: Ctx -> ByteString
finalize :: Ctx -> ByteString
finalize (Ctx Int
sz Ctx
ctx) = Int -> ByteString -> ByteString
B.take (Int
sz forall a. Integral a => a -> a -> a
`div` Int
8) (Ctx -> ByteString
SHA512.finalize Ctx
ctx)
hash :: Int -> ByteString -> ByteString
hash :: Int -> ByteString -> ByteString
hash Int
t = Ctx -> ByteString
finalize forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ctx -> ByteString -> Ctx
update (Int -> Ctx
init Int
t)
hashlazy :: Int -> L.ByteString -> ByteString
hashlazy :: Int -> ByteString -> ByteString
hashlazy Int
t = Ctx -> ByteString
finalize forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' Ctx -> ByteString -> Ctx
update (Int -> Ctx
init Int
t) forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> [ByteString]
L.toChunks