cfb_mode/lib.rs
1//! [Cipher feedback][1] (CFB) mode with full block feedback.
2//!
3//! <img src="https://raw.githubusercontent.com/RustCrypto/media/26acc39f/img/block-modes/cfb_enc.svg" width="49%" />
4//! <img src="https://raw.githubusercontent.com/RustCrypto/media/26acc39f/img/block-modes/cfb_dec.svg" width="49%"/>
5//!
6//! Mode functionality is accessed using traits from re-exported [`cipher`] crate.
7//!
8//! # ⚠️ Security Warning: Hazmat!
9//!
10//! This crate does not ensure ciphertexts are authentic! Thus ciphertext integrity
11//! is not verified, which can lead to serious vulnerabilities!
12//!
13//! # Example
14//! ```
15//! use aes::cipher::{AsyncStreamCipher, KeyIvInit};
16//! use hex_literal::hex;
17//!
18//! type Aes128CfbEnc = cfb_mode::Encryptor<aes::Aes128>;
19//! type Aes128CfbDec = cfb_mode::Decryptor<aes::Aes128>;
20//!
21//! let key = [0x42; 16];
22//! let iv = [0x24; 16];
23//! let plaintext = *b"hello world! this is my plaintext.";
24//! let ciphertext = hex!(
25//! "3357121ebb5a29468bd861467596ce3d6f99e251cc2d9f0a598032ae386d0ab995b3"
26//! );
27//!
28//! // encrypt/decrypt in-place
29//! let mut buf = plaintext.to_vec();
30//! Aes128CfbEnc::new(&key.into(), &iv.into()).encrypt(&mut buf);
31//! assert_eq!(buf[..], ciphertext[..]);
32//!
33//! Aes128CfbDec::new(&key.into(), &iv.into()).decrypt(&mut buf);
34//! assert_eq!(buf[..], plaintext[..]);
35//!
36//! // encrypt/decrypt from buffer to buffer
37//! // buffer length must be equal to input length
38//! let mut buf1 = [0u8; 34];
39//! Aes128CfbEnc::new(&key.into(), &iv.into())
40//! .encrypt_b2b(&plaintext, &mut buf1)
41//! .unwrap();
42//! assert_eq!(buf1[..], ciphertext[..]);
43//!
44//! let mut buf2 = [0u8; 34];
45//! Aes128CfbDec::new(&key.into(), &iv.into())
46//! .decrypt_b2b(&buf1, &mut buf2)
47//! .unwrap();
48//! assert_eq!(buf2[..], plaintext[..]);
49//! ```
50//!
51//! [1]: https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher_feedback_(CFB)
52
53#![no_std]
54#![doc(
55 html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
56 html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
57)]
58#![forbid(unsafe_code)]
59#![cfg_attr(docsrs, feature(doc_cfg))]
60#![warn(missing_docs, rust_2018_idioms)]
61
62mod decrypt;
63mod encrypt;
64
65pub use cipher;
66pub use decrypt::{BufDecryptor, Decryptor};
67pub use encrypt::{BufEncryptor, Encryptor};