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

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

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

-- | The Hash implementation, i.e. `HashI` associated with the
-- portable C implementation for the hash SHA256. This can be used to
-- define an implementation of truncated hashes like SHA224.
cPortable :: HashI SHA256 (HashMemory SHA256)
cPortable :: HashI SHA256 (HashMemory SHA256)
cPortable = String
-> String
-> Compressor SHA256
-> LengthWrite SHA256
-> HashI SHA256 (HashMemory SHA256)
forall h.
IsSha h =>
String
-> String
-> Compressor h
-> LengthWrite h
-> HashI h (HashMemory h)
shaImplementation
            String
"sha256-cportable"
            String
"Sha256 Implementation using portable C and Haskell FFI"
            Compressor SHA256
c_sha256_compress LengthWrite SHA256
forall h. LengthWrite h
length64Write


foreign import ccall unsafe
  "raaz/hash/sha256/portable.h raazHashSha256PortableCompress"
  c_sha256_compress  :: Pointer -> Int -> Ptr SHA256 -> IO ()