Skip to main content

AesCcm

Struct AesCcm 

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

AES-CCM with the RFC 3610 default parameters: L = 2, so the nonce is 13 bytes and the maximum payload is 2^16 - 1 bytes. The tag length M is configurable per call.

This is the wrapper most callers want. The generic (M, L) form is exposed via ccm_encrypt / ccm_decrypt for protocols that need a different L.

Implementations§

Source§

impl AesCcm

Source

pub fn new(key: &[u8], m: usize) -> Option<Self>

Initialise AES-CCM with M{4, 6, 8, 10, 12, 14, 16}. Returns None for invalid M or invalid AES key length.

Source

pub fn encrypt( &self, nonce: &[u8; 13], aad: &[u8], plaintext: &[u8], ) -> Option<(Vec<u8>, Vec<u8>)>

Encrypt and authenticate. nonce.len() == 13. Returns (ciphertext, tag) where tag.len() == M.

Source

pub fn decrypt( &self, nonce: &[u8; 13], aad: &[u8], ciphertext: &[u8], tag: &[u8], ) -> Option<Vec<u8>>

Decrypt and verify. nonce.len() == 13, tag.len() == M. Returns None on tag mismatch or any malformed input.

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.