Skip to main content

MacCtx

Struct MacCtx 

Source
pub struct MacCtx { /* private fields */ }
Expand description

Stateful MAC context (EVP_MAC_CTX*).

!Clone — use fork() to duplicate mid-stream state. All stateful operations require &mut self.

Implementations§

Source§

impl MacCtx

Source

pub fn new(alg: &MacAlg) -> Result<Self, ErrorStack>

Create a new (uninitialised) MAC context from an algorithm descriptor.

Call MacCtx::init with a key before feeding data.

§Errors
Source

pub fn init( &mut self, key: &[u8], params: Option<&Params<'_>>, ) -> Result<(), ErrorStack>

Initialise (or re-initialise) with a key and optional parameters.

key is always copied into the MAC context by EVP_MAC_init. HMAC additionally pads the key into IPAD/OPAD. The copy is unavoidable.

§Errors
Source

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

Feed data into the ongoing MAC computation.

§Errors
Source

pub fn finish(&mut self, out: &mut [u8]) -> Result<usize, ErrorStack>

Finalise the MAC and write into out.

out must be at least self.mac_size() bytes. Returns the number of bytes written.

§Errors
Source

pub fn finish_xof(&mut self, out: &mut [u8]) -> Result<(), ErrorStack>

Finalise with variable-length XOF output (KMAC-128, KMAC-256).

§Errors
Source

pub fn mac_size(&self) -> usize

Expected MAC output length in bytes. Available after init.

Source

pub fn fork(&self) -> Result<MacCtx, ErrorStack>

Fork the current mid-stream state into a new context (EVP_MAC_CTX_dup).

Named fork (not clone) to signal this is a potentially expensive deep copy.

§Errors

Trait Implementations§

Source§

impl Drop for MacCtx

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for MacCtx

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.