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