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 in constant time

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Mac for Poly1305

Source§

type Key = [u8; 32]

Source§

type Tag = Tag<POLY1305_TAG_SIZE>