ChaCha20Ietf

Struct ChaCha20Ietf 

Source
pub struct ChaCha20Ietf;
Expand description

An implementation of ChaCha20 (IETF-version)

Implementations§

Source§

impl ChaCha20Ietf

Source

pub fn cipher() -> Box<dyn Cipher>

Creates a Cipher instance with ChaCha20Ietf as underlying cipher

Source

pub fn xor(key: &[u8], nonce: &[u8], n: u32, data: &mut [u8])

XORs the bytes in data with the ChaCha20 keystream for key and nonce starting at the nth block

§Warning:

This function panics if

  • key is smaller or larger than 32 bytes/256 bits
  • nonce is smaller or larger than 12 bytes/96 bits
  • n exceeds 2^32 - 1 (which means that data must be smaller than (2^32 - n) * 64)

Consider using the crypto_api-interface instead of calling this function directly

Trait Implementations§

Source§

impl Cipher for ChaCha20Ietf

Source§

fn info(&self) -> CipherInfo

Returns information about the cipher
Source§

fn encrypted_len_max(&self, plaintext_len: usize) -> usize

Predicts the maximum encrypted length for plaintext_len bytes
Source§

fn encrypt( &self, buf: &mut [u8], plaintext_len: usize, key: &[u8], nonce: &[u8], ) -> Result<usize, Box<dyn Error + 'static>>

Encrypts plaintext_len bytes in-place in buf using key and nonce and returns the ciphertext length
Source§

fn encrypt_to( &self, buf: &mut [u8], plaintext: &[u8], key: &[u8], nonce: &[u8], ) -> Result<usize, Box<dyn Error + 'static>>

Encrypts plaintext into buf using key and nonce and returns the ciphertext length
Source§

fn decrypt( &self, buf: &mut [u8], ciphertext_len: usize, key: &[u8], nonce: &[u8], ) -> Result<usize, Box<dyn Error + 'static>>

Decrypts ciphertext_len bytes in-place in buf using key and nonce and returns the plaintext length
Source§

fn decrypt_to( &self, buf: &mut [u8], ciphertext: &[u8], key: &[u8], nonce: &[u8], ) -> Result<usize, Box<dyn Error + 'static>>

Decrypts ciphertext into buf using key and nonce and returns the plaintext length
Source§

impl SecKeyGen for ChaCha20Ietf

Source§

fn new_sec_key( &self, buf: &mut [u8], rng: &mut dyn SecureRng, ) -> Result<usize, Box<dyn Error + 'static>>

Generates a new key into buf using rng and returns the length of the secret key

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.