crypto::mac +linux +x86_64

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[link]

type mac = struct {
	// A stream which only supports writes and never returns errors.
stream: io::stream, // Writes the resulting MAC to 'buf'. Must only be called once, and must
// be followed by calling [[finish]].
sum: nullable *fn(mac: *mac, buf: []u8) void, // Finalizes the MAC function, securely discards all state and frees
// all resources used by the MAC.
finish: *fn(mac: *mac) void, // Size of the MAC in bytes.
sz: size, // Internal block size of the MAC in bytes.
bsz: size, };

The general purpose interface for a MAC function.

Functions

fn bsz[link]

fn bsz(m: *mac) size;

Returns the block size of the MAC in bytes.

fn finish[link]

fn finish(m: *mac) void;

Finalizes the MAC function, securely discarding any sensitive state, and freeing any associated resources.

fn sum[link]

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[link]

fn sz(m: *mac) size;

Returns the size of the MAC in bytes. This is consistent regardless of the MAC state.

fn write[link]

fn write(m: *mac, buf: const []u8) size;

Writes an input to the MAC function.