-- |
-- 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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MD2] -> ShowS
$cshowList :: [MD2] -> ShowS
show :: MD2 -> String
$cshow :: MD2 -> String
showsPrec :: Int -> MD2 -> ShowS
$cshowsPrec :: Int -> MD2 -> ShowS
Show,Typeable MD2
MD2 -> DataType
MD2 -> Constr
(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)
gmapMo :: 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
gmapMp :: forall (m :: * -> *).
MonadPlus 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
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> MD2 -> m MD2
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> MD2 -> m MD2
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> MD2 -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> MD2 -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> MD2 -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> MD2 -> [u]
gmapQr :: 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
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> MD2 -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> MD2 -> r
gmapT :: (forall b. Data b => b -> b) -> MD2 -> MD2
$cgmapT :: (forall b. Data b => b -> b) -> MD2 -> MD2
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c MD2)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c MD2)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c MD2)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c MD2)
dataTypeOf :: MD2 -> DataType
$cdataTypeOf :: MD2 -> DataType
toConstr :: MD2 -> Constr
$ctoConstr :: MD2 -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c MD2
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c MD2
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> MD2 -> c MD2
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> MD2 -> c 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          = forall a. Ptr (Context a) -> IO ()
c_md2_init
    hashInternalUpdate :: Ptr (Context MD2) -> Ptr Word8 -> Word32 -> IO ()
hashInternalUpdate        = forall a. Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
c_md2_update
    hashInternalFinalize :: Ptr (Context MD2) -> Ptr (Digest MD2) -> IO ()
hashInternalFinalize      = forall a. Ptr (Context a) -> Ptr (Digest a) -> IO ()
c_md2_finalize

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

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

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