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

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

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

instance HashAlgorithm Tiger where
    type HashBlockSize           Tiger = 64
    type HashDigestSize          Tiger = 24
    type HashInternalContextSize Tiger = 96
    hashBlockSize :: Tiger -> Int
hashBlockSize  Tiger
_          = Int
64
    hashDigestSize :: Tiger -> Int
hashDigestSize Tiger
_          = Int
24
    hashInternalContextSize :: Tiger -> Int
hashInternalContextSize Tiger
_ = Int
96
    hashInternalInit :: Ptr (Context Tiger) -> IO ()
hashInternalInit          = Ptr (Context Tiger) -> IO ()
forall a. Ptr (Context a) -> IO ()
c_tiger_init
    hashInternalUpdate :: Ptr (Context Tiger) -> Ptr Word8 -> Word32 -> IO ()
hashInternalUpdate        = Ptr (Context Tiger) -> Ptr Word8 -> Word32 -> IO ()
forall a. Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
c_tiger_update
    hashInternalFinalize :: Ptr (Context Tiger) -> Ptr (Digest Tiger) -> IO ()
hashInternalFinalize      = Ptr (Context Tiger) -> Ptr (Digest Tiger) -> IO ()
forall a. Ptr (Context a) -> Ptr (Digest a) -> IO ()
c_tiger_finalize

foreign import ccall unsafe "crypton_tiger_init"
    c_tiger_init :: Ptr (Context a)-> IO ()

foreign import ccall "crypton_tiger_update"
    c_tiger_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()

foreign import ccall unsafe "crypton_tiger_finalize"
    c_tiger_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()