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

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

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

instance HashAlgorithm SHA224 where
    type HashBlockSize           SHA224 = 64
    type HashDigestSize          SHA224 = 28
    type HashInternalContextSize SHA224 = 192
    hashBlockSize :: SHA224 -> Int
hashBlockSize  SHA224
_          = Int
64
    hashDigestSize :: SHA224 -> Int
hashDigestSize SHA224
_          = Int
28
    hashInternalContextSize :: SHA224 -> Int
hashInternalContextSize SHA224
_ = Int
192
    hashInternalInit :: Ptr (Context SHA224) -> IO ()
hashInternalInit          = Ptr (Context SHA224) -> IO ()
forall a. Ptr (Context a) -> IO ()
c_sha224_init
    hashInternalUpdate :: Ptr (Context SHA224) -> Ptr Word8 -> Word32 -> IO ()
hashInternalUpdate        = Ptr (Context SHA224) -> Ptr Word8 -> Word32 -> IO ()
forall a. Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
c_sha224_update
    hashInternalFinalize :: Ptr (Context SHA224) -> Ptr (Digest SHA224) -> IO ()
hashInternalFinalize      = Ptr (Context SHA224) -> Ptr (Digest SHA224) -> IO ()
forall a. Ptr (Context a) -> Ptr (Digest a) -> IO ()
c_sha224_finalize

instance HashAlgorithmPrefix SHA224 where
    hashInternalFinalizePrefix :: Ptr (Context SHA224)
-> Ptr Word8 -> Word32 -> Word32 -> Ptr (Digest SHA224) -> IO ()
hashInternalFinalizePrefix = Ptr (Context SHA224)
-> Ptr Word8 -> Word32 -> Word32 -> Ptr (Digest SHA224) -> IO ()
forall a.
Ptr (Context a)
-> Ptr Word8 -> Word32 -> Word32 -> Ptr (Digest a) -> IO ()
c_sha224_finalize_prefix

foreign import ccall unsafe "crypton_sha224_init"
    c_sha224_init :: Ptr (Context a)-> IO ()

foreign import ccall "crypton_sha224_update"
    c_sha224_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()

foreign import ccall unsafe "crypton_sha224_finalize"
    c_sha224_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()

foreign import ccall "crypton_sha224_finalize_prefix"
    c_sha224_finalize_prefix :: Ptr (Context a) -> Ptr Word8 -> Word32 -> Word32 -> Ptr (Digest a) -> IO ()