Expand description
RC4 stream cipher algorithm implementation.
This module provides the RC4 (Rivest Cipher 4) stream cipher implementation. RC4 is a widely-used stream cipher that uses a variable-length key (1-256 bytes) to generate a pseudorandom keystream which is XOR’d with the plaintext.
§Security Note
RC4 is considered cryptographically broken and should not be used for security-sensitive applications. It is provided here for obfuscation purposes only. For production use, consider using a modern authenticated encryption algorithm.
§Algorithm
RC4 consists of two main phases:
- KSA (Key Scheduling Algorithm): Initializes a 256-byte permutation table (S-box) based on the key
- PRGA (Pseudo-Random Generation Algorithm): Generates keystream bytes by permuting the S-box
§Types
Rc4<KEY_LEN, D>: The main algorithm type with const generic key lengthReEncrypt<KEY_LEN>: A drop strategy that re-encrypts data on drop
§Example
use const_secret::{
Encrypted, StringLiteral,
drop_strategy::Zeroize,
rc4::{ReEncrypt, Rc4},
};
const KEY: [u8; 5] = *b"mykey";
// Zeroize on drop (default)
const SECRET: Encrypted<Rc4<5, Zeroize<[u8; 5]>>, StringLiteral, 5> =
Encrypted::<Rc4<5, Zeroize<[u8; 5]>>, StringLiteral, 5>::new(*b"hello", KEY);
// Re-encrypt on drop
const SECRET2: Encrypted<Rc4<5, ReEncrypt<5>>, StringLiteral, 6> =
Encrypted::<Rc4<5, ReEncrypt<5>>, StringLiteral, 6>::new(*b"secret", KEY);
fn main() {
let s1: &str = &*SECRET;
assert_eq!(s1, "hello");
let s2: &str = &*SECRET2;
assert_eq!(s2, "secret");
}