Expand description
§RustCrypto: BeltDwp
Pure Rust implementation of the belt-dwp AEAD algorithm
specified in the republic of Belarus standard STB 34.101.31-2020.
§Security Notes
No security audits of this crate have ever been performed, and it has not been thoroughly assessed to ensure its operation is constant-time on common CPU architectures.
USE AT YOUR OWN RISK!
§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.
§Usage
Simple usage (allocating, no associated data):
use belt_dwp::{
aead::{Aead, AeadCore, Generate, Key, KeyInit},
BeltDwp, Nonce
};
let key = Key::<BeltDwp>::generate();
let cipher = BeltDwp::new(&key);
let nonce = Nonce::generate(); // 128-bits; MUST be unique per message
let ciphertext = cipher.encrypt(&nonce, b"plaintext message".as_ref())?;
let plaintext = cipher.decrypt(&nonce, ciphertext.as_ref())?;
assert_eq!(&plaintext, b"plaintext message");§In-place Usage (eliminates alloc requirement)
This crate has an optional alloc feature which can be disabled in e.g.
microcontroller environments that don’t have a heap.
The AeadInOut::encrypt_in_place and AeadInOut::decrypt_in_place
methods accept any type that impls the aead::Buffer trait which
contains the plaintext for encryption or ciphertext for decryption.
Enabling the arrayvec feature of this crate will provide an impl of
aead::Buffer for arrayvec::ArrayVec (re-exported from the aead crate as
aead::arrayvec::ArrayVec).
It can then be passed as the buffer parameter to the in-place encrypt
and decrypt methods:
use belt_dwp::{
aead::{AeadInOut, Generate, Key, KeyInit, arrayvec::ArrayVec},
BeltDwp, Nonce
};
let key = Key::<BeltDwp>::generate();
let cipher = BeltDwp::new(&key);
let nonce = Nonce::generate(); // 128-bits; MUST be unique per message
let mut buffer: ArrayVec<u8, 128> = ArrayVec::new(); // Note: buffer needs 16-bytes overhead for auth tag
buffer.try_extend_from_slice(b"plaintext message").unwrap();
// Encrypt `buffer` in-place, replacing the plaintext contents with ciphertext
cipher.encrypt_in_place(&nonce, b"", &mut buffer)?;
// `buffer` now contains the message ciphertext
assert_ne!(buffer.as_ref(), b"plaintext message");
// Decrypt `buffer` in-place, replacing its ciphertext context with the original plaintext
cipher.decrypt_in_place(&nonce, b"", &mut buffer)?;
assert_eq!(buffer.as_ref(), b"plaintext message");Re-exports§
pub use aead;
Structs§
- Belt
Block - BelT block cipher.
- Dwp
belt-dwpauthenticated encryption with associated data (AEAD) cipher defined in STB 34.101.31-2020 generic over block cipher implementation and tag size.- Error
- Error type.
Traits§
- Aead
Core - Authenticated Encryption with Associated Data (AEAD) algorithm.
- Aead
InOut - In-place and inout AEAD trait which handles the authentication tag as a return value/separate parameter.
- KeyInit
- Types which can be initialized from a key.
- KeySize
User - Types which use key for initialization.