Hmac<D> structv0.1.0
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
| Name | Description |
|---|---|
D: Digest | the 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.
| Name | Type | Description |
|---|---|---|
prototype | D | any value of the digest type, read only to select it |
key | char8[..] | the key |
Returns: an authenticator keyed with those bytes
Methods
Update
pub func Update<D: Digest>(
self: &var Hmac<D>,
bytes: char8[..]
)
Adds bytes to the message being authenticated.
| Type parameter | Description |
|---|---|
D: Digest | the digest type |
| Name | Type | Description |
|---|---|---|
bytes | char8[..] | the bytes to absorb |
Finish
pub func Finish<D: Digest>(
self: &var Hmac<D>,
into: var char8[..]
)
Writes the authentication tag into into.
| Type parameter | Description |
|---|---|
D: Digest | the digest type |
| Name | Type | Description |
|---|---|---|
into | var char8[..] | receives the output |
TagLength
pub func TagLength<D: Digest>(self: &Hmac<D>) -> uint
How many bytes Finish writes: the underlying digest's length.
| Type parameter | Description |
|---|---|
D: Digest | the digest type |
Returns: how many bytes a tag occupies, which is the digest's length
Related
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.
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.
Type parameters
| Name | Description |
|---|---|
D: Digest | the digest type |
Parameters
| Name | Type | Description |
|---|---|---|
prototype | D | any value of the digest type, read only to select it |
key | char8[..] | the key |
message | char8[..] | the message to authenticate |
into | var char8[..] | receives the output |