nettle-0.1.1: 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.KeyedHash

Description

Generic interface to calculate key based hashes.

Synopsis

- class KeyedHashAlgorithm k where
  - implKeyedHashDigestSize :: Tagged k Int
  - implKeyedHashName :: Tagged k String
  - implKeyedHashInit :: ByteString -> k
  - implKeyedHashUpdate :: k -> ByteString -> k
  - implKeyedHashUpdateLazy :: k -> ByteString -> k
  - implKeyedHashFinalize :: k -> ByteString
- data KeyedHash = forall k . KeyedHashAlgorithm k => KeyedHash !k
- keyedHashDigestSize :: KeyedHashAlgorithm k => k -> Int
- keyedHashDigestSize' :: KeyedHash -> Int
- keyedHashName :: KeyedHashAlgorithm k => k -> String
- keyedHashName' :: KeyedHash -> String
- keyedHashInit :: KeyedHashAlgorithm k => ByteString -> Tagged k KeyedHash
- keyedHashInit' :: KeyedHashAlgorithm k => k -> ByteString -> KeyedHash
- keyedHashUpdate :: KeyedHash -> ByteString -> KeyedHash
- keyedHashUpdateLazy :: KeyedHash -> ByteString -> KeyedHash
- keyedHashFinalize :: KeyedHash -> ByteString
- keyedHash :: KeyedHashAlgorithm k => ByteString -> ByteString -> Tagged k ByteString
- keyedHash' :: KeyedHashAlgorithm k => k -> ByteString -> ByteString -> ByteString
- keyedHashLazy :: KeyedHashAlgorithm k => ByteString -> ByteString -> Tagged k ByteString
- keyedHashLazy' :: KeyedHashAlgorithm k => k -> ByteString -> ByteString -> ByteString

# Documentation

class KeyedHashAlgorithm k where Source

`KeyedHashAlgorithm` is a class for keyed hash algorithms that take a key and a message to produce a digest. The most popular example is `HMAC`.

Minimal complete definition

implKeyedHashDigestSize, implKeyedHashName, implKeyedHashInit, implKeyedHashUpdate, implKeyedHashFinalize

Methods

implKeyedHashDigestSize :: Tagged k Int Source

Digest size in bytes the keyed hash algorithm returns

implKeyedHashName :: Tagged k String Source

Name

implKeyedHashInit :: ByteString -> k Source

Initialize state from a key

implKeyedHashUpdate :: k -> ByteString -> k Source

Add more message data to the state

implKeyedHashUpdateLazy :: k -> ByteString -> k Source

Add more lazy message data to the state

implKeyedHashFinalize :: k -> ByteString Source

Produce final digest

Instances

KeyedHashAlgorithm UMAC128 Source |
KeyedHashAlgorithm UMAC96 Source |
KeyedHashAlgorithm UMAC64 Source |
KeyedHashAlgorithm UMAC32 Source |
HashAlgorithm a => KeyedHashAlgorithm (HMAC a) Source |

data KeyedHash Source

`KeyedHash` hides the `KeyedHashAlgorithm` implementation.

Constructors

forall k . KeyedHashAlgorithm k => KeyedHash !k |

keyedHashDigestSize :: KeyedHashAlgorithm k => k -> Int Source

Untagged variant of `implKeyedHashDigestSize`; takes a (possible `undefined`) key typed value from a `KeyedHashAlgorithm` instance as parameter.

keyedHashDigestSize' :: KeyedHash -> Int Source

Get `implKeyedHashDigestSize` from a `KeyedHash`

keyedHashName :: KeyedHashAlgorithm k => k -> String Source

Untagged variant of `implKeyedHashName`; takes a (possible `undefined`) key typed value from a `KeyedHashAlgorithm` instance as parameter.

keyedHashName' :: KeyedHash -> String Source

Get `implKeyedHashName` from a `KeyedHash`

keyedHashInit Source

Arguments

:: KeyedHashAlgorithm k |
=> ByteString | `key` argument
-> Tagged k KeyedHash |

Initialize a `KeyedHash` context from a `key`

keyedHashInit' :: KeyedHashAlgorithm k => k -> ByteString -> KeyedHash Source

Untagged variant of `keyedHashInit`; takes a (possible `undefined`) key typed value from a `KeyedHashAlgorithm` instance as parameter.

keyedHashUpdate :: KeyedHash -> ByteString -> KeyedHash Source

Add more message data to the context

keyedHashUpdateLazy :: KeyedHash -> ByteString -> KeyedHash Source

Add more lazy message data to the context

keyedHashFinalize :: KeyedHash -> ByteString Source

Produce final digest

keyedHash :: KeyedHashAlgorithm k => ByteString -> ByteString -> Tagged k ByteString Source

Helper to hash `key` and `message` in one step

Example:

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

keyedHash' :: KeyedHashAlgorithm k => k -> ByteString -> ByteString -> ByteString Source

Untagged variant of `keyedHash`; takes a (possible `undefined`) key typed value from a `KeyedHashAlgorithm` instance as parameter.

Example:

    keyedHash' (undefined :: HMAC SHA256) (fromString "secretkey") (fromString "secret message")

keyedHashLazy :: KeyedHashAlgorithm k => ByteString -> ByteString -> Tagged k ByteString Source

Helper to hash `key` and lazy `message` in one step

Example:

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

keyedHashLazy' :: KeyedHashAlgorithm k => k -> ByteString -> ByteString -> ByteString Source

Untagged variant of `keyedHashLazy`; takes a (possible `undefined`) key typed value from a `KeyedHashAlgorithm` instance as parameter.

Example:

    keyedHashLazy' (undefined :: HMAC SHA256) (fromString "secretkey") (fromString "secret message")