pub struct Salsa20 { /* private fields */ }Expand description
Salsa20 stream cipher (20-round variant).
Salsa20 keeps its 16-word state plus one cached 64-byte keystream block.
apply_keystream XORs the generated stream into caller-owned buffers, so
the same method handles both encryption and decryption.
Implementations§
Source§impl Salsa20
impl Salsa20
Sourcepub fn new(key: &[u8; 32], nonce: &[u8; 8]) -> Self
pub fn new(key: &[u8; 32], nonce: &[u8; 8]) -> Self
Create a Salsa20 instance with a 32-byte key and 8-byte nonce.
Sourcepub fn with_key_bytes(key: &[u8], nonce: &[u8; 8]) -> Self
pub fn with_key_bytes(key: &[u8], nonce: &[u8; 8]) -> Self
Create a Salsa20 instance with either a 16-byte or 32-byte key.
Sourcepub fn with_counter(key: &[u8], nonce: &[u8; 8], counter: u64) -> Self
pub fn with_counter(key: &[u8], nonce: &[u8; 8], counter: u64) -> Self
Create a Salsa20 instance at an arbitrary 64-byte block counter.
Sourcepub fn new_wiping(key: &mut [u8; 32], nonce: &mut [u8; 8]) -> Self
pub fn new_wiping(key: &mut [u8; 32], nonce: &mut [u8; 8]) -> Self
Create with a 32-byte key and wipe the caller’s key and nonce buffers.
Sourcepub fn with_key_bytes_wiping(key: &mut [u8], nonce: &mut [u8; 8]) -> Self
pub fn with_key_bytes_wiping(key: &mut [u8], nonce: &mut [u8; 8]) -> Self
Create with a 16- or 32-byte key and wipe the caller’s key and nonce.
Sourcepub fn apply_keystream(&mut self, buf: &mut [u8])
pub fn apply_keystream(&mut self, buf: &mut [u8])
XOR the Salsa20 keystream into buf in place.
Sourcepub fn fill(&mut self, buf: &mut [u8])
pub fn fill(&mut self, buf: &mut [u8])
Fill buf with keystream bytes by XORing into the existing contents.
Sourcepub fn keystream_block(&mut self) -> [u8; 64]
pub fn keystream_block(&mut self) -> [u8; 64]
Return the next 64 bytes of keystream, respecting the current stream position.
Sourcepub fn set_counter(&mut self, counter: u64)
pub fn set_counter(&mut self, counter: u64)
Seek to a 64-byte block boundary.
Trait Implementations§
Source§impl StreamCipher for Salsa20
impl StreamCipher for Salsa20
Source§fn apply_keystream(&mut self, buf: &mut [u8])
fn apply_keystream(&mut self, buf: &mut [u8])
Self::fill for callers that prefer this terminology.