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
//! 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[..]);
//! ```
pub use cipher;
pub use crate;