Expand description
Generic implementation of the ELK (Encrypted LFSR Keystream) mode of operation for block ciphers.
Mode functionality is accessed using traits from the re-exported cipher crate.
ELK is a stream-like mode of operation that generates a keystream by encrypting the state of a
Galois-Field Linear Feedback Shift Register (LFSR) with a block cipher.
§⚠️ Security Warning: Hazmat!
This crate does not ensure ciphertexts are authentic! Thus ciphertext integrity is not verified, which can lead to serious vulnerabilities! It is highly recommended to use ELK in combination with a strong MAC to provide robust authenticated encryption.
§Stream Cipher Behavior & State
Because ELK is a keystream-based cipher, encryption and decryption are mathematically identical
(XORing a keystream). However, the internal LFSR state of the Elk instance is advanced with each
block processed. Therefore:
- To decrypt a ciphertext, you must use a cipher instance initialized with the same initial key and IV.
- Calling
.apply_keystream(&mut data)twice in succession on the same unmodified instance will not work as expected because the second call will use the advanced LFSR state instead of the initial state.
§Example
use aes::cipher::KeyIvInit;
use aes_elk::Elk;
type Aes128Elk = Elk<aes::Aes128>;
let key = [0x42; 16];
let iv = [0x24; 16];
let plaintext = *b"hello world! this is my plaintext! it can be any length.";
// encrypt in-place
let mut buf = plaintext.to_vec();
let mut encryptor = Aes128Elk::new(&key.into(), &iv.into());
let mut decryptor = encryptor.clone(); // Clone the initial state for decryption
encryptor.apply_keystream(&mut buf).unwrap();
assert_ne!(buf[..], plaintext[..]);
// decrypt in-place
decryptor.apply_keystream(&mut buf).unwrap();
assert_eq!(buf[..], plaintext[..]);Re-exports§
pub use cipher;
Structs§
- Elk
- Universal ELK (Encrypted LFSR Keystream) mode. Supports any block cipher with 128, 256, 512, or 1024 bit block sizes.
Enums§
- Error
- Error types for ELK operations.