Portability  portable 

Stability  experimental 
Maintainer  stbuehler@web.de 
Safe Haskell  None 
This module exports hash algorithms supported by nettle: http://www.lysator.liu.se/~nisse/nettle/
 class HashAlgorithm a where
 hashBlockSize :: Tagged a Int
 hashDigestSize :: Tagged a Int
 hashName :: Tagged a String
 hashInit :: a
 hashUpdate :: a > B.ByteString > a
 hashUpdateLazy :: a > ByteString > a
 hashFinalize :: a > B.ByteString
 hashHMAC :: B.ByteString > Tagged a KeyedHash
 hash :: HashAlgorithm a => B.ByteString > Tagged a B.ByteString
 hash' :: HashAlgorithm a => a > B.ByteString > B.ByteString
 hashLazy :: HashAlgorithm a => ByteString > Tagged a ByteString
 hashLazy' :: HashAlgorithm a => a > ByteString > ByteString
 data GOSTHASH94
 data MD2
 data MD4
 data MD5
 data RIPEMD160
 data SHA1
 data SHA224
 data SHA256
 data SHA384
 data SHA512
 data SHA3_224
 data SHA3_256
 data SHA3_384
 data SHA3_512
HashAlgorithm class
class HashAlgorithm a whereSource
HashAlgorithm
is a class that hash algorithms will implement. generating a digest is a 3 step procedure:

hashInit
to create a new context 
hashUpdate
to hash data 
hashFinalize
to extract the final digest
The final digest has hashDigestSize
bytes, and the algorithm uses hashBlockSize
as internal block size.
hashBlockSize :: Tagged a IntSource
Block size in bytes the hash algorithm operates on
hashDigestSize :: Tagged a IntSource
Digest size in bytes the hash algorithm returns
hashName :: Tagged a StringSource
Name of the hash algorithm
Initialize a new context for this hash algorithm
hashUpdate :: a > B.ByteString > aSource
Update the context with bytestring, and return a new context with the updates.
hashUpdateLazy :: a > ByteString > aSource
Update the context with a lazy bytestring, and return a new context with the updates.
hashFinalize :: a > B.ByteStringSource
Finalize a context and return a digest.
hashHMAC :: B.ByteString > Tagged a KeyedHashSource
Use HashAlgorithm
for HMAC; can use a optimized variant or the default hmacInit
one
hash :: HashAlgorithm a => B.ByteString > Tagged a B.ByteStringSource
Helper to hash a single (strict) B.ByteString
in one step.
Example:
untag (hash (fromString "abc") :: Tagged SHA256 B.ByteString)
hash' :: HashAlgorithm a => a > B.ByteString > B.ByteStringSource
Untagged variant of hash
; takes a (possible undefined
) typed HashAlgorithm
context as parameter.
Example:
hash' (undefined :: SHA256) $ fromString "abc"
hashLazy :: HashAlgorithm a => ByteString > Tagged a ByteStringSource
Helper to hash a single (lazy) ByteString
in one step.
Example:
untag (hashLazy (fromString "abc") :: Tagged SHA256 L.ByteString)
hashLazy' :: HashAlgorithm a => a > ByteString > ByteStringSource
Untagged variant of hashLazy
; takes a (possible undefined
) typed HashAlgorithm
context as parameter.
Example:
hashLazy' (undefined :: SHA256) $ fromString "abc"
hash algorithms
Only members of the SHA2 and SHA3 family have no known weaknesses (according to http://www.lysator.liu.se/~nisse/nettle/nettle.html#Hashfunctions)
GOSTHASH94
data GOSTHASH94 Source
The GOST94 or GOST R 34.1194 hash algorithm is a Sovietera algorithm used in Russian government standards (see RFC 4357). It outputs message digests of 32 bytes (256 bits).
MD family
MD2
is a hash function of Ronald Rivest's, described in RFC 1319. It outputs message digests of 16 bytes (128 bits).
MD4
is a hash function of Ronald Rivest's, described in RFC 1320. It outputs message digests of 16 bytes (128 bits).
MD5
is a hash function of Ronald Rivest's, described in RFC 1321. It outputs message digests of 16 bytes (128 bits).
RIPEMD160
RIPEMD160
is a hash function designed by Hans Dobbertin, Antoon Bosselaers, and Bart Preneel, as a strengthened version of RIPEMD.
It produces message digests of 20 bytes (160 bits).
SHA1
SHA1
is a hash function specified by NIST (The U.S. National Institute for Standards and Technology).
It produces message digests of 20 bytes (160 bits).
SHA2 family
The SHA2 family supports digests lengths of 28, 32, 48 or 64 bytes (224, 256, 384, 512 bits), and the variants are named after the bit length.
The SHA2 family of hash functions were specified by NIST, intended as a replacement for SHA1
.
SHA224
is a member of the SHA2 family which outputs messages digests of 28 bytes (224 bits).
SHA256
is a member of the SHA2 family which outputs messages digests of 32 bytes (256 bits).
SHA384
is a member of the SHA2 family which outputs messages digests of 48 bytes (384 bits).
SHA512
is a member of the SHA2 family which outputs messages digests of 64 bytes (512 bits).
SHA3 family
The SHA3 family supports (like SHA2) digests lengths of 28, 32, 48 or 64 bytes (224, 256, 384, 512 bits), and the variants are named after the bit length.
The SHA3 hash functions were specified by NIST in response to weaknesses in SHA1, and doubts about SHA2 hash functions which structurally are very similar to SHA1. The standard is a result of a competition, where the winner, also known as Keccak, was designed by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche. It is structurally very different from all widely used earlier hash functions.
SHA3_224
is a member of the SHA3 family which outputs messages digests of 28 bytes (224 bits).
SHA3_256
is a member of the SHA3 family which outputs messages digests of 32 bytes (256 bits).
SHA3_384
is a member of the SHA3 family which outputs messages digests of 48 bytes (384 bits).
SHA3_512
is a member of the SHA3 family which outputs messages digests of 64 bytes (512 bits).