raaz-0.2.1: The raaz cryptographic library.

Safe Haskell | None
Language | Haskell2010

Raaz.Hash

Contents

- Cryptographic hashes and hmacs.
  - Encoding and displaying.
- Exposing individual hashes.

Description

This module exposes all the cryptographic hash functions available under the raaz library.

Synopsis

- 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.Blake2
- 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:

1. Distinct hashes are distinct types and hence it is a compiler error to compare two different hashes.
2. A hash and its associated hmac are distinct types and hence it is an compile time error to compare a hash with its hmac.
3. 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`

### NOTE: SHA1 is broken.

SHA1 is no more available form this module, its use is highly depreciated. If you want to use it for transition please import Raaz.Hash.Sha1 specifically

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

Minimal complete definition

additionalPadBlocks

Instances

Hash BLAKE2s Source # |
Instance details Defined in Raaz.Hash.Blake2.Internal Methods additionalPadBlocks :: BLAKE2s -> BLOCKS BLAKE2s Source #
Hash BLAKE2b Source # |
Instance details Defined in Raaz.Hash.Blake2.Internal Methods additionalPadBlocks :: BLAKE2b -> BLOCKS BLAKE2b Source #
Hash SHA1 Source # |
Instance details Defined in Raaz.Hash.Sha1.Internal Methods additionalPadBlocks :: SHA1 -> BLOCKS SHA1 Source #
Hash SHA224 Source # |
Instance details Defined in Raaz.Hash.Sha224.Internal Methods additionalPadBlocks :: SHA224 -> BLOCKS SHA224 Source #
Hash SHA256 Source # |
Instance details Defined in Raaz.Hash.Sha256.Internal Methods additionalPadBlocks :: SHA256 -> BLOCKS SHA256 Source #
Hash SHA384 Source # |
Instance details Defined in Raaz.Hash.Sha384.Internal Methods additionalPadBlocks :: SHA384 -> BLOCKS SHA384 Source #
Hash SHA512 Source # |
Instance details Defined in Raaz.Hash.Sha512.Internal Methods additionalPadBlocks :: SHA512 -> BLOCKS SHA512 Source #

hash Source #

Arguments

:: (Hash h, Recommendation h, PureByteSource src) |
=> src | Message
-> h |

Compute the hash of a pure byte source like, `ByteString`.

hashFile Source #

Arguments

:: (Hash h, Recommendation h) |
=> FilePath | File to be hashed
-> IO h |

Compute the hash of file.

hashSource Source #

Arguments

:: (Hash h, Recommendation h, ByteSource src) |
=> src | Message
-> IO h |

Compute the hash of a generic byte source.

data HMAC h 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.

Instances

Eq h => Eq (HMAC h) Source # |
Instance details Defined in Raaz.Hash.Internal.HMAC Methods (==) :: HMAC h -> HMAC h -> Bool Source # (/=) :: HMAC h -> HMAC h -> Bool Source #
Show h => Show (HMAC h) Source # |
Instance details Defined in Raaz.Hash.Internal.HMAC Methods showsPrec :: Int -> HMAC h -> ShowS Source # show :: HMAC h -> String Source # showList :: [HMAC h] -> ShowS Source #
IsString h => IsString (HMAC h) Source # |
Instance details Defined in Raaz.Hash.Internal.HMAC Methods fromString :: String -> HMAC h Source #
Storable h => Storable (HMAC h) Source # |

Instance details

Defined in Raaz.Hash.Internal.HMAC

Methods

sizeOf :: HMAC h -> Int Source #

alignment :: HMAC h -> Int Source #

peekElemOff :: Ptr (HMAC h) -> Int -> IO (HMAC h) Source #

pokeElemOff :: Ptr (HMAC h) -> Int -> HMAC h -> IO () Source #

peekByteOff :: Ptr b -> Int -> IO (HMAC h) Source #

pokeByteOff :: Ptr b -> Int -> HMAC h -> IO () Source #

peek :: Ptr (HMAC h) -> IO (HMAC h) Source #

poke :: Ptr (HMAC h) -> HMAC h -> IO () Source #

EndianStore h => EndianStore (HMAC h) Source # |
Instance details Defined in Raaz.Hash.Internal.HMAC Methods store :: Ptr (HMAC h) -> HMAC h -> IO () Source # load :: Ptr (HMAC h) -> IO (HMAC h) Source # adjustEndian :: Ptr (HMAC h) -> Int -> IO () Source #
Encodable h => Encodable (HMAC h) Source # |
Instance details Defined in Raaz.Hash.Internal.HMAC Methods toByteString :: HMAC h -> ByteString Source # fromByteString :: ByteString -> Maybe (HMAC h) Source # unsafeFromByteString :: ByteString -> HMAC h Source #
type Key (HMAC h) Source # |
Instance details Defined in Raaz.Hash.Internal.HMAC type Key (HMAC h)

hmac Source #

Arguments

:: (Hash h, Recommendation h, PureByteSource src) |
=> Key (HMAC h) |
-> src | Message
-> HMAC h |

Compute the hash of a pure byte source like, `ByteString`.

hmacFile Source #

Arguments

:: (Hash h, Recommendation h) |
=> Key (HMAC h) | Key to use for mac-ing
-> FilePath | File to be hashed
-> IO (HMAC h) |

Compute the hmac of file.

hmacSource Source #

Arguments

:: (Hash h, Recommendation h, ByteSource src) |
=> Key (HMAC h) | key to use for mac-ing.
-> src | Message
-> IO (HMAC h) |

Compute the hmac 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.Blake2

module Raaz.Hash.Sha224

module Raaz.Hash.Sha256

module Raaz.Hash.Sha384

module Raaz.Hash.Sha512