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

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

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

instance HashAlgorithm RIPEMD160 where
    type HashBlockSize           RIPEMD160 = 64
    type HashDigestSize          RIPEMD160 = 20
    type HashInternalContextSize RIPEMD160 = 128
    hashBlockSize :: RIPEMD160 -> Int
hashBlockSize  RIPEMD160
_          = Int
64
    hashDigestSize :: RIPEMD160 -> Int
hashDigestSize RIPEMD160
_          = Int
20
    hashInternalContextSize :: RIPEMD160 -> Int
hashInternalContextSize RIPEMD160
_ = Int
128
    hashInternalInit :: Ptr (Context RIPEMD160) -> IO ()
hashInternalInit          = Ptr (Context RIPEMD160) -> IO ()
forall a. Ptr (Context a) -> IO ()
c_ripemd160_init
    hashInternalUpdate :: Ptr (Context RIPEMD160) -> Ptr Word8 -> Word32 -> IO ()
hashInternalUpdate        = Ptr (Context RIPEMD160) -> Ptr Word8 -> Word32 -> IO ()
forall a. Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
c_ripemd160_update
    hashInternalFinalize :: Ptr (Context RIPEMD160) -> Ptr (Digest RIPEMD160) -> IO ()
hashInternalFinalize      = Ptr (Context RIPEMD160) -> Ptr (Digest RIPEMD160) -> IO ()
forall a. Ptr (Context a) -> Ptr (Digest a) -> IO ()
c_ripemd160_finalize

foreign import ccall unsafe "cryptonite_ripemd160_init"
    c_ripemd160_init :: Ptr (Context a)-> IO ()

foreign import ccall "cryptonite_ripemd160_update"
    c_ripemd160_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()

foreign import ccall unsafe "cryptonite_ripemd160_finalize"
    c_ripemd160_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()