Skip to main content

Aead

Trait Aead 

Source
pub trait Aead {
    type Tag: AsRef<[u8]>;
    type Nonce: AsRef<[u8]>;

    // Required methods
    fn seal(&self, nonce: &Self::Nonce, plaintext: &[u8], ad: &[u8]) -> Vec<u8>;
    fn seal_in_place(
        &self,
        nonce: &Self::Nonce,
        plaintext: &mut [u8],
        ad: &[u8],
    ) -> Self::Tag;
    fn open(
        &self,
        nonce: &Self::Nonce,
        ciphertext: &[u8],
        ad: &[u8],
    ) -> Option<Vec<u8>>;
    fn open_in_place(
        &self,
        nonce: &Self::Nonce,
        ciphertext: &mut [u8],
        tag: &Self::Tag,
        ad: &[u8],
    ) -> Result<(), InvalidCiphertext>;
}
Expand description

Authenticated Encryption with Associated Data (AEAD) algorithm trait.

Required Associated Types§

Source

type Tag: AsRef<[u8]>

The type of tags produced by this AEAD. Generally a u8 array of fixed length.

Source

type Nonce: AsRef<[u8]>

The type of nonces used by this AEAD. Generally a u8 array of fixed length.

Required Methods§

Source

fn seal(&self, nonce: &Self::Nonce, plaintext: &[u8], ad: &[u8]) -> Vec<u8>

Encrypt and authenticate plaintext, and authenticate ad, returning the result as a freshly allocated Vec. The nonce must never be used in any sealing operation with the same key, ever again.

Source

fn seal_in_place( &self, nonce: &Self::Nonce, plaintext: &mut [u8], ad: &[u8], ) -> Self::Tag

Encrypt and authenticate plaintext, and authenticate ad, writing the ciphertext over plaintext and additionally returning the calculated tag, which is usually appended to the ciphertext. The nonce must never be used in any sealing operation with the same key, ever again.

Source

fn open( &self, nonce: &Self::Nonce, ciphertext: &[u8], ad: &[u8], ) -> Option<Vec<u8>>

Authenticate ciphertext and ad and, if valid, decrypt ciphertext, returning the original plaintext in a newly allocated Vec. The nonce must be the same value as given to the sealing operation that produced ciphertext.

Source

fn open_in_place( &self, nonce: &Self::Nonce, ciphertext: &mut [u8], tag: &Self::Tag, ad: &[u8], ) -> Result<(), InvalidCiphertext>

Authenticate ciphertext and ad using tag and, if valid, decrypt ciphertext in place. The nonce must be the same value as given to the sealing operation that produced ciphertext.

Implementors§