Skip to main content

ChaCha20Poly1305

Struct ChaCha20Poly1305 

pub struct ChaCha20Poly1305 { /* private fields */ }
Expand description

ChaCha20-Poly1305 AEAD as specified in RFC 8439.

§Parameters

  • Key: 256 bits (32 bytes)
  • Nonce: 96 bits (12 bytes)
  • Tag: 128 bits (16 bytes)

§Panics

encrypt_in_place panics if in_out exceeds [CHACHA20_IETF_MAX_LEN] bytes (~256 GiB), the maximum allowed by RFC 8439’s 32-bit block counter. decrypt_in_place returns [AeadError::InvalidCiphertext] in that case instead.

Implementations§

§

impl ChaCha20Poly1305

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

Creates a new AEAD instance from a 32-byte key.

Trait Implementations§

§

impl Aead for ChaCha20Poly1305

§

const KEY_SIZE: usize = 32

§

const TAG_SIZE: usize = 16

§

const NONCE_SIZE: usize = 12

§

fn encrypt_in_place(&self, in_out: &mut [u8], nonce: &[u8], aad: &[u8]) -> Hash

§

fn decrypt_in_place( &self, in_out: &mut [u8], nonce: &[u8], aad: &[u8], tag: &[u8], ) -> Result<(), AeadError>

§

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

§

fn decrypt( &self, ciphertext: &[u8], nonce: &[u8], aad: &[u8], ) -> Result<Vec<u8>, AeadError>

Source§

impl Aead for ChaCha20Poly1305

ChaCha20-Poly1305 (AEAD id 0x0003).

Source§

const HPKE_AEAD_ID: u16 = 0x0003

The HPKE AEAD identifier (draft-ietf-hpke-hpke-05 Section 7.3, IANA “HPKE AEAD Identifiers”), used to build the ciphersuite suite_id.
Source§

const MAX_PLAINTEXT_SIZE: u64 = CHACHA20_POLY1305_MAX_PLAINTEXT_SIZE

Maximum length, in bytes, of a plaintext passed to Aead::seal, i.e. P_MAX ([RFC 5116]). Read more
Source§

const MAX_CIPHERTEXT_SIZE: u64 = CHACHA20_POLY1305_MAX_CIPHERTEXT_SIZE

Maximum length, in bytes, of a ciphertext passed to Aead::open, i.e. C_MAX ([RFC 5116]). Read more
Source§

fn new(key: &[u8]) -> Result<Self, HpkeError>

Instantiates the cipher from KEY_SIZE raw key bytes, as produced by the HPKE key schedule. Read more
Source§

fn seal( &self, in_out: &mut [u8], nonce: &[u8], associated_data: &[u8], ) -> Result<Hash, HpkeError>

Encrypts in_out in place and returns the detached authentication tag, forwarding to [crypto::Aead::encrypt_in_place]. Read more
Source§

fn open( &self, in_out: &mut [u8], nonce: &[u8], associated_data: &[u8], tag: &[u8], ) -> Result<(), HpkeError>

Decrypts in_out in place using the detached authentication tag, forwarding to [crypto::Aead::decrypt_in_place]. Read more
§

impl Drop for ChaCha20Poly1305

§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
§

impl Zeroize for ChaCha20Poly1305

§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.

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 = !

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.
§

impl<T> Zeroize for T
where T: Zeroize,