{-# LANGUAGE DataKinds #-}

-- |
-- Module      :  Data.Digest.Blake2
-- Copyright   :  Aleksandr Krupenkin 2016-2021
-- License     :  Apache-2.0
--
-- Maintainer  :  mail@akru.me
-- Stability   :  experimental
-- Portability :  unportable
--
-- Cryptonite Blake2b wrappers.
--

module Data.Digest.Blake2 where

import           Crypto.Hash     (Blake2b, Digest, hash)
import           Data.ByteArray  (convert)
import           Data.ByteString (ByteString)

-- | Blake2b with 64 bit output.
blake2_64 :: ByteString -> ByteString
{-# INLINE blake2_64 #-}
blake2_64 :: ByteString -> ByteString
blake2_64 = Digest (Blake2b 64) -> ByteString
forall bin bout.
(ByteArrayAccess bin, ByteArray bout) =>
bin -> bout
convert (Digest (Blake2b 64) -> ByteString)
-> (ByteString -> Digest (Blake2b 64)) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> Digest (Blake2b 64)
forall ba a.
(ByteArrayAccess ba, HashAlgorithm a) =>
ba -> Digest a
hash :: ByteString -> Digest (Blake2b 64))

-- | Blake2b with 128 bit output.
blake2_128 :: ByteString -> ByteString
{-# INLINE blake2_128 #-}
blake2_128 :: ByteString -> ByteString
blake2_128 = Digest (Blake2b 128) -> ByteString
forall bin bout.
(ByteArrayAccess bin, ByteArray bout) =>
bin -> bout
convert (Digest (Blake2b 128) -> ByteString)
-> (ByteString -> Digest (Blake2b 128)) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> Digest (Blake2b 128)
forall ba a.
(ByteArrayAccess ba, HashAlgorithm a) =>
ba -> Digest a
hash :: ByteString -> Digest (Blake2b 128))

-- | Blake2b with 256 bit output.
blake2_256 :: ByteString -> ByteString
{-# INLINE blake2_256 #-}
blake2_256 :: ByteString -> ByteString
blake2_256 = Digest (Blake2b 256) -> ByteString
forall bin bout.
(ByteArrayAccess bin, ByteArray bout) =>
bin -> bout
convert (Digest (Blake2b 256) -> ByteString)
-> (ByteString -> Digest (Blake2b 256)) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> Digest (Blake2b 256)
forall ba a.
(ByteArrayAccess ba, HashAlgorithm a) =>
ba -> Digest a
hash :: ByteString -> Digest (Blake2b 256))

-- | Blake2b with 512 bit output.
blake2_512 :: ByteString -> ByteString
{-# INLINE blake2_512 #-}
blake2_512 :: ByteString -> ByteString
blake2_512 = Digest (Blake2b 512) -> ByteString
forall bin bout.
(ByteArrayAccess bin, ByteArray bout) =>
bin -> bout
convert (Digest (Blake2b 512) -> ByteString)
-> (ByteString -> Digest (Blake2b 512)) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> Digest (Blake2b 512)
forall ba a.
(ByteArrayAccess ba, HashAlgorithm a) =>
ba -> Digest a
hash :: ByteString -> Digest (Blake2b 512))