pub struct StreamCipher { /* private fields */ }Expand description
An ASCON-based seekable stream cipher.
Implementations§
Source§impl StreamCipher
impl StreamCipher
Sourcepub const KEY_LENGTH: usize = 32usize
pub const KEY_LENGTH: usize = 32usize
The key length in bytes
Sourcepub fn new(key: &[u8; 32], context: impl AsRef<[u8]>) -> Self
pub fn new(key: &[u8; 32], context: impl AsRef<[u8]>) -> Self
Create a new state with the given key and context.
The key must be 32 bytes long, and must be randomly generated, for example using
rand::thread_rng().gen::<[u8; 32]>() or getrandom::getrandom().
The context is optional can be of any length. It is used to improve multi-user security.
Sourcepub fn fill(
&self,
out: &mut [u8],
start_offset: u64,
) -> Result<(), &'static str>
pub fn fill( &self, out: &mut [u8], start_offset: u64, ) -> Result<(), &'static str>
Fill the given buffer with the keystream starting at the given offset.
The offset is in bytes.
The key stream is deterministic: the same key, context and offset will always produce the same output.
Sourcepub fn apply_keystream(
&self,
out: &mut [u8],
start_offset: u64,
) -> Result<(), &'static str>
pub fn apply_keystream( &self, out: &mut [u8], start_offset: u64, ) -> Result<(), &'static str>
Encrypt or decrypt the given buffer in place, given the offset.
The buffer is modified in place. The offset is in bytes.
The key stream is deterministic: the same key, context and offset will always produce the same output.
This function is equivalent to calling fill and then XORing the output with the input.
§Caveats
- There is no integrity.
- An adversary can flip arbitrary bits in the ciphertext and the corresponding bits in the plaintext will be flipped when decrypted.
Trait Implementations§
Source§impl Clone for StreamCipher
impl Clone for StreamCipher
Source§fn clone(&self) -> StreamCipher
fn clone(&self) -> StreamCipher
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more