cryptohash-0.11.9: collection of crypto hashes, fast, pure and practical

LicenseBSD-style
MaintainerVincent Hanquez <vincent@snarc.org>
Stabilityexperimental
Portabilityunknown
Safe HaskellTrustworthy
LanguageHaskell98

Crypto.Hash

Contents

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

Types

class HashAlgorithm a where #

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

Methods

hashBlockSize :: Context a -> Int #

Block size in bytes the hash algorithm operates on

hashInit :: Context a #

Initialize a new context for this hash algorithm

hashUpdates :: Context a -> [ByteString] -> Context a #

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

hashFinalize :: Context a -> Digest a #

Finalize a context and return a digest.

digestFromByteString :: ByteString -> Maybe (Digest a) #

Try to convert a binary digest bytestring to a digest.

Instances

HashAlgorithm MD2 #

MD2 cryptographic hash

HashAlgorithm MD4 #

MD4 cryptographic hash

HashAlgorithm MD5 #

MD5 cryptographic hash

HashAlgorithm RIPEMD160 #

RIPEMD160 cryptographic hash

HashAlgorithm SHA1 #

SHA1 cryptographic hash

HashAlgorithm SHA224 #

SHA224 cryptographic hash

HashAlgorithm SHA256 #

SHA256 cryptographic hash

HashAlgorithm SHA3_224 #

SHA3 (224 bits version) cryptographic hash

HashAlgorithm SHA3_256 #

SHA3 (256 bits version) cryptographic hash

HashAlgorithm SHA3_384 #

SHA3 (384 bits version) cryptographic hash

HashAlgorithm SHA3_512 #

SHA3 (512 bits version) cryptographic hash

HashAlgorithm SHA384 #

SHA384 cryptographic hash

HashAlgorithm SHA512 #

SHA512 cryptographic hash

HashAlgorithm Skein256_224 #

Skein256 (224 bits version) cryptographic hash

HashAlgorithm Skein256_256 #

Skein256 (256 bits version) cryptographic hash

HashAlgorithm Skein512_224 #

Skein512 (224 bits version) cryptographic hash

HashAlgorithm Skein512_256 #

Skein512 (256 bits version) cryptographic hash

HashAlgorithm Skein512_384 #

Skein512 (384 bits version) cryptographic hash

HashAlgorithm Skein512_512 #

Skein512 (512 bits version) cryptographic hash

HashAlgorithm Tiger #

Tiger cryptographic hash

HashAlgorithm Whirlpool #

Whirlpool cryptographic hash

type HashFunctionBS a = ByteString -> Digest a #

Alias to a single pass hash function that operate on a strict bytestring

type HashFunctionLBS a = ByteString -> Digest a #

Alias to a single pass hash function that operate on a lazy bytestring

data Context a #

Represent a context for a given hash algorithm.

Instances

data Digest a #

Represent a digest for a given hash algorithm.

Instances

Eq (Digest a) # 

Methods

(==) :: Digest a -> Digest a -> Bool #

(/=) :: Digest a -> Digest a -> Bool #

Ord (Digest a) # 

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) # 

Methods

showsPrec :: Int -> Digest a -> ShowS #

show :: Digest a -> String #

showList :: [Digest a] -> ShowS #

Byteable (Digest a) # 

Methods

toBytes :: Digest a -> ByteString #

byteableLength :: Digest a -> Int #

withBytePtr :: Digest a -> (Ptr Word8 -> IO b) -> IO b #

Functions

digestToByteString :: Digest a -> ByteString #

Deprecated: use toBytes from byteable:Data.Byteable

return the binary bytestring. deprecated use toBytes.

digestToHexByteString :: Digest a -> ByteString #

Return the hexadecimal (base16) bytestring of the digest

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

Hash a strict bytestring into a digest.

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

Hash a lazy bytestring into a digest.

hashUpdate :: HashAlgorithm a => Context a -> ByteString -> Context a #

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

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

Initialize a new context for a specified hash algorithm

hash algorithms

MAC algorithms

newtype HMAC a #

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

Instances

Eq (HMAC a) # 

Methods

(==) :: HMAC a -> HMAC a -> Bool #

(/=) :: HMAC a -> HMAC a -> Bool #

Byteable (HMAC a) # 

Methods

toBytes :: HMAC a -> ByteString #

byteableLength :: HMAC a -> Int #

withBytePtr :: HMAC a -> (Ptr Word8 -> IO b) -> IO b #

hmac #

Arguments

:: HashAlgorithm a 
=> ByteString

Secret key

-> ByteString

Message to MAC

-> HMAC a 

compute a MAC using the supplied hashing function

hmacAlg #

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