crypto::mac
mac provides a generic interface for use with message authentication code (MAC)
functions.
Index
Types
type mac;
Functions
fn bsz(*mac) size;
fn finish(*mac) void;
fn sum(*mac, []u8) void;
fn sz(*mac) size;
fn write(*mac, const []u8) size;
Types
type mac
type mac = struct {
stream: io::stream,
sum: nullable *fn(mac: *mac, buf: []u8) void,
finish: *fn(mac: *mac) void,
sz: size,
bsz: size,
};
The general purpose interface for a MAC function.
Functions
fn bsz
fn bsz(m: *mac) size;
Returns the block size of the MAC in bytes.
fn finish
fn finish(m: *mac) void;
Finalizes the MAC function, securely discarding any sensitive state, and
freeing any associated resources.
fn sum
fn sum(m: *mac, buf: []u8) void;
Computes the final MAC and writes it to 'buf', which must be at least sz
bytes. Generally, each MAC implementation provides a constant which is equal
to the length, so you may not have to dynamically allocate this buffer.
This function may only be called once for any given mac object; calling
it more than once will cause a runtime assertion to fail.
After calling sum, you must call finish to securely erase sensitive
information stored in the MAC function state.
fn sz
fn sz(m: *mac) size;
Returns the size of the MAC in bytes. This is consistent regardless
of the MAC state.
fn write
fn write(m: *mac, buf: const []u8) size;
Writes an input to the MAC function.