Crypto.Nettle.KeyedHash

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

Description

Generic interface to calculate key based hashes.

Synopsis

- class KeyedHashAlgorithm k where
- data KeyedHash = 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 #

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

Digest size in bytes the keyed hash algorithm returns

implKeyedHashName :: Tagged k String #

Name

implKeyedHashInit :: ByteString -> k #

Initialize state from a key

implKeyedHashUpdate :: k -> ByteString -> k #

Add more message data to the state

implKeyedHashUpdateLazy :: k -> ByteString -> k #

Add more lazy message data to the state

implKeyedHashFinalize :: k -> ByteString #

Produce final digest

Instances

KeyedHashAlgorithm UMAC128 # |
Methods implKeyedHashDigestSize :: Tagged * UMAC128 Int # implKeyedHashName :: Tagged * UMAC128 String # implKeyedHashInit :: ByteString -> UMAC128 # implKeyedHashUpdate :: UMAC128 -> ByteString -> UMAC128 # implKeyedHashUpdateLazy :: UMAC128 -> ByteString -> UMAC128 # implKeyedHashFinalize :: UMAC128 -> ByteString #
KeyedHashAlgorithm UMAC96 # |
Methods implKeyedHashDigestSize :: Tagged * UMAC96 Int # implKeyedHashName :: Tagged * UMAC96 String # implKeyedHashInit :: ByteString -> UMAC96 # implKeyedHashUpdate :: UMAC96 -> ByteString -> UMAC96 # implKeyedHashUpdateLazy :: UMAC96 -> ByteString -> UMAC96 # implKeyedHashFinalize :: UMAC96 -> ByteString #
KeyedHashAlgorithm UMAC64 # |
Methods implKeyedHashDigestSize :: Tagged * UMAC64 Int # implKeyedHashName :: Tagged * UMAC64 String # implKeyedHashInit :: ByteString -> UMAC64 # implKeyedHashUpdate :: UMAC64 -> ByteString -> UMAC64 # implKeyedHashUpdateLazy :: UMAC64 -> ByteString -> UMAC64 # implKeyedHashFinalize :: UMAC64 -> ByteString #
KeyedHashAlgorithm UMAC32 # |
Methods implKeyedHashDigestSize :: Tagged * UMAC32 Int # implKeyedHashName :: Tagged * UMAC32 String # implKeyedHashInit :: ByteString -> UMAC32 # implKeyedHashUpdate :: UMAC32 -> ByteString -> UMAC32 # implKeyedHashUpdateLazy :: UMAC32 -> ByteString -> UMAC32 # implKeyedHashFinalize :: UMAC32 -> ByteString #
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 #

data KeyedHash #

`KeyedHash` hides the `KeyedHashAlgorithm` implementation.

Constructors

KeyedHashAlgorithm k => KeyedHash !k |

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

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

keyedHashDigestSize' :: KeyedHash -> Int #

Get `implKeyedHashDigestSize` from a `KeyedHash`

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

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

keyedHashName' :: KeyedHash -> String #

Get `implKeyedHashName` from a `KeyedHash`

keyedHashInit #

Arguments

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

Initialize a `KeyedHash` context from a `key`

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

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

keyedHashUpdate :: KeyedHash -> ByteString -> KeyedHash #

Add more message data to the context

keyedHashUpdateLazy :: KeyedHash -> ByteString -> KeyedHash #

Add more lazy message data to the context

keyedHashFinalize :: KeyedHash -> ByteString #

Produce final digest

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

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 #

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 #

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 #

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