Crypto.Nettle.HMAC

nettle-0.2.0: safe nettle binding

Copyright | (c) 2013 Stefan Bühler
License | MIT-style (see the file COPYING)
Maintainer | stbuehler@web.de
Stability | experimental
Portability | portable
Safe Haskell | Safe
Language | Haskell98

Crypto.Nettle.HMAC

Description

Generic HMAC implementation based on the `HashAlgorithm` class, implementing the `KeyedHashAlgorithm` class.

Synopsis

- data HMAC a
- hmacInit :: HashAlgorithm a => ByteString -> Tagged a KeyedHash
- hmacInit' :: HashAlgorithm a => a -> ByteString -> KeyedHash
- hmac :: HashAlgorithm a => ByteString -> ByteString -> Tagged a ByteString
- hmac' :: HashAlgorithm a => a -> ByteString -> ByteString -> ByteString
- hmacLazy :: HashAlgorithm a => ByteString -> ByteString -> Tagged a ByteString
- hmacLazy' :: HashAlgorithm a => a -> ByteString -> ByteString -> ByteString

# Documentation

data HMAC a #

`HMAC` is a generic `KeyedHashAlgorithm` instance to calculate the `HMAC` based on a `HashAlgorithm`

Instances

HashAlgorithm a => KeyedHashAlgorithm (HMAC a) # |
Methods implKeyedHashDigestSize :: Tagged * (HMAC a) Int # implKeyedHashName :: Tagged * (HMAC a) String # implKeyedHashInit :: ByteString -> HMAC a # implKeyedHashUpdate :: HMAC a -> ByteString -> HMAC a # implKeyedHashUpdateLazy :: HMAC a -> ByteString -> HMAC a # implKeyedHashFinalize :: HMAC a -> ByteString #

hmacInit #

Arguments

:: HashAlgorithm a |
=> ByteString | `key` argument
-> Tagged a KeyedHash |

`hmacInit` is the default implementation for `hashHMAC` and initializes a `KeyedHash` to calculate the HMAC for a message with the given `key`.

Example:

    let c = untag (hmacInit (fromString "secretkey") :: Tagged SHA256 KeyedHash) in keyedHashFinalize $ keyedHashUpdate c (fromString "secret message")

hmacInit' :: HashAlgorithm a => a -> ByteString -> KeyedHash #

Untagged variant of `hmacInit`; takes a (possible `undefined`) typed `HashAlgorithm` context as parameter.

Example:

    keyedHashFinalize $ flip keyedHashUpdate (fromString "secret message") $ hmacInit' (undefined :: SHA256) (fromString "secretkey")

hmac #

Arguments

:: HashAlgorithm a |
=> ByteString | `key` argument
-> ByteString | `message` argument
-> Tagged a ByteString |

calculate HMAC with a `HashAlgorithm` for a `key` and `message`

Example:

    untag (hmac (fromString "secretkey") (fromString "secret message") :: Tagged SHA256 B.ByteString)

hmac' :: HashAlgorithm a => a -> ByteString -> ByteString -> ByteString #

Untagged variant of `hmac`; takes a (possible `undefined`) typed `HashAlgorithm` context as parameter.

Example:

    hmac' (undefined :: SHA256) (fromString "secretkey") (fromString "secret message")

hmacLazy #

Arguments

:: HashAlgorithm a |
=> ByteString | `key` argument
-> ByteString | `message` argument
-> Tagged a ByteString |

calculate HMAC with a `HashAlgorithm` for a `key` and lazy `message`

Example:

    untag (hmacLazy (fromString "secretkey") (fromString "secret message") :: Tagged SHA256 B.ByteString)

hmacLazy' :: HashAlgorithm a => a -> ByteString -> ByteString -> ByteString #

Untagged variant of `hmacLazy`; takes a (possible `undefined`) typed `HashAlgorithm` context as parameter.

Example:

    hmacLazy' (undefined :: SHA256) (fromString "secretkey") (fromString "secret message")