Generic implementation of the belt-ctr
block mode of operation.
Mode functionality is accessed using traits from the cipher
crate.
This crate does not ensure ciphertexts are authentic! Thus ciphertext integrity is not verified, which can lead to serious vulnerabilities! AEADs provide simple authenticated encryption, which is much less error-prone than manual integrity verification.
use hex_literal::hex;
use belt_ctr::{BeltCtr, cipher::{KeyIvInit, StreamCipher, StreamCipherSeek}};
let key = &[0x42; 32];
let iv = &[0x24; 16];
let plaintext: &[u8; 34] = b"hello world! this is my plaintext.";
let ciphertext: &[u8; 34] = &hex!(
"38DF06243BD85DA1CAE597CE680D3AFE"
"0EBB372A4F6A858DB2DBE20A63567EED"
"7D1B"
);
let mut cipher: BeltCtr = BeltCtr::new_from_slices(key, iv).unwrap();
// encrypt in-place
let mut buf = plaintext.clone();
cipher.apply_keystream(&mut buf);
assert_eq!(buf[..], ciphertext[..]);
cipher.seek(0);
cipher.apply_keystream(&mut buf);
assert_eq!(buf[..], plaintext[..]);
Licensed under either of:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.