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

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

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

instance HashAlgorithm Whirlpool where
    type HashBlockSize           Whirlpool = 64
    type HashDigestSize          Whirlpool = 64
    type HashInternalContextSize Whirlpool = 168
    hashBlockSize :: Whirlpool -> Int
hashBlockSize  Whirlpool
_          = Int
64
    hashDigestSize :: Whirlpool -> Int
hashDigestSize Whirlpool
_          = Int
64
    hashInternalContextSize :: Whirlpool -> Int
hashInternalContextSize Whirlpool
_ = Int
168
    hashInternalInit :: Ptr (Context Whirlpool) -> IO ()
hashInternalInit          = Ptr (Context Whirlpool) -> IO ()
forall a. Ptr (Context a) -> IO ()
c_whirlpool_init
    hashInternalUpdate :: Ptr (Context Whirlpool) -> Ptr Word8 -> Word32 -> IO ()
hashInternalUpdate        = Ptr (Context Whirlpool) -> Ptr Word8 -> Word32 -> IO ()
forall a. Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
c_whirlpool_update
    hashInternalFinalize :: Ptr (Context Whirlpool) -> Ptr (Digest Whirlpool) -> IO ()
hashInternalFinalize      = Ptr (Context Whirlpool) -> Ptr (Digest Whirlpool) -> IO ()
forall a. Ptr (Context a) -> Ptr (Digest a) -> IO ()
c_whirlpool_finalize

foreign import ccall unsafe "cryptonite_whirlpool_init"
    c_whirlpool_init :: Ptr (Context a)-> IO ()

foreign import ccall "cryptonite_whirlpool_update"
    c_whirlpool_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()

foreign import ccall unsafe "cryptonite_whirlpool_finalize"
    c_whirlpool_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()