Skip to main content

AsconAead128

Struct AsconAead128 

Source
pub struct AsconAead128 { /* private fields */ }
Expand description

Ascon-AEAD128 authenticated encryption with associated data (NIST SP 800-232).

§Parameters

  • Key: 128 bits (16 bytes)
  • Nonce: 128 bits (16 bytes)
  • Tag: 128 bits (16 bytes)
  • Rate: 128 bits, capacity: 192 bits
  • Initialization/finalization rounds: 12
  • Data processing rounds: 8

§Example

use crypto::{Aead, ascon::AsconAead128};

let key = [0x42u8; 16];
let nonce = [0xABu8; 16];
let aad = b"example metadata";
let plaintext = b"hello, world!";

let cipher = AsconAead128::new(&key);

let mut ct = plaintext.to_vec();
let tag = cipher.encrypt_in_place(&mut ct, &nonce, aad);

let mut pt = ct.clone();
cipher.decrypt_in_place(&mut pt, &nonce, aad, tag.as_ref()).unwrap();
assert_eq!(&pt, plaintext);

§Usage limits (NIST SP 800-232 §4.3)

  • Max data per key: 2^54 bytes
  • Nonces must be distinct per key (up to 2^8 repetitions tolerated)
  • Max decryption failures: 2^(tag_len - 32) before key rotation

Implementations§

Source§

impl AsconAead128

Source

pub fn new(key: &[u8; 16]) -> Self

Creates a new Ascon-AEAD128 instance from a 16-byte key.

Trait Implementations§

Source§

impl Aead for AsconAead128

Source§

const TAG_SIZE: usize = 16

Source§

const NONCE_SIZE: usize = 16

Source§

fn encrypt_in_place(&self, in_out: &mut [u8], nonce: &[u8], aad: &[u8]) -> Hash

Source§

fn decrypt_in_place( &self, in_out: &mut [u8], nonce: &[u8], aad: &[u8], tag: &[u8], ) -> Result<(), AeadError>

Source§

fn encrypt(&self, plaintext: &[u8], nonce: &[u8], aad: &[u8]) -> Vec<u8>

Source§

fn decrypt( &self, ciphertext: &[u8], nonce: &[u8], aad: &[u8], ) -> Result<Vec<u8>, AeadError>

Source§

impl Drop for AsconAead128

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Zeroize for AsconAead128

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Zeroize for T
where T: Zeroize,