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

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

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

instance HashAlgorithm MD5 where
    type HashBlockSize           MD5 = 64
    type HashDigestSize          MD5 = 16
    type HashInternalContextSize MD5 = 96
    hashBlockSize :: MD5 -> Int
hashBlockSize  MD5
_          = Int
64
    hashDigestSize :: MD5 -> Int
hashDigestSize MD5
_          = Int
16
    hashInternalContextSize :: MD5 -> Int
hashInternalContextSize MD5
_ = Int
96
    hashInternalInit :: Ptr (Context MD5) -> IO ()
hashInternalInit          = forall a. Ptr (Context a) -> IO ()
c_md5_init
    hashInternalUpdate :: Ptr (Context MD5) -> Ptr Word8 -> Word32 -> IO ()
hashInternalUpdate        = forall a. Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
c_md5_update
    hashInternalFinalize :: Ptr (Context MD5) -> Ptr (Digest MD5) -> IO ()
hashInternalFinalize      = forall a. Ptr (Context a) -> Ptr (Digest a) -> IO ()
c_md5_finalize

instance HashAlgorithmPrefix MD5 where
    hashInternalFinalizePrefix :: Ptr (Context MD5)
-> Ptr Word8 -> Word32 -> Word32 -> Ptr (Digest MD5) -> IO ()
hashInternalFinalizePrefix = forall a.
Ptr (Context a)
-> Ptr Word8 -> Word32 -> Word32 -> Ptr (Digest a) -> IO ()
c_md5_finalize_prefix

foreign import ccall unsafe "crypton_md5_init"
    c_md5_init :: Ptr (Context a)-> IO ()

foreign import ccall "crypton_md5_update"
    c_md5_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()

foreign import ccall unsafe "crypton_md5_finalize"
    c_md5_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()

foreign import ccall "crypton_md5_finalize_prefix"
    c_md5_finalize_prefix :: Ptr (Context a) -> Ptr Word8 -> Word32 -> Word32 -> Ptr (Digest a) -> IO ()