[][src]Crate cfb8

Generic 8-bit Cipher Feedback (CFB8) mode implementation.

This crate implements CFB8 as a self-synchronizing stream cipher.


This crate does not provide any authentification! Thus ciphertext integrity is not verified, which can lead to serious vulnerabilities!


extern crate aes;
extern crate cfb8;
#[macro_use] extern crate hex_literal;

use aes::Aes128;
use cfb8::Cfb8;
use cfb8::stream_cipher::{NewStreamCipher, StreamCipher};

type AesCfb8 = Cfb8<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!("
    8fb603d8 66a1181c 08506c75 37ee9cad
    35be8ff8 e0c79526 9d735d04 c0a93017
    b1a748e0 25146b68 23fc9ad3

let mut data = plaintext.to_vec();
// encrypt plaintext
AesCfb8::new_var(key, iv).unwrap().encrypt(&mut data);
assert_eq!(data, &ciphertext[..]);
// and decrypt it back
AesCfb8::new_var(key, iv).unwrap().decrypt(&mut data);
assert_eq!(data, &plaintext[..]);

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


pub extern crate stream_cipher;



CFB self-synchronizing stream cipher instance.