Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module exposes all the cryptographic hash functions available under the raaz library.
- class (Primitive h, EndianStore h, Encodable h, Eq h, Implementation h ~ SomeHashI h) => Hash h
- hash :: (Hash h, Recommendation h, PureByteSource src) => src -> h
- hashFile :: (Hash h, Recommendation h) => FilePath -> IO h
- hashSource :: (Hash h, Recommendation h, ByteSource src) => src -> IO h
- data HMAC h
- hmac :: (Hash h, Recommendation h, PureByteSource src) => Key (HMAC h) -> src -> HMAC h
- hmacFile :: (Hash h, Recommendation h) => Key (HMAC h) -> FilePath -> IO (HMAC h)
- hmacSource :: (Hash h, Recommendation h, ByteSource src) => Key (HMAC h) -> src -> IO (HMAC h)
- module Raaz.Hash.Sha1
- module Raaz.Hash.Sha224
- module Raaz.Hash.Sha256
- module Raaz.Hash.Sha384
- module Raaz.Hash.Sha512
Cryptographic hashes and hmacs.
The cryptographic hashes provided by raaz give the following guarantees:
- Distinct hashes are distinct types and hence it is a compiler error to compare two different hashes.
- A hash and its associated hmac are distinct types and hence it is an compile time error to compare a hash with its hmac.
- The
Eq
instance for hashes and the corresponding hmacs use a constant time equality test and hence it is safe to check equality using the operator==
.
The functions hash
, hashFile
, and hashSource
provide a rather
high level interface for computing hashes. For hmacs the associated
functions are hmac
, hmacFile
, and hmacSource
Encoding and displaying.
When interfacing with other applications or when printing output to
users, it is often necessary to encode hash, hmac or their keys as
strings. Applications usually present hashes encoded in base16. The
Show
and IsString
instances for the hashes exposed
here follow this convention.
More generaly, hashes, hmacs and their key are instances of type
class Encodable
and can hence can be encoded in
any of the formats supported in raaz.
class (Primitive h, EndianStore h, Encodable h, Eq h, Implementation h ~ SomeHashI h) => Hash h Source #
Type class capturing a cryptographic hash.
:: (Hash h, Recommendation h, PureByteSource src) | |
=> src | Message |
-> h |
Compute the hash of a pure byte source like, ByteString
.
:: (Hash h, Recommendation h) | |
=> FilePath | File to be hashed |
-> IO h |
Compute the hash of file.
:: (Hash h, Recommendation h, ByteSource src) | |
=> src | Message |
-> IO h |
Compute the hash of a generic byte source.
The HMAC associated to a hash value. The HMAC type is essentially
the underlying hash type wrapped inside a newtype. Therefore, the
Eq
instance for HMAC is essentially the Eq
instance for the
underlying hash. It is safe against timing attack provided the
underlying hash comparison is safe under timing attack.
:: (Hash h, Recommendation h, PureByteSource src) | |
=> Key (HMAC h) | |
-> src | Message |
-> HMAC h |
Compute the hash of a pure byte source like, ByteString
.
Compute the hash of file.
:: (Hash h, Recommendation h, ByteSource src) | |
=> Key (HMAC h) | |
-> src | Message |
-> IO (HMAC h) |
Compute the hash of a generic byte source.
Exposing individual hashes.
Individual hash and hmacs are exposed via their respective modules.
These module also export the specialized variants for hashSource
,
hash
and hashFile
for specific hashes. For example, if you are
interested only in say SHA512
you can import the module
Raaz.Hash.Sha512. This will expose the functions sha512Source
,
sha512
and sha512File
which are specialized variants of
hashSource
hash
and hashFile
respectively for the hash
SHA512
. For example, if you want to print the sha512 checksum of
a file, you can use the following.
sha512Checksum :: FilePath -> IO () -- print the sha512 checksum of a given file. sha512Checksum fname = sha512File fname >>= print
module Raaz.Hash.Sha1
module Raaz.Hash.Sha224
module Raaz.Hash.Sha256
module Raaz.Hash.Sha384
module Raaz.Hash.Sha512