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>
impl<const ROUNDS: usize> ChaCha<ROUNDS, false>
Sourcepub fn new(key: &[u8; 32], nonce: &[u8; 8]) -> ChaCha<ROUNDS, false>
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).
Sourcepub fn set_counter(&mut self, counter: u64)
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>
impl<const ROUNDS: usize> ChaCha<ROUNDS, true>
Sourcepub fn new(key: &[u8; 32], nonce: &[u8; 12]) -> ChaCha<ROUNDS, true>
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).
Sourcepub fn set_counter(&mut self, counter: u32)
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> StreamCipher for ChaCha<ROUNDS, IS_IETF>
impl<const ROUNDS: usize, const IS_IETF: bool> StreamCipher for ChaCha<ROUNDS, IS_IETF>
Source§fn xor_keystream(&mut self, in_out: &mut [u8])
fn xor_keystream(&mut self, in_out: &mut [u8])
XOR plaintext with the ChaCha keystream.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more