Skip to main content

Mac

Trait Mac 

Source
pub trait Mac: Sized {
    type Key: AsRef<[u8]> + AsMut<[u8]> + Clone + Zeroize;
    type Tag: AsRef<[u8]> + AsMut<[u8]> + Clone;

    // Required methods
    fn new(key: &[u8]) -> Result<Self>;
    fn update(&mut self, data: &[u8]) -> Result<&mut Self>;
    fn finalize(&mut self) -> Result<Self::Tag>;
    fn reset(&mut self) -> Result<()>;

    // Provided methods
    fn compute_tag(key: &[u8], data: &[u8]) -> Result<Self::Tag> { ... }
    fn verify_tag(key: &[u8], data: &[u8], tag: &[u8]) -> Result<bool> { ... }
}
Expand description

Trait for Message Authentication Code (MAC) algorithms

Required Associated Types§

Source

type Key: AsRef<[u8]> + AsMut<[u8]> + Clone + Zeroize

Key type with appropriate algorithm binding

Source

type Tag: AsRef<[u8]> + AsMut<[u8]> + Clone

Tag output type with appropriate size constraint

Required Methods§

Source

fn new(key: &[u8]) -> Result<Self>

Creates a new MAC instance with the given key

Source

fn update(&mut self, data: &[u8]) -> Result<&mut Self>

Updates the MAC state with data, returning self for method chaining

Source

fn finalize(&mut self) -> Result<Self::Tag>

Finalizes and returns the MAC tag

Source

fn reset(&mut self) -> Result<()>

Reset the MAC state for reuse

Provided Methods§

Source

fn compute_tag(key: &[u8], data: &[u8]) -> Result<Self::Tag>

One-shot MAC computation

Source

fn verify_tag(key: &[u8], data: &[u8], tag: &[u8]) -> Result<bool>

Verify a MAC tag with equal-length byte comparison that avoids early exit.

Public lengths and errors use ordinary control flow; this is not a whole-operation constant-time guarantee. This reusable-key trait must not be implemented by one-time authenticators such as Poly1305.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§