Hmac<D> structv0.1.0

Source
An incremental HMAC over any digest.
pub struct Hmac<D: Digest> {
    // private fields
}

prototype supplies both the algorithm and its parameters; it is copied rather than consumed, so one prototype can start any number of authentications. Structural Copy whenever D is copyable; copying snapshots both digest states independently.

Type parameters

NameDescription
D: Digestthe digest type

Constructors

Hmac

pub func Hmac(prototype: D, key: char8[..]) -> Hmac<D>

An HMAC keyed with key. A key longer than the digest's block is replaced by its own digest, which is what the specification says and is worth knowing: two keys differing only past the block length authenticate identically, because they are the same key after this step. A shorter key is padded with zeros.

NameTypeDescription
prototypeDany value of the digest type, read only to select it
keychar8[..]the key

Returns: an authenticator keyed with those bytes

Source

Methods

Update

pub func Update<D: Digest>(
    self: &var Hmac<D>,
    bytes: char8[..]
)

Adds bytes to the message being authenticated.

Type parameterDescription
D: Digestthe digest type
NameTypeDescription
byteschar8[..]the bytes to absorb

Source

Finish

pub func Finish<D: Digest>(
    self: &var Hmac<D>,
    into: var char8[..]
)

Writes the authentication tag into into.

Type parameterDescription
D: Digestthe digest type
NameTypeDescription
intovar char8[..]receives the output

Source

TagLength

pub func TagLength<D: Digest>(self: &Hmac<D>) -> uint

How many bytes Finish writes: the underlying digest's length.

Type parameterDescription
D: Digestthe digest type

Returns: how many bytes a tag occupies, which is the digest's length

Source

HmacMaximumBlock

pub const HmacMaximumBlock: uint = 168;

The longest block any supported digest uses, which is what the padded key buffers are sized to. SHAKE128's rate is the largest at a hundred and sixty eight bytes; SHA-512's block is a hundred and twenty eight and SHA-256's sixty four. The buffers below are written as that literal because an array length must be a compile-time integer and a constant does not satisfy that yet.

Source

HmacOf<D>

pub func HmacOf<D: Digest>(
    prototype: D,
    key: char8[..],
    message: char8[..],
    into: var char8[..]
)

The HMAC of message under key, in one call.

Source

Type parameters

NameDescription
D: Digestthe digest type

Parameters

NameTypeDescription
prototypeDany value of the digest type, read only to select it
keychar8[..]the key
messagechar8[..]the message to authenticate
intovar char8[..]receives the output