Skip to main content

Module aead

Module aead 

Source
Expand description

Authenticated encryption with detached authentication tags.

This module wraps BoringSSL’s EVP_AEAD interface and is intended for protocols that keep ciphertext and authentication tag in separate buffers.

§Overview

AeadCtx is the main type. Create one with an Algorithm and a key, then use it to encrypt and decrypt:

§When to use crate::symm instead

If you want one-shot helpers that allocate output buffers or APIs centered on EVP_CIPHER, prefer crate::symm, including crate::symm::encrypt_aead and crate::symm::decrypt_aead.

§Nonce guidance

Never reuse a nonce with the same key. Nonce reuse can completely undermine AEAD security.

Nonces are usually public (not secret). They must either be transmitted with the message or derived by both sides (for example from a shared sequence number).

Different algorithms can have different nonce-length requirements and safety considerations around nonce generation. The caller is responsible for following safe nonce practices for the selected algorithm. Algorithm::nonce_len returns the required nonce size in bytes.

§Example

use boring::aead::{AeadCtx, Algorithm};

let algorithm = Algorithm::aes_128_gcm();
let ctx = AeadCtx::new_default_tag(&algorithm, &[0u8; 16]).unwrap();
let nonce = [0u8; 12];
let aad = b"record-header";
let mut payload = b"hello world".to_vec();
let mut tag = vec![0u8; algorithm.max_overhead()];

ctx.seal_in_place(&nonce, payload.as_mut_slice(), &mut tag, aad)
    .unwrap();

ctx.open_in_place(&nonce, payload.as_mut_slice(), &tag, aad)
    .unwrap();

assert_eq!(payload.as_slice(), b"hello world");

Structs§

AeadCtx
An AEAD encryption/decryption context wrapping BoringSSL’s EVP_AEAD_CTX.
AeadCtxRef
A borrowed reference to a AeadCtx.
Algorithm
Represents a specific AEAD algorithm.