Generic Cipher Feedback (CFB) mode implementation.
This crate implements CFB as a self-synchronizing stream cipher.
Warning
This crate does not provide any authentification! Thus ciphertext integrity is not verified, which can lead to serious vulnerabilities!
Examples
extern crate aes;
extern crate cfb_mode;
#[macro_use] extern crate hex_literal;
use aes::Aes128;
use cfb_mode::Cfb;
type AesCfb = Cfb<Aes128>;
let key = b"very secret key.";
let iv = b"unique init vect";
let plaintext = b"The quick brown fox jumps over the lazy dog.";
let ciphertext = hex!("
8f0cb6e8 9286cd02 09c95da4 fa663269
bf7f286d 76820a4a f6cd3794 64cb6765
8c764fa2 ce107f96 e1cf1dcd
");
let mut buffer = plaintext.to_vec();
// encrypt plaintext
AesCfb::new_var(key, iv).unwrap().encrypt(&mut buffer);
assert_eq!(buffer, &ciphertext[..]);
// and decrypt it back
AesCfb::new_var(key, iv).unwrap().decrypt(&mut buffer);
assert_eq!(buffer, &plaintext[..]);
// CFB mode can be used with streaming messages
let mut cipher = AesCfb::new_var(key, iv).unwrap();
for chunk in buffer.chunks_mut(3) {
cipher.encrypt(chunk);
}
assert_eq!(buffer, &ciphertext[..]);