cryptonite-0.25: Cryptography Primitives sink

License | BSD-style
Maintainer | Vincent Hanquez <vincent@snarc.org>
Stability | experimental
Portability | unknown
Safe Haskell | None
Language | Haskell2010

Crypto.Hash

Contents

- Types
- Functions
- Hash methods parametrized by algorithm
- Hash methods
- Hash algorithms

Description

Generalized cryptographic hash interface, that you can use with cryptographic hash algorithm that belong to the HashAlgorithm type class.

    import Crypto.Hash

    sha1 :: ByteString -> Digest SHA1
    sha1 = hash

    hexSha3_512 :: ByteString -> String
    hexSha3_512 bs = show (hash bs :: Digest SHA3_512)

Synopsis

- data Context a
- data Digest a
- digestFromByteString :: forall a ba. (HashAlgorithm a, ByteArrayAccess ba) => ba -> Maybe (Digest a)
- hashInitWith :: HashAlgorithm alg => alg -> Context alg
- hashWith :: (ByteArrayAccess ba, HashAlgorithm alg) => alg -> ba -> Digest alg
- hashInit :: forall a. HashAlgorithm a => Context a
- hashUpdates :: forall a ba. (HashAlgorithm a, ByteArrayAccess ba) => Context a -> [ba] -> Context a
- hashUpdate :: (ByteArrayAccess ba, HashAlgorithm a) => Context a -> ba -> Context a
- hashFinalize :: forall a. HashAlgorithm a => Context a -> Digest a
- hashBlockSize :: HashAlgorithm a => a -> Int
- hashDigestSize :: HashAlgorithm a => a -> Int
- hash :: (ByteArrayAccess ba, HashAlgorithm a) => ba -> Digest a
- hashlazy :: HashAlgorithm a => ByteString -> Digest a
- module Crypto.Hash.Algorithms

# Types

data Context a #

Represent a context for a given hash algorithm.

Instances

NFData (Context a) # |
Instance details Defined in Crypto.Hash.Types Methods rnf :: Context a -> () #
ByteArrayAccess (Context a) # |
Instance details Defined in Crypto.Hash.Types Methods length :: Context a -> Int # withByteArray :: Context a -> (Ptr p -> IO a0) -> IO a0 # copyByteArrayToPtr :: Context a -> Ptr p -> IO () #

data Digest a #

Represent a digest for a given hash algorithm.

This type is an instance of `ByteArrayAccess` from package memory. Module Data.ByteArray provides many primitives to work with those values including conversion to other types.

Creating a digest from a bytearray is also possible with function `digestFromByteString`.

Instances

Eq (Digest a) # |
Instance details Defined in Crypto.Hash.Types Methods (==) :: Digest a -> Digest a -> Bool # (/=) :: Digest a -> Digest a -> Bool #
Ord (Digest a) # |
Instance details Defined in Crypto.Hash.Types Methods compare :: Digest a -> Digest a -> Ordering # (<) :: Digest a -> Digest a -> Bool # (<=) :: Digest a -> Digest a -> Bool # (>) :: Digest a -> Digest a -> Bool # (>=) :: Digest a -> Digest a -> Bool # max :: Digest a -> Digest a -> Digest a # min :: Digest a -> Digest a -> Digest a #
Show (Digest a) # |
Instance details Defined in Crypto.Hash.Types Methods showsPrec :: Int -> Digest a -> ShowS # show :: Digest a -> String # showList :: [Digest a] -> ShowS #
NFData (Digest a) # |
Instance details Defined in Crypto.Hash.Types Methods rnf :: Digest a -> () #
ByteArrayAccess (Digest a) # |
Instance details Defined in Crypto.Hash.Types Methods length :: Digest a -> Int # withByteArray :: Digest a -> (Ptr p -> IO a0) -> IO a0 # copyByteArrayToPtr :: Digest a -> Ptr p -> IO () #

# Functions

digestFromByteString :: forall a ba. (HashAlgorithm a, ByteArrayAccess ba) => ba -> Maybe (Digest a) #

Try to transform a bytearray into a Digest of specific algorithm.

If the digest is not the right size for the algorithm specified, then Nothing is returned.

# Hash methods parametrized by algorithm

hashInitWith :: HashAlgorithm alg => alg -> Context alg #

Initialize a new context for a specified hash algorithm

hashWith :: (ByteArrayAccess ba, HashAlgorithm alg) => alg -> ba -> Digest alg #

Run the `hash` function but takes an explicit hash algorithm parameter

# Hash methods

hashInit :: forall a. HashAlgorithm a => Context a #

Initialize a new context for this hash algorithm

hashUpdates :: forall a ba. (HashAlgorithm a, ByteArrayAccess ba) => Context a -> [ba] -> Context a #

Update the context with a list of strict bytestring, and return a new context with the updates.

hashUpdate :: (ByteArrayAccess ba, HashAlgorithm a) => Context a -> ba -> Context a #

run hashUpdates on one single bytestring and return the updated context.

hashFinalize :: forall a. HashAlgorithm a => Context a -> Digest a #

Finalize a context and return a digest.

hashBlockSize :: HashAlgorithm a => a -> Int #

Get the block size of a hash algorithm

hashDigestSize :: HashAlgorithm a => a -> Int #

Get the digest size of a hash algorithm

hash :: (ByteArrayAccess ba, HashAlgorithm a) => ba -> Digest a #

Hash a strict bytestring into a digest.

hashlazy :: HashAlgorithm a => ByteString -> Digest a #

Hash a lazy bytestring into a digest.

# Hash algorithms

module Crypto.Hash.Algorithms