logo

Crate cfb8

source · []
Expand description

Cipher Feedback with eight bit feedback (CFB-8) 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::{AsyncStreamCipher, KeyIvInit};
use hex_literal::hex;

type Aes128Cfb8Enc = cfb8::Encryptor<aes::Aes128>;
type Aes128Cfb8Dec = cfb8::Decryptor<aes::Aes128>;

let key = [0x42; 16];
let iv = [0x24; 16];
let plaintext = *b"hello world! this is my plaintext.";
let ciphertext = hex!(
    "33b356ce9184290c4c8facc1c0b1f918d5475aeb75b88c161ca65bdf05c7137ff4b0"
);

// encrypt/decrypt in-place
let mut buf = plaintext.to_vec();
Aes128Cfb8Enc::new(&key.into(), &iv.into()).encrypt(&mut buf);
assert_eq!(buf[..], ciphertext[..]);

Aes128Cfb8Dec::new(&key.into(), &iv.into()).decrypt(&mut buf);
assert_eq!(buf[..], plaintext[..]);

// encrypt/decrypt from buffer to buffer
// buffer length must be equal to input length
let mut buf1 = [0u8; 34];
Aes128Cfb8Enc::new(&key.into(), &iv.into())
    .encrypt_b2b(&plaintext, &mut buf1)
    .unwrap();
assert_eq!(buf1[..], ciphertext[..]);

let mut buf2 = [0u8; 34];
Aes128Cfb8Dec::new(&key.into(), &iv.into())
    .decrypt_b2b(&buf1, &mut buf2)
    .unwrap();
assert_eq!(buf2[..], plaintext[..]);

Re-exports

pub use cipher;

Structs

CFB-8 mode decryptor.

CFB-8 mode encryptor.