Skip to main content

ChaCha20Poly1305Cipher

Struct ChaCha20Poly1305Cipher 

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

ChaCha20-Poly1305 AEAD cipher supporting zero-copy in-place encryption and decryption directly within pre-allocated network packet buffers (such as AF_XDP UMEM chunks).

Implementations§

Source§

impl ChaCha20Poly1305Cipher

Source

pub fn new(key: [u8; 32]) -> Self

Creates a new cipher instance from a 32-byte symmetric key.

Source

pub fn seal_in_place( &self, counter: u64, buf: &mut [u8], plaintext_len: usize, ) -> Result<usize, CryptoError>

Seal plaintext in-place inside buf[..plaintext_len], writing the 16-byte Poly1305 authentication tag immediately following the ciphertext into buf[plaintext_len..plaintext_len + 16].

The buffer must have capacity of at least plaintext_len + 16 bytes. Returns the total sealed ciphertext length (plaintext_len + 16).

Source

pub fn open_in_place( &self, counter: u64, buf: &mut [u8], sealed_len: usize, ) -> Result<usize, CryptoError>

Open and authenticate ciphertext in-place inside buf[..sealed_len].

Expects the 16-byte Poly1305 authentication tag at the end of the ciphertext: buf[sealed_len - 16..sealed_len]. Returns the decrypted plaintext length (sealed_len - 16).

Source

pub fn open_in_place_with_window( &self, counter: u64, buf: &mut [u8], sealed_len: usize, replay: &mut ReplayWindow, ) -> Result<usize, CryptoError>

Open and authenticate ciphertext in-place, verifying against a sliding anti-replay window.

The replay window is checked before AEAD decryption and committed only upon successful authentication.

Trait Implementations§

Source§

impl Debug for ChaCha20Poly1305Cipher

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.