{-# LANGUAGE ExplicitNamespaces, TypeOperators, TypeFamilies #-}
module Crypto.Sodium.Hash
(
I.HashBlake2b
, blake2b
, blake2bWithKey
, HashSha256
, sha256
, HashSha512
, sha512
) where
import Data.ByteArray (ByteArray, ByteArrayAccess, Bytes)
import GHC.TypeNats (KnownNat, type (<=))
import NaCl.Hash (HashSha256, HashSha512, sha256, sha512)
import System.IO.Unsafe (unsafePerformIO)
import qualified Crypto.Sodium.Hash.Internal as I
import qualified Libsodium as Na
blake2b
:: forall len hashBytes pt.
( ByteArrayAccess pt
, ByteArray hashBytes
, KnownNat len
, Na.CRYPTO_GENERICHASH_BYTES_MIN <= len
, len <= Na.CRYPTO_GENERICHASH_BYTES_MAX
)
=> pt
-> I.HashBlake2b len hashBytes
blake2b :: pt -> HashBlake2b len hashBytes
blake2b pt
msg = IO (HashBlake2b len hashBytes) -> HashBlake2b len hashBytes
forall a. IO a -> a
unsafePerformIO (IO (HashBlake2b len hashBytes) -> HashBlake2b len hashBytes)
-> IO (HashBlake2b len hashBytes) -> HashBlake2b len hashBytes
forall a b. (a -> b) -> a -> b
$ Maybe Bytes -> pt -> IO (HashBlake2b len hashBytes)
forall (len :: Nat) hashBytes pt key.
(ByteArrayAccess pt, ByteArrayAccess key, ByteArray hashBytes,
KnownNat len, CRYPTO_GENERICHASH_BYTES_MIN <= len,
len <= CRYPTO_GENERICHASH_BYTES_MAX) =>
Maybe key -> pt -> IO (HashBlake2b len hashBytes)
I.blake2b (Maybe Bytes
forall a. Maybe a
Nothing :: Maybe Bytes) pt
msg
blake2bWithKey
:: forall len hashBytes pt key.
( ByteArrayAccess pt
, ByteArrayAccess key
, ByteArray hashBytes
, KnownNat len
, Na.CRYPTO_GENERICHASH_BYTES_MIN <= len
, len <= Na.CRYPTO_GENERICHASH_BYTES_MAX
)
=> key
-> pt
-> I.HashBlake2b len hashBytes
blake2bWithKey :: key -> pt -> HashBlake2b len hashBytes
blake2bWithKey key
key pt
msg = IO (HashBlake2b len hashBytes) -> HashBlake2b len hashBytes
forall a. IO a -> a
unsafePerformIO (IO (HashBlake2b len hashBytes) -> HashBlake2b len hashBytes)
-> IO (HashBlake2b len hashBytes) -> HashBlake2b len hashBytes
forall a b. (a -> b) -> a -> b
$ Maybe key -> pt -> IO (HashBlake2b len hashBytes)
forall (len :: Nat) hashBytes pt key.
(ByteArrayAccess pt, ByteArrayAccess key, ByteArray hashBytes,
KnownNat len, CRYPTO_GENERICHASH_BYTES_MIN <= len,
len <= CRYPTO_GENERICHASH_BYTES_MAX) =>
Maybe key -> pt -> IO (HashBlake2b len hashBytes)
I.blake2b (key -> Maybe key
forall a. a -> Maybe a
Just key
key) pt
msg