[][src]Trait aead::Aead

pub trait Aead {
    type NonceSize: ArrayLength<u8>;
    type TagSize: ArrayLength<u8>;
    type CiphertextOverhead: ArrayLength<u8> + Unsigned;
    fn encrypt<'msg, 'aad>(
        &self,
        nonce: &Nonce<Self::NonceSize>,
        plaintext: impl Into<Payload<'msg, 'aad>>
    ) -> Result<Vec<u8>, Error>;
fn decrypt<'msg, 'aad>(
        &self,
        nonce: &Nonce<Self::NonceSize>,
        ciphertext: impl Into<Payload<'msg, 'aad>>
    ) -> Result<Vec<u8>, Error>; }
This is supported on feature="alloc" only.

Authenticated Encryption with Associated Data (AEAD) algorithm.

This trait is intended for use with stateless AEAD algorithms. The AeadMut trait provides a stateful interface.

Associated Types

type NonceSize: ArrayLength<u8>

This is supported on feature="alloc" only.

The length of a nonce.

type TagSize: ArrayLength<u8>

This is supported on feature="alloc" only.

The maximum length of the nonce.

type CiphertextOverhead: ArrayLength<u8> + Unsigned

This is supported on feature="alloc" only.

The upper bound amount of additional space required to support a ciphertext vs. a plaintext.

Loading content...

Required methods

fn encrypt<'msg, 'aad>(
    &self,
    nonce: &Nonce<Self::NonceSize>,
    plaintext: impl Into<Payload<'msg, 'aad>>
) -> Result<Vec<u8>, Error>

This is supported on feature="alloc" only.

Encrypt the given plaintext payload, and return the resulting ciphertext as a vector of bytes.

The Payload type can be used to provide Additional Associated Data (AAD) along with the message: this is an optional bytestring which is not encrypted, but is authenticated along with the message. Failure to pass the same AAD that was used during encryption will cause decryption to fail, which is useful if you would like to "bind" the ciphertext to some other identifier, like a digital signature key or other identifier.

If you don't care about AAD and just want to encrypt a plaintext message, &[u8] will automatically be coerced into a Payload:

let plaintext = b"Top secret message, handle with care";
let ciphertext = cipher.encrypt(nonce, plaintext);

The default implementation assumes a postfix tag (ala AES-GCM, AES-GCM-SIV, ChaCha20Poly1305). Aead implementations which do not use a postfix tag will need to override this to correctly assemble the ciphertext message.

fn decrypt<'msg, 'aad>(
    &self,
    nonce: &Nonce<Self::NonceSize>,
    ciphertext: impl Into<Payload<'msg, 'aad>>
) -> Result<Vec<u8>, Error>

This is supported on feature="alloc" only.

Decrypt the given ciphertext slice, and return the resulting plaintext as a vector of bytes.

See notes on Aead::encrypt() about allowable message payloads and Associated Additional Data (AAD).

If you have no AAD, you can call this as follows:

let ciphertext = b"...";
let plaintext = cipher.decrypt(nonce, ciphertext)?;

The default implementation assumes a postfix tag (ala AES-GCM, AES-GCM-SIV, ChaCha20Poly1305). Aead implementations which do not use a postfix tag will need to override this to correctly parse the ciphertext message.

Loading content...

Implementors

impl<Alg: AeadInPlace> Aead for Alg[src]

type NonceSize = Alg::NonceSize

This is supported on feature="alloc" only.

type TagSize = Alg::TagSize

This is supported on feature="alloc" only.

type CiphertextOverhead = Alg::CiphertextOverhead

This is supported on feature="alloc" only.
Loading content...