#stream-cipher #cipher #block-mode #belt #crypto

no-std belt-ctr

CTR block mode of operation specified by the BelT standard

2 unstable releases

0.1.0 Apr 2, 2023
0.0.0 Mar 3, 2023

#2606 in Cryptography


Used in bevy_asset_packer

MIT/Apache

10KB
163 lines

RustCrypto: belt-ctr

crate Docs Apache2/MIT licensed Rust Version Project Chat Build Status

Generic implementation of the belt-ctr block mode of operation.

Mode functionality is accessed using traits from the 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! AEADs provide simple authenticated encryption, which is much less error-prone than manual integrity verification.

Example

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[..]);

Minimum Supported Rust Version

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.

SemVer Policy

  • All on-by-default features of this library are covered by SemVer
  • MSRV is considered exempt from SemVer as noted above

License

Licensed under either of:

at your option.

Contribution

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.

Dependencies

~405KB