[][src]Crate ofb

Generic Output Feedback (OFB) mode implementation.

This crate implements OFB as a synchronous stream cipher.

Security Warning

This crate does not ensure ciphertexts are authentic! Thus ciphertext integrity is not verified, which can lead to serious vulnerabilities!

Examples

use aes::Aes128;
use hex_literal::hex;
use ofb::Ofb;
use ofb::cipher::{NewStreamCipher, SyncStreamCipher};

type AesOfb = Ofb<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
    9455b0bb e346b653 ec0d44aa bece8cc9
    f886df67 049d780d 9ccdf957
");

let mut buffer = plaintext.to_vec();
// create cipher instance
let mut cipher = AesOfb::new_var(key, iv).unwrap();
// apply keystream (encrypt)
cipher.apply_keystream(&mut buffer);
assert_eq!(buffer, &ciphertext[..]);
// and decrypt it back
AesOfb::new_var(key, iv).unwrap().apply_keystream(&mut buffer);
assert_eq!(buffer, &plaintext[..]);

// OFB mode can be used with streaming messages
let mut cipher = AesOfb::new_var(key, iv).unwrap();
for chunk in buffer.chunks_mut(3) {
    cipher.apply_keystream(chunk);
}
assert_eq!(buffer, &ciphertext[..]);

Re-exports

pub use cipher;

Structs

Ofb

OFB self-synchronizing stream cipher instance.