Skip to content

Rust implementation of grain-128AEADv2 compatible with rustcrypto projet.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

acmo0/grain-128AEADv2

Repository files navigation

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.

It works without standard library and even without allocator if your disable the vec default feature

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 additional data",
    b"this is a secret message"
);

let plaintext = cipher.decrypt_aead(
    &nonce,
    b"Some additional 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.

About

Rust implementation of grain-128AEADv2 compatible with rustcrypto projet.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages