-- |
-- Module      : Crypto.Hash.Blake2bp
-- License     : BSD-style
-- Maintainer  : Vincent Hanquez <vincent@snarc.org>
-- Stability   : experimental
-- Portability : unknown
--
-- Module containing the binding functions to work with the
-- Blake2bp cryptographic hash.
--
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
module Crypto.Hash.Blake2bp
    (  Blake2bp_512 (..)
    ) where

import           Crypto.Hash.Types
import           Foreign.Ptr (Ptr)
import           Data.Data
import           Data.Word (Word8, Word32)


-- | Blake2bp (512 bits) cryptographic hash algorithm
data Blake2bp_512 = Blake2bp_512
    deriving (Int -> Blake2bp_512 -> ShowS
[Blake2bp_512] -> ShowS
Blake2bp_512 -> String
(Int -> Blake2bp_512 -> ShowS)
-> (Blake2bp_512 -> String)
-> ([Blake2bp_512] -> ShowS)
-> Show Blake2bp_512
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Blake2bp_512 -> ShowS
showsPrec :: Int -> Blake2bp_512 -> ShowS
$cshow :: Blake2bp_512 -> String
show :: Blake2bp_512 -> String
$cshowList :: [Blake2bp_512] -> ShowS
showList :: [Blake2bp_512] -> ShowS
Show,Typeable Blake2bp_512
Typeable Blake2bp_512 =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Blake2bp_512 -> c Blake2bp_512)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Blake2bp_512)
-> (Blake2bp_512 -> Constr)
-> (Blake2bp_512 -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Blake2bp_512))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c Blake2bp_512))
-> ((forall b. Data b => b -> b) -> Blake2bp_512 -> Blake2bp_512)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Blake2bp_512 -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Blake2bp_512 -> r)
-> (forall u. (forall d. Data d => d -> u) -> Blake2bp_512 -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> Blake2bp_512 -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Blake2bp_512 -> m Blake2bp_512)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Blake2bp_512 -> m Blake2bp_512)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Blake2bp_512 -> m Blake2bp_512)
-> Data Blake2bp_512
Blake2bp_512 -> Constr
Blake2bp_512 -> DataType
(forall b. Data b => b -> b) -> Blake2bp_512 -> Blake2bp_512
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Blake2bp_512 -> u
forall u. (forall d. Data d => d -> u) -> Blake2bp_512 -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Blake2bp_512 -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Blake2bp_512 -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Blake2bp_512 -> m Blake2bp_512
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Blake2bp_512 -> m Blake2bp_512
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Blake2bp_512
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Blake2bp_512 -> c Blake2bp_512
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Blake2bp_512)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c Blake2bp_512)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Blake2bp_512 -> c Blake2bp_512
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Blake2bp_512 -> c Blake2bp_512
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Blake2bp_512
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Blake2bp_512
$ctoConstr :: Blake2bp_512 -> Constr
toConstr :: Blake2bp_512 -> Constr
$cdataTypeOf :: Blake2bp_512 -> DataType
dataTypeOf :: Blake2bp_512 -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Blake2bp_512)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Blake2bp_512)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c Blake2bp_512)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c Blake2bp_512)
$cgmapT :: (forall b. Data b => b -> b) -> Blake2bp_512 -> Blake2bp_512
gmapT :: (forall b. Data b => b -> b) -> Blake2bp_512 -> Blake2bp_512
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Blake2bp_512 -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Blake2bp_512 -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Blake2bp_512 -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Blake2bp_512 -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Blake2bp_512 -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Blake2bp_512 -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Blake2bp_512 -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Blake2bp_512 -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Blake2bp_512 -> m Blake2bp_512
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Blake2bp_512 -> m Blake2bp_512
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Blake2bp_512 -> m Blake2bp_512
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Blake2bp_512 -> m Blake2bp_512
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Blake2bp_512 -> m Blake2bp_512
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Blake2bp_512 -> m Blake2bp_512
Data)

instance HashAlgorithm Blake2bp_512 where
    type HashBlockSize           Blake2bp_512 = 128
    type HashDigestSize          Blake2bp_512 = 64
    type HashInternalContextSize Blake2bp_512 = 1768
    hashBlockSize :: Blake2bp_512 -> Int
hashBlockSize  Blake2bp_512
_          = Int
128
    hashDigestSize :: Blake2bp_512 -> Int
hashDigestSize Blake2bp_512
_          = Int
64
    hashInternalContextSize :: Blake2bp_512 -> Int
hashInternalContextSize Blake2bp_512
_ = Int
1768
    hashInternalInit :: Ptr (Context Blake2bp_512) -> IO ()
hashInternalInit Ptr (Context Blake2bp_512)
p        = Ptr (Context Blake2bp_512) -> Word32 -> IO ()
forall a. Ptr (Context a) -> Word32 -> IO ()
c_blake2bp_init Ptr (Context Blake2bp_512)
p Word32
512
    hashInternalUpdate :: Ptr (Context Blake2bp_512) -> Ptr Word8 -> Word32 -> IO ()
hashInternalUpdate        = Ptr (Context Blake2bp_512) -> Ptr Word8 -> Word32 -> IO ()
forall a. Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
c_blake2bp_update
    hashInternalFinalize :: Ptr (Context Blake2bp_512) -> Ptr (Digest Blake2bp_512) -> IO ()
hashInternalFinalize Ptr (Context Blake2bp_512)
p    = Ptr (Context Blake2bp_512)
-> Word32 -> Ptr (Digest Blake2bp_512) -> IO ()
forall a. Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()
c_blake2bp_finalize Ptr (Context Blake2bp_512)
p Word32
512


foreign import ccall unsafe "crypton_blake2bp_init"
    c_blake2bp_init :: Ptr (Context a) -> Word32 -> IO ()

foreign import ccall "crypton_blake2bp_update"
    c_blake2bp_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()

foreign import ccall unsafe "crypton_blake2bp_finalize"
    c_blake2bp_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()