StreamCipher

Trait StreamCipher 

Source
pub trait StreamCipher {
    const KEY_SIZE: usize;
    const NONCE_SIZE: usize;
    const BLOCK_SIZE: usize;

    // Required methods
    fn process(&mut self, data: &mut [u8]) -> Result<()>;
    fn keystream(&mut self, output: &mut [u8]) -> Result<()>;
    fn reset(&mut self) -> Result<()>;
    fn seek(&mut self, position: u64) -> Result<()>;

    // Provided methods
    fn encrypt(&mut self, data: &mut [u8]) -> Result<()> { ... }
    fn decrypt(&mut self, data: &mut [u8]) -> Result<()> { ... }
}
Expand description

Common trait for stream cipher implementations

Required Associated Constants§

Source

const KEY_SIZE: usize

The key size in bytes

Source

const NONCE_SIZE: usize

The nonce size in bytes

Source

const BLOCK_SIZE: usize

The internal block size in bytes (if applicable)

Required Methods§

Source

fn process(&mut self, data: &mut [u8]) -> Result<()>

Process data in place (encrypts for encryption, decrypts for decryption)

Source

fn keystream(&mut self, output: &mut [u8]) -> Result<()>

Generate keystream directly into an output buffer

Source

fn reset(&mut self) -> Result<()>

Reset the cipher to its initial state

Source

fn seek(&mut self, position: u64) -> Result<()>

Seek to a specific position in the keystream (if supported)

Provided Methods§

Source

fn encrypt(&mut self, data: &mut [u8]) -> Result<()>

Encrypt data in place

Source

fn decrypt(&mut self, data: &mut [u8]) -> Result<()>

Decrypt data in place

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl StreamCipher for ChaCha20

Source§

const KEY_SIZE: usize = 32usize

Source§

const NONCE_SIZE: usize = 12usize

Source§

const BLOCK_SIZE: usize = 64usize