cfb8/
lib.rs

1//! [Cipher Feedback with eight bit feedback][1] (CFB-8) mode.
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 Aes128Cfb8Enc = cfb8::Encryptor<aes::Aes128>;
19//! type Aes128Cfb8Dec = cfb8::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//!     "33b356ce9184290c4c8facc1c0b1f918d5475aeb75b88c161ca65bdf05c7137ff4b0"
26//! );
27//!
28//! // encrypt/decrypt in-place
29//! let mut buf = plaintext.to_vec();
30//! Aes128Cfb8Enc::new(&key.into(), &iv.into()).encrypt(&mut buf);
31//! assert_eq!(buf[..], ciphertext[..]);
32//!
33//! Aes128Cfb8Dec::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//! Aes128Cfb8Enc::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//! Aes128Cfb8Dec::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#CFB-1,_CFB-8,_CFB-64,_CFB-128,_etc.
52
53#![no_std]
54#![doc(
55    html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/26acc39f/logo.svg",
56    html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/26acc39f/logo.svg",
57    html_root_url = "https://docs.rs/cfb8/0.8.1"
58)]
59#![forbid(unsafe_code)]
60#![cfg_attr(docsrs, feature(doc_cfg))]
61#![warn(missing_docs, rust_2018_idioms)]
62
63mod decrypt;
64mod encrypt;
65
66pub use cipher;
67pub use decrypt::Decryptor;
68pub use encrypt::Encryptor;