grain-128aeadv2

Crates.iograin-128aeadv2
lib.rsgrain-128aeadv2
version0.1.2
created_at2025-12-09 17:21:53.845297+00
updated_at2025-12-12 21:19:56.771421+00
descriptionImplementation of Grain-128AEADv2 stream cipher.
homepage
repositoryhttps://github.com/acmo0/grain-128aeadv2/
max_upload_size
id1975796
size96,682
(acmo0)

documentation

https://docs.rs/grain-128aeadv2

README

Grain-128AEADv2

Crates.io Total Downloads Crates.io Version

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.

Security Notes

[!CAUTION] No security audits of this crate have ever been performed. USE AT YOUR OWN RISK!

Minimum Supported Rust Version

This crate requires Rust 1.85 at a minimum.

Quickstart

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");

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.

Commit count: 0

cargo fmt