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

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


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

instance HashAlgorithm Blake2sp_224 where
    type HashBlockSize           Blake2sp_224 = 64
    type HashDigestSize          Blake2sp_224 = 28
    type HashInternalContextSize Blake2sp_224 = 1752
    hashBlockSize :: Blake2sp_224 -> Int
hashBlockSize  Blake2sp_224
_          = Int
64
    hashDigestSize :: Blake2sp_224 -> Int
hashDigestSize Blake2sp_224
_          = Int
28
    hashInternalContextSize :: Blake2sp_224 -> Int
hashInternalContextSize Blake2sp_224
_ = Int
1752
    hashInternalInit :: Ptr (Context Blake2sp_224) -> IO ()
hashInternalInit Ptr (Context Blake2sp_224)
p        = forall a. Ptr (Context a) -> Word32 -> IO ()
c_blake2sp_init Ptr (Context Blake2sp_224)
p Word32
224
    hashInternalUpdate :: Ptr (Context Blake2sp_224) -> Ptr Word8 -> Word32 -> IO ()
hashInternalUpdate        = forall a. Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
c_blake2sp_update
    hashInternalFinalize :: Ptr (Context Blake2sp_224) -> Ptr (Digest Blake2sp_224) -> IO ()
hashInternalFinalize Ptr (Context Blake2sp_224)
p    = forall a. Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()
c_blake2sp_finalize Ptr (Context Blake2sp_224)
p Word32
224

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

instance HashAlgorithm Blake2sp_256 where
    type HashBlockSize           Blake2sp_256 = 64
    type HashDigestSize          Blake2sp_256 = 32
    type HashInternalContextSize Blake2sp_256 = 1752
    hashBlockSize :: Blake2sp_256 -> Int
hashBlockSize  Blake2sp_256
_          = Int
64
    hashDigestSize :: Blake2sp_256 -> Int
hashDigestSize Blake2sp_256
_          = Int
32
    hashInternalContextSize :: Blake2sp_256 -> Int
hashInternalContextSize Blake2sp_256
_ = Int
1752
    hashInternalInit :: Ptr (Context Blake2sp_256) -> IO ()
hashInternalInit Ptr (Context Blake2sp_256)
p        = forall a. Ptr (Context a) -> Word32 -> IO ()
c_blake2sp_init Ptr (Context Blake2sp_256)
p Word32
256
    hashInternalUpdate :: Ptr (Context Blake2sp_256) -> Ptr Word8 -> Word32 -> IO ()
hashInternalUpdate        = forall a. Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
c_blake2sp_update
    hashInternalFinalize :: Ptr (Context Blake2sp_256) -> Ptr (Digest Blake2sp_256) -> IO ()
hashInternalFinalize Ptr (Context Blake2sp_256)
p    = forall a. Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()
c_blake2sp_finalize Ptr (Context Blake2sp_256)
p Word32
256


foreign import ccall unsafe "crypton_blake2sp_init"
    c_blake2sp_init :: Ptr (Context a) -> Word32 -> IO ()

foreign import ccall "crypton_blake2sp_update"
    c_blake2sp_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()

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