Cmac
Mojo struct 🡭
Cmac
@memory_only
struct Cmac[Cipher: BlockCipherEncryptable & Copyable & Deinitable]CMAC (OMAC1): a cipher-based message authentication code.
CMAC turns any block cipher into a MAC by chaining input blocks through the cipher like CBC-MAC, then masking the final block with one of two subkeys derived from the cipher itself. The subkey mask is what closes CBC-MAC’s classic forgery on variable-length messages.
NIST SP 800-38B: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38b.pdf RFC 4493 (AES-CMAC): https://www.rfc-editor.org/rfc/rfc4493
Aliases
BLOCK_SIZE = Cipher.BLOCK_SIZETAG_SIZE = Cmac[Cipher].BLOCK_SIZE
Parameters
- Cipher (
BlockCipherEncryptable & Copyable & Deinitable)
Implemented traits
AnyType, Copyable, Deinitable, Mac, Movable
Methods
__init__
fn def __init__(out self, var cipher: Cipher)Initialize CMAC from an already-keyed block cipher.
Args:
- cipher (
Cipher) - self (
Self)
Returns:
Self
update
fn def update[o: Origin[mut=o.mut]](mut self, data: Span[UInt8, o])Absorb more input.
Parameters:
- o (
Origin[mut=mut])
Args:
- self (
Self) - data (
Span[UInt8, o])
Raises:
finalize
fn def finalize(var self) -> Array[UInt8, Cipher.BLOCK_SIZE]Consume self and return the TAG_SIZE-byte authentication tag.
Derives K1 (and K2, if the buffered final block turned out to be partial) per NIST SP 800-38B’s subkey generation algorithm, masks the buffered final block with it, and runs one more cipher block to produce the tag.
Args:
- self (
Self)
Returns:
Array[UInt8, Cipher.BLOCK_SIZE]
Raises:
reset
fn def reset(mut self)Reset the accumulator to its initial state while keeping the key.
Args:
- self (
Self)