License | BSD-style |
---|---|
Maintainer | Vincent Hanquez <vincent@snarc.org> |
Stability | experimental |
Portability | unknown |
Safe Haskell | Trustworthy |
Language | Haskell98 |
Crypto.Hash
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)
- class HashAlgorithm a where
- type HashFunctionBS a = ByteString -> Digest a
- type HashFunctionLBS a = ByteString -> Digest a
- data Context a
- data Digest a
- digestToByteString :: Digest a -> ByteString
- digestToHexByteString :: Digest a -> ByteString
- hash :: HashAlgorithm a => ByteString -> Digest a
- hashlazy :: HashAlgorithm a => ByteString -> Digest a
- hashUpdate :: HashAlgorithm a => Context a -> ByteString -> Context a
- hashInitAlg :: HashAlgorithm alg => alg -> Context alg
- data MD2 :: * = MD2
- data MD4 :: * = MD4
- data MD5 :: * = MD5
- data SHA1 :: * = SHA1
- data SHA224 :: * = SHA224
- data SHA256 :: * = SHA256
- data SHA384 :: * = SHA384
- data SHA512 :: * = SHA512
- data RIPEMD160 :: * = RIPEMD160
- data Tiger :: * = Tiger
- data SHA3_224 :: * = SHA3_224
- data SHA3_256 :: * = SHA3_256
- data SHA3_384 :: * = SHA3_384
- data SHA3_512 :: * = SHA3_512
- data Skein256_224 :: * = Skein256_224
- data Skein256_256 :: * = Skein256_256
- data Skein512_224 :: * = Skein512_224
- data Skein512_256 :: * = Skein512_256
- data Skein512_384 :: * = Skein512_384
- data Skein512_512 :: * = Skein512_512
- data Whirlpool :: * = Whirlpool
- newtype HMAC a = HMAC {
- hmacGetDigest :: Digest a
- hmac :: HashAlgorithm a => ByteString -> ByteString -> HMAC a
- hmacAlg :: HashAlgorithm a => a -> ByteString -> ByteString -> HMAC a
Types
class HashAlgorithm a where Source #
Class representing hashing algorithms.
The hash algorithm is built over 3 primitives:
- init : create a new hashing context
- updates : update the hashing context with some strict bytestrings and return the new context
- finalize : finalize the context into a digest
Minimal complete definition
hashBlockSize, hashInit, hashUpdates, hashFinalize, digestFromByteString
Methods
hashBlockSize :: Context a -> Int Source #
Block size in bytes the hash algorithm operates on
hashInit :: Context a Source #
Initialize a new context for this hash algorithm
hashUpdates :: Context a -> [ByteString] -> Context a Source #
Update the context with a list of strict bytestring, and return a new context with the updates.
hashFinalize :: Context a -> Digest a Source #
Finalize a context and return a digest.
digestFromByteString :: ByteString -> Maybe (Digest a) Source #
Try to convert a binary digest bytestring to a digest.
Instances
HashAlgorithm Whirlpool Source # | Whirlpool cryptographic hash |
HashAlgorithm Tiger Source # | Tiger cryptographic hash |
HashAlgorithm Skein512_512 Source # | Skein512 (512 bits version) cryptographic hash |
HashAlgorithm Skein512_384 Source # | Skein512 (384 bits version) cryptographic hash |
HashAlgorithm Skein512_256 Source # | Skein512 (256 bits version) cryptographic hash |
HashAlgorithm Skein512_224 Source # | Skein512 (224 bits version) cryptographic hash |
HashAlgorithm Skein256_256 Source # | Skein256 (256 bits version) cryptographic hash |
HashAlgorithm Skein256_224 Source # | Skein256 (224 bits version) cryptographic hash |
HashAlgorithm SHA512 Source # | SHA512 cryptographic hash |
HashAlgorithm SHA384 Source # | SHA384 cryptographic hash |
HashAlgorithm SHA3_512 Source # | SHA3 (512 bits version) cryptographic hash |
HashAlgorithm SHA3_384 Source # | SHA3 (384 bits version) cryptographic hash |
HashAlgorithm SHA3_256 Source # | SHA3 (256 bits version) cryptographic hash |
HashAlgorithm SHA3_224 Source # | SHA3 (224 bits version) cryptographic hash |
HashAlgorithm SHA256 Source # | SHA256 cryptographic hash |
HashAlgorithm SHA224 Source # | SHA224 cryptographic hash |
HashAlgorithm SHA1 Source # | SHA1 cryptographic hash |
HashAlgorithm RIPEMD160 Source # | RIPEMD160 cryptographic hash |
HashAlgorithm MD5 Source # | MD5 cryptographic hash |
HashAlgorithm MD4 Source # | MD4 cryptographic hash |
HashAlgorithm MD2 Source # | MD2 cryptographic hash |
type HashFunctionBS a = ByteString -> Digest a Source #
Alias to a single pass hash function that operate on a strict bytestring
type HashFunctionLBS a = ByteString -> Digest a Source #
Alias to a single pass hash function that operate on a lazy bytestring
Represent a context for a given hash algorithm.
Represent a digest for a given hash algorithm.
Functions
digestToByteString :: Digest a -> ByteString Source #
Deprecated: use toBytes from byteable:Data.Byteable
return the binary bytestring. deprecated use toBytes.
digestToHexByteString :: Digest a -> ByteString Source #
Return the hexadecimal (base16) bytestring of the digest
hash :: HashAlgorithm a => ByteString -> Digest a Source #
Hash a strict bytestring into a digest.
hashlazy :: HashAlgorithm a => ByteString -> Digest a Source #
Hash a lazy bytestring into a digest.
hashUpdate :: HashAlgorithm a => Context a -> ByteString -> Context a Source #
run hashUpdates on one single bytestring and return the updated context.
hashInitAlg :: HashAlgorithm alg => alg -> Context alg Source #
Initialize a new context for a specified hash algorithm
hash algorithms
Constructors
MD2 |
Constructors
MD4 |
Constructors
MD5 |
Constructors
SHA1 |
Constructors
SHA224 |
Constructors
SHA256 |
Constructors
SHA384 |
Constructors
SHA512 |
Constructors
RIPEMD160 |
Constructors
Tiger |
Constructors
SHA3_224 |
Constructors
SHA3_256 |
Constructors
SHA3_384 |
Constructors
SHA3_512 |
data Skein256_224 :: * #
Constructors
Skein256_224 |
Instances
Data Skein256_224 | |
Show Skein256_224 | |
HashAlgorithm Skein256_224 | |
HashAlgorithm Skein256_224 Source # | Skein256 (224 bits version) cryptographic hash |
type HashInternalContextSize Skein256_224 | |
type HashDigestSize Skein256_224 | |
type HashBlockSize Skein256_224 | |
data Skein256_256 :: * #
Constructors
Skein256_256 |
Instances
Data Skein256_256 | |
Show Skein256_256 | |
HashAlgorithm Skein256_256 | |
HashAlgorithm Skein256_256 Source # | Skein256 (256 bits version) cryptographic hash |
type HashInternalContextSize Skein256_256 | |
type HashDigestSize Skein256_256 | |
type HashBlockSize Skein256_256 | |
data Skein512_224 :: * #
Constructors
Skein512_224 |
Instances
Data Skein512_224 | |
Show Skein512_224 | |
HashAlgorithm Skein512_224 | |
HashAlgorithm Skein512_224 Source # | Skein512 (224 bits version) cryptographic hash |
type HashInternalContextSize Skein512_224 | |
type HashDigestSize Skein512_224 | |
type HashBlockSize Skein512_224 | |
data Skein512_256 :: * #
Constructors
Skein512_256 |
Instances
Data Skein512_256 | |
Show Skein512_256 | |
HashAlgorithm Skein512_256 | |
HashAlgorithm Skein512_256 Source # | Skein512 (256 bits version) cryptographic hash |
type HashInternalContextSize Skein512_256 | |
type HashDigestSize Skein512_256 | |
type HashBlockSize Skein512_256 | |
data Skein512_384 :: * #
Constructors
Skein512_384 |
Instances
Data Skein512_384 | |
Show Skein512_384 | |
HashAlgorithm Skein512_384 | |
HashAlgorithm Skein512_384 Source # | Skein512 (384 bits version) cryptographic hash |
type HashInternalContextSize Skein512_384 | |
type HashDigestSize Skein512_384 | |
type HashBlockSize Skein512_384 | |
data Skein512_512 :: * #
Constructors
Skein512_512 |
Instances
Data Skein512_512 | |
Show Skein512_512 | |
HashAlgorithm Skein512_512 | |
HashAlgorithm Skein512_512 Source # | Skein512 (512 bits version) cryptographic hash |
type HashInternalContextSize Skein512_512 | |
type HashDigestSize Skein512_512 | |
type HashBlockSize Skein512_512 | |
Constructors
Whirlpool |
MAC algorithms
Represent an HMAC that is a phantom type with the hash used to produce the mac.
The Eq instance is constant time.
Constructors
HMAC | |
Fields
|
Arguments
:: HashAlgorithm a | |
=> ByteString | Secret key |
-> ByteString | Message to MAC |
-> HMAC a |
compute a MAC using the supplied hashing function
Arguments
:: HashAlgorithm a | |
=> a | the hash algorithm the actual value is unused. |
-> ByteString | Secret key |
-> ByteString | Message to MAC |
-> HMAC a |
compute a HMAC using a specified algorithm