License | BSD-style |
---|---|
Maintainer | Vincent Hanquez <vincent@snarc.org> |
Stability | experimental |
Portability | unknown |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Generalized impure cryptographic hash interface
Synopsis
- class HashAlgorithm a where
- type HashBlockSize a :: Nat
- type HashDigestSize a :: Nat
- type HashInternalContextSize a :: Nat
- hashBlockSize :: a -> Int
- hashDigestSize :: a -> Int
- hashInternalContextSize :: a -> Int
- hashInternalInit :: Ptr (Context a) -> IO ()
- hashInternalUpdate :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
- hashInternalFinalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()
- data MutableContext a
- hashMutableInit :: HashAlgorithm alg => IO (MutableContext alg)
- hashMutableInitWith :: HashAlgorithm alg => alg -> IO (MutableContext alg)
- hashMutableUpdate :: (ByteArrayAccess ba, HashAlgorithm a) => MutableContext a -> ba -> IO ()
- hashMutableFinalize :: forall a. HashAlgorithm a => MutableContext a -> IO (Digest a)
- hashMutableReset :: HashAlgorithm a => MutableContext a -> IO ()
Documentation
class HashAlgorithm a where Source #
Class representing hashing algorithms.
The interface presented here is update in place and lowlevel. the Hash module takes care of hidding the mutable interface properly.
type HashBlockSize a :: Nat Source #
Associated type for the block size of the hash algorithm
type HashDigestSize a :: Nat Source #
Associated type for the digest size of the hash algorithm
type HashInternalContextSize a :: Nat Source #
Associated type for the internal context size of the hash algorithm
hashBlockSize :: a -> Int Source #
Get the block size of a hash algorithm
hashDigestSize :: a -> Int Source #
Get the digest size of a hash algorithm
hashInternalContextSize :: a -> Int Source #
Get the size of the context used for a hash algorithm
hashInternalInit :: Ptr (Context a) -> IO () Source #
Initialize a context pointer to the initial state of a hash algorithm
hashInternalUpdate :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO () Source #
Update the context with some raw data
hashInternalFinalize :: Ptr (Context a) -> Ptr (Digest a) -> IO () Source #
Finalize the context and set the digest raw memory to the right value
Instances
data MutableContext a Source #
A Mutable hash context
This type is an instance of ByteArrayAccess
for debugging purpose.
Internal layout is architecture dependent, may contain uninitialized data
fragments, and change in future versions. The bytearray should not be used
as input to cryptographic algorithms.
Instances
ByteArrayAccess (MutableContext a) Source # | |
Defined in Crypto.Hash.IO length :: MutableContext a -> Int Source # withByteArray :: MutableContext a -> (Ptr p -> IO a0) -> IO a0 Source # copyByteArrayToPtr :: MutableContext a -> Ptr p -> IO () Source # |
hashMutableInit :: HashAlgorithm alg => IO (MutableContext alg) Source #
Create a new mutable hash context.
the algorithm used is automatically determined from the return constraint.
hashMutableInitWith :: HashAlgorithm alg => alg -> IO (MutableContext alg) Source #
Create a new mutable hash context.
The algorithm is explicitely passed as parameter
hashMutableUpdate :: (ByteArrayAccess ba, HashAlgorithm a) => MutableContext a -> ba -> IO () Source #
Update a mutable hash context in place
hashMutableFinalize :: forall a. HashAlgorithm a => MutableContext a -> IO (Digest a) Source #
Finalize a mutable hash context and compute a digest
hashMutableReset :: HashAlgorithm a => MutableContext a -> IO () Source #
Reset the mutable context to the initial state of the hash