Crypto.Nettle.UMAC

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 | None
Language | Haskell98

Crypto.Nettle.UMAC

Description

This module exports the UMAC algorithms supported by nettle: http://www.lysator.liu.se/~nisse/nettle/

Synopsis

- class UMAC u where
- data UMAC32
- data UMAC64
- data UMAC96
- data UMAC128
- umacInitKeyedHash :: (UMAC u, KeyedHashAlgorithm u) => ByteString -> ByteString -> Tagged u KeyedHash

# Documentation

class UMAC u where #

`UMAC` is a class of keyed hash algorithms that take an additional nonce.

Keys for `UMAC` are always 16 bytes; there are different digest sizes: 4, 8, 12 and 16 bytes (32, 64, 96 and 128 bits), and the variants are named after the digest length in bits.

On initialization the nonce is set to 0; each finalize returns a new state with an incremented nonce. The nonce is interpreted as 16-byte (128-bit) big-endian integer (and for string shorter than 16 bytes padded with zeroes on the left; setting empty nonces is not allowed).

Minimal complete definition

umacDigestSize, umacInit, umacSetNonce, umacUpdate, umacFinalize

Methods

umacDigestSize :: Tagged u Int #

digest size in bytes

umacName :: Tagged u String #

umac name (UMAC ++ digest size in bits)

umacInit :: ByteString -> u #

initialize a new context from a `key` with a zero `nonce`

umacSetNonce :: u -> ByteString -> u #

set a `nonce`; can be called anytime before producing the digest

umacUpdate :: u -> ByteString -> u #

append `message` data to be hashed

umacUpdateLazy :: u -> ByteString -> u #

append lazy `message` data to be hashed

umacFinalize :: u -> (ByteString, u) #

produce a digest, and return a new state with incremented nonce

Instances

UMAC UMAC128 # |
Methods umacDigestSize :: Tagged * UMAC128 Int # umacName :: Tagged * UMAC128 String # umacInit :: ByteString -> UMAC128 # umacSetNonce :: UMAC128 -> ByteString -> UMAC128 # umacUpdate :: UMAC128 -> ByteString -> UMAC128 # umacUpdateLazy :: UMAC128 -> ByteString -> UMAC128 # umacFinalize :: UMAC128 -> (ByteString, UMAC128) #
UMAC UMAC96 # |
Methods umacDigestSize :: Tagged * UMAC96 Int # umacName :: Tagged * UMAC96 String # umacInit :: ByteString -> UMAC96 # umacSetNonce :: UMAC96 -> ByteString -> UMAC96 # umacUpdate :: UMAC96 -> ByteString -> UMAC96 # umacUpdateLazy :: UMAC96 -> ByteString -> UMAC96 # umacFinalize :: UMAC96 -> (ByteString, UMAC96) #
UMAC UMAC64 # |
Methods umacDigestSize :: Tagged * UMAC64 Int # umacName :: Tagged * UMAC64 String # umacInit :: ByteString -> UMAC64 # umacSetNonce :: UMAC64 -> ByteString -> UMAC64 # umacUpdate :: UMAC64 -> ByteString -> UMAC64 # umacUpdateLazy :: UMAC64 -> ByteString -> UMAC64 # umacFinalize :: UMAC64 -> (ByteString, UMAC64) #
UMAC UMAC32 # |
Methods umacDigestSize :: Tagged * UMAC32 Int # umacName :: Tagged * UMAC32 String # umacInit :: ByteString -> UMAC32 # umacSetNonce :: UMAC32 -> ByteString -> UMAC32 # umacUpdate :: UMAC32 -> ByteString -> UMAC32 # umacUpdateLazy :: UMAC32 -> ByteString -> UMAC32 # umacFinalize :: UMAC32 -> (ByteString, UMAC32) #

data UMAC32 #

`UMAC32` is the 32-bit (4 byte) digest variant. See `umacInitKeyedHash` for the `KeyedHashAlgorithm` instance.

Instances

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 #
UMAC UMAC32 # |
Methods umacDigestSize :: Tagged * UMAC32 Int # umacName :: Tagged * UMAC32 String # umacInit :: ByteString -> UMAC32 # umacSetNonce :: UMAC32 -> ByteString -> UMAC32 # umacUpdate :: UMAC32 -> ByteString -> UMAC32 # umacUpdateLazy :: UMAC32 -> ByteString -> UMAC32 # umacFinalize :: UMAC32 -> (ByteString, UMAC32) #

data UMAC64 #

`UMAC64` is the 32-bit (4 byte) digest variant. See `umacInitKeyedHash` for the `KeyedHashAlgorithm` instance.

Instances

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 #
UMAC UMAC64 # |
Methods umacDigestSize :: Tagged * UMAC64 Int # umacName :: Tagged * UMAC64 String # umacInit :: ByteString -> UMAC64 # umacSetNonce :: UMAC64 -> ByteString -> UMAC64 # umacUpdate :: UMAC64 -> ByteString -> UMAC64 # umacUpdateLazy :: UMAC64 -> ByteString -> UMAC64 # umacFinalize :: UMAC64 -> (ByteString, UMAC64) #

data UMAC96 #

`UMAC96` is the 32-bit (4 byte) digest variant. See `umacInitKeyedHash` for the `KeyedHashAlgorithm` instance.

Instances

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 #
UMAC UMAC96 # |
Methods umacDigestSize :: Tagged * UMAC96 Int # umacName :: Tagged * UMAC96 String # umacInit :: ByteString -> UMAC96 # umacSetNonce :: UMAC96 -> ByteString -> UMAC96 # umacUpdate :: UMAC96 -> ByteString -> UMAC96 # umacUpdateLazy :: UMAC96 -> ByteString -> UMAC96 # umacFinalize :: UMAC96 -> (ByteString, UMAC96) #

data UMAC128 #

`UMAC128` is the 32-bit (4 byte) digest variant. See `umacInitKeyedHash` for the `KeyedHashAlgorithm` instance.

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 #
UMAC UMAC128 # |
Methods umacDigestSize :: Tagged * UMAC128 Int # umacName :: Tagged * UMAC128 String # umacInit :: ByteString -> UMAC128 # umacSetNonce :: UMAC128 -> ByteString -> UMAC128 # umacUpdate :: UMAC128 -> ByteString -> UMAC128 # umacUpdateLazy :: UMAC128 -> ByteString -> UMAC128 # umacFinalize :: UMAC128 -> (ByteString, UMAC128) #

umacInitKeyedHash #

Arguments

:: (UMAC u, KeyedHashAlgorithm u) |
=> ByteString | `key` argument
-> ByteString | `nonce` argument
-> Tagged u KeyedHash |

The default `KeyedHash` generated for UMAC `KeyedHashAlgorithm` instances use a zero nonce; to set a different nonce you need to use this initialization function (or use the `UMAC` interface).

Once the UMAC lives as `KeyedHash` the nonce cannot be changed anymore, as `KeyedHash` hides all internal state.