raaz-0.0.1: The raaz cryptographic library.

Safe HaskellNone
LanguageHaskell98

Raaz.Hash

Contents

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

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.

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 # 

Methods

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

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

Show h => Show (HMAC h) Source # 

Methods

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

show :: HMAC h -> String #

showList :: [HMAC h] -> ShowS #

IsString h => IsString (HMAC h) Source # 

Methods

fromString :: String -> HMAC h #

Storable h => Storable (HMAC h) Source # 

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 # 

Methods

store :: Pointer -> HMAC h -> IO () Source #

load :: Pointer -> IO (HMAC h) Source #

Encodable h => Encodable (HMAC h) Source # 
Hash h => Symmetric (HMAC h) Source # 

Associated Types

type Key (HMAC h) :: * Source #

(Hash h, Recommendation h) => Recommendation (HMAC h) Source # 
Hash h => Primitive (HMAC h) Source # 

Associated Types

type Implementation (HMAC h) :: * Source #

Methods

blockSize :: HMAC h -> BYTES Int Source #

type Key (HMAC h) Source # 
type Key (HMAC h)
type Implementation (HMAC h) Source # 

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

File to be hashed

-> IO (HMAC h) 

Compute the hash of file.

hmacSource Source #

Arguments

:: (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