Crates.io | belt-ctr |
lib.rs | belt-ctr |
version | 0.1.0 |
source | src |
created_at | 2023-03-03 06:08:02.430137 |
updated_at | 2023-04-02 06:35:55.862048 |
description | CTR block mode of operation specified by the BelT standard |
homepage | |
repository | https://github.com/RustCrypto/block-modes |
max_upload_size | |
id | 799482 |
size | 22,945 |
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[..]);
Rust 1.57 or higher.
Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump.
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.