#encryption #aead #ascon

no-std ascon-aead

Implementation of the authenticated encryption schemes Ascon-AEAD128

16 unstable releases (5 breaking)

Uses new Rust 2024

0.6.0-pre.2 Dec 19, 2025
0.6.0-pre.1 Nov 3, 2025
0.5.2 Sep 22, 2025
0.5.1 Apr 21, 2025
0.1.0 Apr 28, 2021

#2888 in Cryptography

Download history 2507/week @ 2025-09-20 265/week @ 2025-09-27 790/week @ 2025-10-04 275/week @ 2025-10-11 2542/week @ 2025-10-18 2421/week @ 2025-10-25 97/week @ 2025-11-01 76/week @ 2025-11-08 168/week @ 2025-11-15 316/week @ 2025-11-22 770/week @ 2025-11-29 479/week @ 2025-12-06 2730/week @ 2025-12-13 3723/week @ 2025-12-20 1885/week @ 2025-12-27 659/week @ 2026-01-03

9,132 downloads per month
Used in 9 crates (5 directly)

Apache-2.0 OR MIT

64KB
686 lines

Ascon AEAD

Pure Rust implementation of the lightweight Authenticated Encryption with Associated Data (AEAD) algorithm Ascon-AEAD128.

Security Notes

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.

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.


lib.rs:

Usage

Simple usage (allocating, no associated data):

use ascon_aead::{AsconAead128, AsconAead128Key, AsconAead128Nonce, Key, Nonce};
use ascon_aead::aead::{Aead, KeyInit};

let key = AsconAead128Key::from_slice(b"very secret key.");
let cipher = AsconAead128::new(key);

// 128-bits; unique per message
let nonce = AsconAead128Nonce::from_slice(b"unique nonce 012");

let ciphertext = cipher.encrypt(nonce, b"plaintext message".as_ref())
    .expect("encryption failure!"); // NOTE: handle this error to avoid panics!

let plaintext = cipher.decrypt(nonce, ciphertext.as_ref())
    .expect("decryption failure!"); // NOTE: handle this error to avoid panics!

assert_eq!(&plaintext, b"plaintext message");

With randomly sampled keys and nonces (requires getrandom feature):

use ascon_aead::AsconAead128;
use ascon_aead::aead::{Aead, AeadCore, KeyInit};

let key = AsconAead128::generate_key()
    .expect("key generation failure"); // NOTE: handle this error to avoid panics!
let cipher = AsconAead128::new(&key);

// 128 bits; unique per message
let nonce = AsconAead128::generate_nonce()
    .expect("nonce generation failure"); // NOTE: handle this error to avoid panics!

let ciphertext = cipher.encrypt(&nonce, b"plaintext message".as_ref())
    .expect("encryption failure!"); // NOTE: handle this error to avoid panics!

let plaintext = cipher.decrypt(&nonce, ciphertext.as_ref())
    .expect("decryption failure!"); // NOTE: handle this error to avoid panics!

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), and enabling the bytes feature of this crate will provide an impl of aead::Buffer for bytes::BytesMut (re-exported from the aead crate as aead::bytes::BytesMut).

Truncated Tags

Ascon-AEAD128 also supports truncated tags ranging from 32 to 128 bits. Currently, only byte lengths are supported. Support for truncated tags is available via TruncatedAsconAEAD128.

use aead::consts::{U5};
use ascon_aead::{TruncatedAsconAead128, Key, Nonce};
use ascon_aead::aead::{Aead, KeyInit};

type TruncatedAscon = TruncatedAsconAead128<U5>;
let key = Key::<TruncatedAscon>::from_slice(b"very secret key.");
let cipher = TruncatedAscon::new(key);

// 128-bits; unique per message
let nonce = Nonce::<TruncatedAscon>::from_slice(b"unique nonce 012");

let ciphertext = cipher.encrypt(nonce, b"plaintext message".as_ref())
    .expect("encryption failure!"); // NOTE: handle this error to avoid panics!

let plaintext = cipher.decrypt(nonce, ciphertext.as_ref())
    .expect("decryption failure!"); // NOTE: handle this error to avoid panics!

assert_eq!(&plaintext, b"plaintext message");

Dependencies

~0.7–1.5MB
~34K SLoC