UniversalHashable

UniversalHashable

Mojo trait 🡭

UniversalHashable

Aliases

  • BLOCK_SIZE =
  • KEY_SIZE =
  • TAG_SIZE =

Implemented traits

AnyType

Methods

__init__

fn def __init__(out self, var h: Array[UInt8, _Self.KEY_SIZE])

Initialize the hash from a KEY_SIZE-byte key.

Args:

  • h (Array[UInt8, _Self.KEY_SIZE])
  • self (Self)

Returns:

_Self

update_block

fn def update_block(mut self, var block: Array[UInt8, _Self.BLOCK_SIZE])

Absorb a single BLOCK_SIZE block.

Args:

  • self (Self)
  • block (Array[UInt8, _Self.BLOCK_SIZE])

update

fn def update[o: Origin[mut=o.mut]](mut self, data: Span[UInt8, o])

Absorb whole BLOCK_SIZE-aligned input.

Raises UhashSizeError if len(data) is not a multiple of BLOCK_SIZE — padding is the caller’s job.

Parameters:

  • o (Origin[mut=mut])

Args:

  • self (Self)
  • data (Span[UInt8, o])

Raises:

update_padded

fn def update_padded[o: Origin[mut=o.mut]](mut self, data: Span[UInt8, o])

Absorb input of any length, zero-padding the final partial block if needed.

Full blocks are passed directly to update_block; if the input length is not a multiple of BLOCK_SIZE the remaining bytes are copied into a zero-filled block before being absorbed. Frequently used by AEAD modes whose MACs are based on universal hashing (e.g. AES-GCM, AES-GCM-SIV).

Parameters:

  • o (Origin[mut=mut])

Args:

  • self (Self)
  • data (Span[UInt8, o])

Raises:

finalize

fn def finalize(var self) -> Array[UInt8, _Self.TAG_SIZE]

Consume self and return the TAG_SIZE-byte authentication tag.

Args:

  • self (Self)

Returns:

Array[UInt8, _Self.TAG_SIZE]

reset

fn def reset(mut self)

Reset the accumulator to its initial state while keeping the key.

Args:

  • self (Self)