Skip to main content

Ccm

Struct Ccm 

Source
pub struct Ccm<C, const TAG_LEN: usize = 16> { /* private fields */ }
Expand description

Counter with CBC-MAC (CCM) with compile-time detached tag length.

TAG_LEN must be one of RFC 3610’s valid lengths: {4, 6, 8, 10, 12, 14, 16}.

Implementations§

Source§

impl<C, const TAG_LEN: usize> Ccm<C, TAG_LEN>

Source

pub fn new(cipher: C) -> Self

Wrap a 128-bit block cipher in SP 800-38C CCM mode.

Source

pub fn cipher(&self) -> &C

Borrow the wrapped block cipher.

Source

pub fn tag_len(&self) -> usize

Return the detached authentication tag length in bytes.

Source§

impl<C: BlockCipher, const TAG_LEN: usize> Ccm<C, TAG_LEN>

Source

pub fn compute_tag( &self, nonce: &[u8], aad: &[u8], plaintext: &[u8], ) -> [u8; TAG_LEN]

Compute a detached CCM tag over plaintext and associated data.

Source

pub fn encrypt( &self, nonce: &[u8], aad: &[u8], data: &mut [u8], ) -> [u8; TAG_LEN]

Encrypt data in place and return the detached CCM authentication tag.

Source

pub fn decrypt( &self, nonce: &[u8], aad: &[u8], data: &mut [u8], tag: &[u8; TAG_LEN], ) -> bool

Verify tag and decrypt in place on success.

Returns false and leaves data unchanged when verification fails.

Trait Implementations§

Source§

impl<C: BlockCipher, const TAG_LEN: usize> Aead for Ccm<C, TAG_LEN>

Source§

type Tag = [u8; TAG_LEN]

Detached authentication tag type.
Source§

fn encrypt_in_place( &self, nonce: &[u8], aad: &[u8], data: &mut [u8], ) -> Self::Tag

Encrypt data in place and return its authentication tag.
Source§

fn decrypt_in_place( &self, nonce: &[u8], aad: &[u8], data: &mut [u8], tag: &Self::Tag, ) -> bool

Decrypt data in place after authenticating tag.
Source§

fn encrypt( &self, nonce: &[u8], aad: &[u8], plaintext: &[u8], ) -> (Vec<u8>, Self::Tag)

Encrypt plaintext and return (ciphertext, tag).
Source§

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

Decrypt ciphertext and return plaintext on successful authentication.

Auto Trait Implementations§

§

impl<C, const TAG_LEN: usize> Freeze for Ccm<C, TAG_LEN>
where C: Freeze,

§

impl<C, const TAG_LEN: usize> RefUnwindSafe for Ccm<C, TAG_LEN>
where C: RefUnwindSafe,

§

impl<C, const TAG_LEN: usize> Send for Ccm<C, TAG_LEN>
where C: Send,

§

impl<C, const TAG_LEN: usize> Sync for Ccm<C, TAG_LEN>
where C: Sync,

§

impl<C, const TAG_LEN: usize> Unpin for Ccm<C, TAG_LEN>
where C: Unpin,

§

impl<C, const TAG_LEN: usize> UnsafeUnpin for Ccm<C, TAG_LEN>
where C: UnsafeUnpin,

§

impl<C, const TAG_LEN: usize> UnwindSafe for Ccm<C, TAG_LEN>
where C: UnwindSafe,

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.