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

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

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

instance HashAlgorithm SHA1 where
    type HashBlockSize           SHA1 = 64
    type HashDigestSize          SHA1 = 20
    type HashInternalContextSize SHA1 = 96
    hashBlockSize :: SHA1 -> Int
hashBlockSize  SHA1
_          = Int
64
    hashDigestSize :: SHA1 -> Int
hashDigestSize SHA1
_          = Int
20
    hashInternalContextSize :: SHA1 -> Int
hashInternalContextSize SHA1
_ = Int
96
    hashInternalInit :: Ptr (Context SHA1) -> IO ()
hashInternalInit          = Ptr (Context SHA1) -> IO ()
forall a. Ptr (Context a) -> IO ()
c_sha1_init
    hashInternalUpdate :: Ptr (Context SHA1) -> Ptr Word8 -> Word32 -> IO ()
hashInternalUpdate        = Ptr (Context SHA1) -> Ptr Word8 -> Word32 -> IO ()
forall a. Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
c_sha1_update
    hashInternalFinalize :: Ptr (Context SHA1) -> Ptr (Digest SHA1) -> IO ()
hashInternalFinalize      = Ptr (Context SHA1) -> Ptr (Digest SHA1) -> IO ()
forall a. Ptr (Context a) -> Ptr (Digest a) -> IO ()
c_sha1_finalize

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

foreign import ccall unsafe "cryptonite_sha1_init"
    c_sha1_init :: Ptr (Context a)-> IO ()

foreign import ccall "cryptonite_sha1_update"
    c_sha1_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()

foreign import ccall unsafe "cryptonite_sha1_finalize"
    c_sha1_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()

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