{-# LANGUAGE ForeignFunctionInterface   #-}
-- | The portable C-implementation of SHA512
module Raaz.Hash.Sha512.Implementation.CPortable
       ( implementation, cPortable
       ) where

import Foreign.Ptr                ( Ptr )
import Raaz.Core
import Raaz.Hash.Internal
import Raaz.Hash.Sha.Util
import Raaz.Hash.Sha512.Internal

-- | The portable C implementation of SHA512.
implementation :: Implementation SHA512
implementation :: Implementation SHA512
implementation =  HashI SHA512 (HashMemory SHA512) -> SomeHashI SHA512
forall h m. HashM h m => HashI h m -> SomeHashI h
SomeHashI HashI SHA512 (HashMemory SHA512)
cPortable

-- | The Hash implementation, i.e. `HashI` associated with the
-- portable C implementation for the hash SHA512. This can be used
-- to implement truncated implementation like SHA384.
cPortable :: HashI SHA512 (HashMemory SHA512)
cPortable :: HashI SHA512 (HashMemory SHA512)
cPortable = String
-> String
-> Compressor SHA512
-> LengthWrite SHA512
-> HashI SHA512 (HashMemory SHA512)
forall h.
IsSha h =>
String
-> String
-> Compressor h
-> LengthWrite h
-> HashI h (HashMemory h)
shaImplementation
            String
"sha512-cportable"
            String
"Sha512 Implementation using portable C and Haskell FFI"
            Compressor SHA512
c_sha512_compress LengthWrite SHA512
forall h. LengthWrite h
length128Write

foreign import ccall unsafe
  "raaz/hash/sha512/portable.h raazHashSha512PortableCompress"
  c_sha512_compress  :: Pointer -> Int -> Ptr SHA512 -> IO ()