1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
/// Module for the ChaCha20 stream cipher algorithm.
pub mod chacha20;
/// Module for the Poly1305 message authentication code (MAC) algorithm.
pub mod poly1305;
/// Re-exporting `ChaCha20` for direct use.
pub use chacha20::ChaCha20;
/// Re-exporting `Poly1305` for direct use.
pub use poly1305::{Poly1305, SignedEnvelope};
pub trait AlgorithmKeyIVInit {
/// Initializes the algorithm 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.
fn init(&mut self, key: &[u8], iv: &[u8]);
}
pub trait AlgorithmKeyInit {
/// Initializes the algorithm with a key.
///
/// This method sets up the internal state of the cipher using the provided key,
/// preparing it for either encryption or decryption.
///
/// # Arguments
/// * `key` - A byte slice representing the cryptographic key.
fn init(&mut self, key: &[u8]);
}
pub trait AlgorithmProcess {
/// 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.
fn process(&mut self, data: &[u8]) -> Vec<u8>;
}
pub trait AlgorithmProcessInPlace {
/// 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.
fn process_in_place(&self, data: &mut [u8]);
}
pub trait EncryptionAlgorithm: AlgorithmKeyIVInit + AlgorithmProcess {}
pub trait AEADAlgorithm: AlgorithmKeyInit + AlgorithmProcess {}