raaz-0.2.3: The raaz cryptographic library.
Safe HaskellNone
LanguageHaskell2010

Raaz.Hash

Description

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

Synopsis

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

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

Instances details
Eq h => Eq (HMAC h) Source # 
Instance details

Defined in Raaz.Hash.Internal.HMAC

Methods

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

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

Show h => Show (HMAC h) Source # 
Instance details

Defined in Raaz.Hash.Internal.HMAC

Methods

showsPrec :: Int -> HMAC h -> ShowS #

show :: HMAC h -> String #

showList :: [HMAC h] -> ShowS #

IsString h => IsString (HMAC h) Source # 
Instance details

Defined in Raaz.Hash.Internal.HMAC

Methods

fromString :: String -> HMAC h #

Storable h => Storable (HMAC h) Source # 
Instance details

Defined in Raaz.Hash.Internal.HMAC

Methods

sizeOf :: HMAC h -> Int #

alignment :: HMAC h -> Int #

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

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

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

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

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

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

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

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