Skip to main content

Mac

Trait Mac 

Source
pub trait Mac: Send {
    // Required methods
    fn output_len(&self) -> usize;
    fn sign(
        &mut self,
        input: &[&[u8]],
        output: &mut [u8],
    ) -> Result<(), CryptoError>;
    fn verify(
        &mut self,
        input: &[&[u8]],
        expected: &[u8],
    ) -> Result<(), CryptoError>;
}
Expand description

A keyed message authentication code with a reusable key schedule.

Created once per key by RTCCrypto::new_hmac and used for every message authenticated with that key, so the ipad/opad derivation is paid once rather than per packet.

Send and mutable, like the keyed cipher traits, and for the same reason: &mut self lets an implementation carry per-message state — a reused streaming context, a hardware session handle — without interior mutability, and does not impose Sync on implementors that cannot offer it. A caller whose own signature is fixed to &self, such as STUN’s Setter::add_to, can still create a local Mac per message and use it mutably.

Required Methods§

Source

fn output_len(&self) -> usize

Returns the untruncated tag length in bytes.

Source

fn sign( &mut self, input: &[&[u8]], output: &mut [u8], ) -> Result<(), CryptoError>

Writes the tag over the concatenation of input into output.

output must be exactly output_len bytes. Protocols that transmit a truncated tag — SRTP sends 80 or 32 bits of an SHA-1 tag — truncate the result themselves.

Source

fn verify( &mut self, input: &[&[u8]], expected: &[u8], ) -> Result<(), CryptoError>

Verifies a complete untruncated tag in constant time.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§