pub struct Salsa20 { /* private fields */ }Expand description
Salsa20 stream cipher state (DJB / eSTREAM variant).
Holds the initial state (key + nonce + 64-bit counter) and buffers
the leftover bytes of the current keystream block so partial calls
to Self::apply_keystream behave like one contiguous stream.
Implementations§
Source§impl Salsa20
impl Salsa20
Sourcepub fn new(key: &[u8; 32], nonce: &[u8; 8], counter: u64) -> Self
pub fn new(key: &[u8; 32], nonce: &[u8; 8], counter: u64) -> Self
Initialise Salsa20 with a 256-bit key, an 8-byte nonce, and an initial 64-bit block counter (usually 0).
Sourcepub fn new_128(key: &[u8; 16], nonce: &[u8; 8], counter: u64) -> Self
pub fn new_128(key: &[u8; 16], nonce: &[u8; 8], counter: u64) -> Self
Initialise Salsa20 with a 128-bit key, an 8-byte nonce, and an
initial 64-bit block counter. Uses the tau expansion
constants and repeats the key across the state border.
Sourcepub fn apply_keystream(&mut self, data: &mut [u8])
pub fn apply_keystream(&mut self, data: &mut [u8])
XOR the keystream into data in place. Encrypts or decrypts
indifferently (the cipher is symmetric).
Handles arbitrary lengths and partial blocks: leftover keystream bytes are remembered between calls, so feeding data in chunks produces the same output as one contiguous call.