| Crates.io | grain-128aeadv2 |
| lib.rs | grain-128aeadv2 |
| version | 0.1.2 |
| created_at | 2025-12-09 17:21:53.845297+00 |
| updated_at | 2025-12-12 21:19:56.771421+00 |
| description | Implementation of Grain-128AEADv2 stream cipher. |
| homepage | |
| repository | https://github.com/acmo0/grain-128aeadv2/ |
| max_upload_size | |
| id | 1975796 |
| size | 96,682 |
Efficient pure Rust implementation of Grain-128AEADv2.
Please see installation details and doc on crates.io.
Pure Rust implementation of Grain-128AEADv2, a lightweight stream cipher.
[!CAUTION] No security audits of this crate have ever been performed. USE AT YOUR OWN RISK!
This crate requires Rust 1.85 at a minimum.
With randomly sampled keys and nonces (requires getrandom feature):
use grain_128aeadv2::{Grain128, aead::{Aead, AeadCore, KeyInit}};
let key = Grain128::generate_key().expect("Unable to generate key");
let cipher = Grain128::new(&key);
// A nonce must be USED ONLY ONCE !
let nonce = Grain128::generate_nonce().expect("Unable to generate nonce");
let (ciphertext, tag) = cipher.encrypt_aead(
&nonce,
b"Some additionnal data",
b"this is a secret message"
);
let plaintext = cipher.decrypt_aead(
&nonce,
b"Some additionnal data",
&ciphertext,
&tag
).expect("Tag verification failed");
assert_eq!(&plaintext, b"this is a secret message");
In-place encryption (requires alloc feature) :
use grain_128aeadv2::{
Grain128, Key, Nonce,
aead::{AeadCore, AeadInOut, KeyInit, arrayvec::ArrayVec}
};
let key = Grain128::generate_key().expect("Unable to generate key");
let cipher = Grain128::new(&key);
// A nonce must be USED ONLY ONCE !
let nonce = Grain128::generate_nonce().expect("Unable to generate nonce");
// Take care : 8 bytes overhead to store the tag
let mut buffer: Vec<u8> = vec![];
buffer.extend_from_slice(b"a secret message");
// Perform in place encryption inside 'buffer'
cipher.encrypt_in_place(&nonce, b"Some AD", &mut buffer).expect("Unable to encrypt");
// Perform in place decryption
cipher.decrypt_in_place(&nonce, b"Some AD", &mut buffer).expect("Tag verification failed");
assert_eq!(&buffer, b"a secret message");
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.