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

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

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

instance HashAlgorithm MD2 where
    type HashBlockSize           MD2 = 16
    type HashDigestSize          MD2 = 16
    type HashInternalContextSize MD2 = 96
    hashBlockSize :: MD2 -> Int
hashBlockSize  MD2
_          = Int
16
    hashDigestSize :: MD2 -> Int
hashDigestSize MD2
_          = Int
16
    hashInternalContextSize :: MD2 -> Int
hashInternalContextSize MD2
_ = Int
96
    hashInternalInit :: Ptr (Context MD2) -> IO ()
hashInternalInit          = Ptr (Context MD2) -> IO ()
forall a. Ptr (Context a) -> IO ()
c_md2_init
    hashInternalUpdate :: Ptr (Context MD2) -> Ptr Word8 -> Word32 -> IO ()
hashInternalUpdate        = Ptr (Context MD2) -> Ptr Word8 -> Word32 -> IO ()
forall a. Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
c_md2_update
    hashInternalFinalize :: Ptr (Context MD2) -> Ptr (Digest MD2) -> IO ()
hashInternalFinalize      = Ptr (Context MD2) -> Ptr (Digest MD2) -> IO ()
forall a. Ptr (Context a) -> Ptr (Digest a) -> IO ()
c_md2_finalize

foreign import ccall unsafe "cryptonite_md2_init"
    c_md2_init :: Ptr (Context a)-> IO ()

foreign import ccall "cryptonite_md2_update"
    c_md2_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()

foreign import ccall unsafe "cryptonite_md2_finalize"
    c_md2_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()