Expand description
Output feedback (OFB) mode.
Mode functionality is accessed using traits from re-exported cipher
crate.
§⚠️ Security Warning: Hazmat!
This crate does not ensure ciphertexts are authentic! Thus ciphertext integrity is not verified, which can lead to serious vulnerabilities!
§Example
use aes::cipher::{KeyIvInit, StreamCipher};
use hex_literal::hex;
type Aes128Ofb = ofb::Ofb<aes::Aes128>;
let key = [0x42; 16];
let iv = [0x24; 16];
let plaintext = *b"hello world! this is my plaintext.";
let ciphertext = hex!(
"3357121ebb5a29468bd861467596ce3dc6ba5df50e536a2443b8ee16c2f7cd0869c9"
);
// encrypt in-place
let mut buf = plaintext.to_vec();
let mut cipher = Aes128Ofb::new(&key.into(), &iv.into());
cipher.apply_keystream(&mut buf);
assert_eq!(buf[..], ciphertext[..]);
// OFB mode can be used with streaming messages
let mut cipher = Aes128Ofb::new(&key.into(), &iv.into());
for chunk in buf.chunks_mut(3) {
cipher.apply_keystream(chunk);
}
assert_eq!(buf[..], plaintext[..]);
// encrypt/decrypt from buffer to buffer
// buffer length must be equal to input length
let mut buf1 = [0u8; 34];
let mut cipher = Aes128Ofb::new(&key.into(), &iv.into());
cipher
.apply_keystream_b2b(&plaintext, &mut buf1)
.unwrap();
assert_eq!(buf1[..], ciphertext[..]);
let mut buf2 = [0u8; 34];
let mut cipher = Aes128Ofb::new(&key.into(), &iv.into());
cipher.apply_keystream_b2b(&buf1, &mut buf2).unwrap();
assert_eq!(buf2[..], plaintext[..]);
Re-exports§
pub use cipher;
Structs§
- Output feedback (OFB) mode.
Type Aliases§
- Buffered Output feedback (OFB) mode.