Skip to main content

ChaCha

Struct ChaCha 

Source
pub struct ChaCha<const ROUNDS: usize, const IS_IETF: bool> { /* private fields */ }
Expand description

ChaCha stream cipher.

IS_IETF selects the nonce/counter layout:

  • false (DJB original): 64-bit counter at words 12–13, 64-bit nonce at words 14–15.
  • true (IETF / RFC 8439): 32-bit counter at word 12, 96-bit nonce at words 13–15.

Implementations§

Source§

impl<const ROUNDS: usize> ChaCha<ROUNDS, false>

Source

pub fn new(key: &[u8; 32], nonce: &[u8; 8]) -> ChaCha<ROUNDS, false>

Create a new ChaCha instance with the DJB nonce layout (8-byte nonce, 64-bit counter).

Source

pub fn set_counter(&mut self, counter: u64)

Set the ChaCha counter (words 12 and 13). It can be used to move forward and backward in the keystream.

Source§

impl<const ROUNDS: usize> ChaCha<ROUNDS, true>

Source

pub fn new(key: &[u8; 32], nonce: &[u8; 12]) -> ChaCha<ROUNDS, true>

Create a new ChaCha instance with the IETF (RFC 8439) nonce layout (12-byte nonce, 32-bit counter).

Source

pub fn set_counter(&mut self, counter: u32)

Set the ChaCha counter (word 12). The counter is a u32. It can be used to move forward and backward in the keystream.

Trait Implementations§

Source§

impl<const ROUNDS: usize, const IS_IETF: bool> Drop for ChaCha<ROUNDS, IS_IETF>

Source§

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

impl<const ROUNDS: usize, const IS_IETF: bool> StreamCipher for ChaCha<ROUNDS, IS_IETF>

Source§

fn xor_keystream(&mut self, in_out: &mut [u8])

XOR plaintext with the ChaCha keystream.

Source§

impl<const ROUNDS: usize, const IS_IETF: bool> Zeroize for ChaCha<ROUNDS, IS_IETF>

Source§

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§

§

impl<const ROUNDS: usize, const IS_IETF: bool> Freeze for ChaCha<ROUNDS, IS_IETF>

§

impl<const ROUNDS: usize, const IS_IETF: bool> RefUnwindSafe for ChaCha<ROUNDS, IS_IETF>

§

impl<const ROUNDS: usize, const IS_IETF: bool> Send for ChaCha<ROUNDS, IS_IETF>

§

impl<const ROUNDS: usize, const IS_IETF: bool> Sync for ChaCha<ROUNDS, IS_IETF>

§

impl<const ROUNDS: usize, const IS_IETF: bool> Unpin for ChaCha<ROUNDS, IS_IETF>

§

impl<const ROUNDS: usize, const IS_IETF: bool> UnsafeUnpin for ChaCha<ROUNDS, IS_IETF>

§

impl<const ROUNDS: usize, const IS_IETF: bool> UnwindSafe for ChaCha<ROUNDS, IS_IETF>

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

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