pub trait Permutation {
    // Required methods
    fn init(&mut self, key: &[u8], iv: &[u8]);
    fn process(&mut self, data: &[u8]) -> Vec<u8>;
    fn clear(&mut self);
}
Expand description

Permutation trait defines the common operations for permutation-based cryptographic algorithms.

This trait provides the fundamental methods required for encryption and decryption processes in ciphers like ChaCha20 and XChaCha20.

Required Methods§

source

fn init(&mut self, key: &[u8], iv: &[u8])

Initializes the permutation with a key and an initialization vector (IV).

This method sets up the internal state of the cipher using the provided key and IV, preparing it for either encryption or decryption.

Arguments
  • key - A byte slice representing the cryptographic key.
  • iv - A byte slice representing the initialization vector.
source

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

Processes the provided data (either encrypts or decrypts, depending on the implementation).

This method applies the cipher’s permutation logic to the provided data, returning the processed data as a new vector of bytes.

Arguments
  • data - A byte slice of data to be processed (encrypted or decrypted).
Returns

A vector of bytes representing the processed data.

source

fn clear(&mut self)

Clears the internal state of the cipher.

This method is used to reset the cipher’s state, ensuring that no sensitive information is left in memory after the cryptographic operations are complete.

Implementors§