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)
Synopsis
- class HashAlgorithm a where
- hashBlockSize :: Context a -> Int
- hashInit :: Context a
- hashUpdates :: Context a -> [ByteString] -> Context a
- hashFinalize :: Context a -> Digest a
- digestFromByteString :: ByteString -> Maybe (Digest a)
- 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 #
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
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
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
Represent a context for a given hash algorithm.
Instances
Byteable (Context a) # | |
Defined in Crypto.Hash.Types |
Represent a digest for a given hash algorithm.
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
MD2 cryptographic hash algorithm
Constructors
MD2 |
Instances
Data MD2 | |
Defined in Crypto.Hash.MD2 Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> MD2 -> c MD2 # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c MD2 # dataTypeOf :: MD2 -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c MD2) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c MD2) # gmapT :: (forall b. Data b => b -> b) -> MD2 -> MD2 # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> MD2 -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> MD2 -> r # gmapQ :: (forall d. Data d => d -> u) -> MD2 -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> MD2 -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> MD2 -> m MD2 # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> MD2 -> m MD2 # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> MD2 -> m MD2 # | |
Show MD2 | |
HashAlgorithm MD2 | |
Defined in Crypto.Hash.MD2 Associated Types type HashBlockSize MD2 :: Nat # type HashDigestSize MD2 :: Nat # type HashInternalContextSize MD2 :: Nat # | |
HashAlgorithm MD2 # | MD2 cryptographic hash |
Defined in Crypto.Hash Methods hashBlockSize :: Context MD2 -> Int # hashUpdates :: Context MD2 -> [ByteString] -> Context MD2 # hashFinalize :: Context MD2 -> Digest MD2 # digestFromByteString :: ByteString -> Maybe (Digest MD2) # | |
type HashInternalContextSize MD2 | |
Defined in Crypto.Hash.MD2 | |
type HashDigestSize MD2 | |
Defined in Crypto.Hash.MD2 | |
type HashBlockSize MD2 | |
Defined in Crypto.Hash.MD2 |
MD4 cryptographic hash algorithm
Constructors
MD4 |
Instances
Data MD4 | |
Defined in Crypto.Hash.MD4 Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> MD4 -> c MD4 # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c MD4 # dataTypeOf :: MD4 -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c MD4) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c MD4) # gmapT :: (forall b. Data b => b -> b) -> MD4 -> MD4 # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> MD4 -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> MD4 -> r # gmapQ :: (forall d. Data d => d -> u) -> MD4 -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> MD4 -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> MD4 -> m MD4 # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> MD4 -> m MD4 # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> MD4 -> m MD4 # | |
Show MD4 | |
HashAlgorithm MD4 | |
Defined in Crypto.Hash.MD4 Associated Types type HashBlockSize MD4 :: Nat # type HashDigestSize MD4 :: Nat # type HashInternalContextSize MD4 :: Nat # | |
HashAlgorithm MD4 # | MD4 cryptographic hash |
Defined in Crypto.Hash Methods hashBlockSize :: Context MD4 -> Int # hashUpdates :: Context MD4 -> [ByteString] -> Context MD4 # hashFinalize :: Context MD4 -> Digest MD4 # digestFromByteString :: ByteString -> Maybe (Digest MD4) # | |
type HashInternalContextSize MD4 | |
Defined in Crypto.Hash.MD4 | |
type HashDigestSize MD4 | |
Defined in Crypto.Hash.MD4 | |
type HashBlockSize MD4 | |
Defined in Crypto.Hash.MD4 |
MD5 cryptographic hash algorithm
Constructors
MD5 |
Instances
Data MD5 | |
Defined in Crypto.Hash.MD5 Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> MD5 -> c MD5 # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c MD5 # dataTypeOf :: MD5 -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c MD5) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c MD5) # gmapT :: (forall b. Data b => b -> b) -> MD5 -> MD5 # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> MD5 -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> MD5 -> r # gmapQ :: (forall d. Data d => d -> u) -> MD5 -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> MD5 -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> MD5 -> m MD5 # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> MD5 -> m MD5 # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> MD5 -> m MD5 # | |
Show MD5 | |
HashAlgorithm MD5 | |
Defined in Crypto.Hash.MD5 Associated Types type HashBlockSize MD5 :: Nat # type HashDigestSize MD5 :: Nat # type HashInternalContextSize MD5 :: Nat # | |
HashAlgorithmPrefix MD5 | |
HashAlgorithm MD5 # | MD5 cryptographic hash |
Defined in Crypto.Hash Methods hashBlockSize :: Context MD5 -> Int # hashUpdates :: Context MD5 -> [ByteString] -> Context MD5 # hashFinalize :: Context MD5 -> Digest MD5 # digestFromByteString :: ByteString -> Maybe (Digest MD5) # | |
type HashInternalContextSize MD5 | |
Defined in Crypto.Hash.MD5 | |
type HashDigestSize MD5 | |
Defined in Crypto.Hash.MD5 | |
type HashBlockSize MD5 | |
Defined in Crypto.Hash.MD5 |
SHA1 cryptographic hash algorithm
Constructors
SHA1 |
Instances
Data SHA1 | |
Defined in Crypto.Hash.SHA1 Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> SHA1 -> c SHA1 # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c SHA1 # dataTypeOf :: SHA1 -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c SHA1) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SHA1) # gmapT :: (forall b. Data b => b -> b) -> SHA1 -> SHA1 # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SHA1 -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SHA1 -> r # gmapQ :: (forall d. Data d => d -> u) -> SHA1 -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> SHA1 -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> SHA1 -> m SHA1 # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SHA1 -> m SHA1 # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SHA1 -> m SHA1 # | |
Show SHA1 | |
HashAlgorithm SHA1 | |
Defined in Crypto.Hash.SHA1 Associated Types type HashBlockSize SHA1 :: Nat # type HashDigestSize SHA1 :: Nat # type HashInternalContextSize SHA1 :: Nat # Methods hashBlockSize :: SHA1 -> Int # hashDigestSize :: SHA1 -> Int # hashInternalContextSize :: SHA1 -> Int # hashInternalInit :: Ptr (Context SHA1) -> IO () # hashInternalUpdate :: Ptr (Context SHA1) -> Ptr Word8 -> Word32 -> IO () # hashInternalFinalize :: Ptr (Context SHA1) -> Ptr (Digest SHA1) -> IO () # | |
HashAlgorithmPrefix SHA1 | |
HashAlgorithm SHA1 # | SHA1 cryptographic hash |
Defined in Crypto.Hash Methods hashBlockSize :: Context SHA1 -> Int # hashUpdates :: Context SHA1 -> [ByteString] -> Context SHA1 # hashFinalize :: Context SHA1 -> Digest SHA1 # digestFromByteString :: ByteString -> Maybe (Digest SHA1) # | |
type HashInternalContextSize SHA1 | |
Defined in Crypto.Hash.SHA1 | |
type HashDigestSize SHA1 | |
Defined in Crypto.Hash.SHA1 | |
type HashBlockSize SHA1 | |
Defined in Crypto.Hash.SHA1 |
SHA224 cryptographic hash algorithm
Constructors
SHA224 |
Instances
SHA256 cryptographic hash algorithm
Constructors
SHA256 |
Instances
SHA384 cryptographic hash algorithm
Constructors
SHA384 |
Instances
SHA512 cryptographic hash algorithm
Constructors
SHA512 |
Instances
RIPEMD160 cryptographic hash algorithm
Constructors
RIPEMD160 |
Instances
Tiger cryptographic hash algorithm
Constructors
Tiger |
Instances
Data Tiger | |
Defined in Crypto.Hash.Tiger Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Tiger -> c Tiger # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Tiger # dataTypeOf :: Tiger -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Tiger) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Tiger) # gmapT :: (forall b. Data b => b -> b) -> Tiger -> Tiger # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Tiger -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Tiger -> r # gmapQ :: (forall d. Data d => d -> u) -> Tiger -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Tiger -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Tiger -> m Tiger # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Tiger -> m Tiger # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Tiger -> m Tiger # | |
Show Tiger | |
HashAlgorithm Tiger | |
Defined in Crypto.Hash.Tiger Associated Types type HashBlockSize Tiger :: Nat # type HashDigestSize Tiger :: Nat # type HashInternalContextSize Tiger :: Nat # Methods hashBlockSize :: Tiger -> Int # hashDigestSize :: Tiger -> Int # hashInternalContextSize :: Tiger -> Int # hashInternalInit :: Ptr (Context Tiger) -> IO () # hashInternalUpdate :: Ptr (Context Tiger) -> Ptr Word8 -> Word32 -> IO () # hashInternalFinalize :: Ptr (Context Tiger) -> Ptr (Digest Tiger) -> IO () # | |
HashAlgorithm Tiger # | Tiger cryptographic hash |
Defined in Crypto.Hash Methods hashBlockSize :: Context Tiger -> Int # hashUpdates :: Context Tiger -> [ByteString] -> Context Tiger # hashFinalize :: Context Tiger -> Digest Tiger # digestFromByteString :: ByteString -> Maybe (Digest Tiger) # | |
type HashInternalContextSize Tiger | |
Defined in Crypto.Hash.Tiger | |
type HashDigestSize Tiger | |
Defined in Crypto.Hash.Tiger | |
type HashBlockSize Tiger | |
Defined in Crypto.Hash.Tiger |
SHA3 (224 bits) cryptographic hash algorithm
Constructors
SHA3_224 |
Instances
SHA3 (256 bits) cryptographic hash algorithm
Constructors
SHA3_256 |
Instances
SHA3 (384 bits) cryptographic hash algorithm
Constructors
SHA3_384 |
Instances
SHA3 (512 bits) cryptographic hash algorithm
Constructors
SHA3_512 |
Instances
data Skein256_224 #
Skein256 (224 bits) cryptographic hash algorithm
Constructors
Skein256_224 |
Instances
data Skein256_256 #
Skein256 (256 bits) cryptographic hash algorithm
Constructors
Skein256_256 |
Instances
data Skein512_224 #
Skein512 (224 bits) cryptographic hash algorithm
Constructors
Skein512_224 |
Instances
data Skein512_256 #
Skein512 (256 bits) cryptographic hash algorithm
Constructors
Skein512_256 |
Instances
data Skein512_384 #
Skein512 (384 bits) cryptographic hash algorithm
Constructors
Skein512_384 |
Instances
data Skein512_512 #
Skein512 (512 bits) cryptographic hash algorithm
Constructors
Skein512_512 |
Instances
Whirlpool cryptographic hash algorithm
Constructors
Whirlpool |
Instances
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