Authenticated encryption and associated data
Three different guarantees
Confidentiality hides message contents; integrity detects changes; authenticity establishes an origin within a trust model. Authenticated encryption with associated data (AEAD) combines confidentiality of plaintext with integrity and authentication of both plaintext and associated data. A shared secret authenticates a key holder, not necessarily a particular person. For example, an encrypted invoice can bind its nonsecret record identifier as associated data (AAD).
Use an established API
AES-GCM and ChaCha20-Poly1305 are established AEAD choices, subject to policy and platform support. In Python cryptography 46.0.4, AESGCM.encrypt(nonce, data, associated_data) returns bytes containing ciphertext and a 16-byte tag; decrypt takes the same nonce and AAD. AESGCM accepts 16, 24 or 32-byte keys; ChaCha20Poly1305 uses 32 bytes. Use the documented 12-byte nonce profile and enforce uniqueness per key. AAD is not hidden.
A local round trip
Run this once in the reviewed local library environment. A fresh key is used for this single encryption, and the expected output is True. This is not a storage format or protocol.
from cryptography.hazmat.primitives.ciphers.aead import AESGCMfrom secrets import token_bytesbox = AESGCM(AESGCM.generate_key(bit_length=128))nonce = token_bytes(12)aad = b"invoice-42"ct = box.encrypt(nonce, b"paid", aad)print(box.decrypt(nonce, ct, aad) == b"paid")Reject invalid authentication
Changing the invoice identifier or ciphertext must result in authentication failure, not a partially trusted record. The library raises InvalidTag for a failed tag check. Return a generic failure, discard output, do not log keys or plaintext, and investigate unexpected failures. AEAD does not independently prevent replay; a reviewed protocol must handle freshness. Do not retry with unauthenticated encryption.
Practice with a known vector
The lab includes RFC 8439 section 2.8.2 ciphertext and tag with a public test key. Verify the exact bytes with the vetted library, then reject the supplied changed tag and AAD cases. A fixed public nonce/key is exclusively for this vector, never a deployment. Reference: authenticated encryption and associated data.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Authenticated encryption and associated data — knowledge check
Apply cryptographic library principles to fictional scenarios.
What does AAD protect?
A changed ciphertext produces InvalidTag. What next?
Which is an AEAD construction?
What is not guaranteed by AEAD alone?
Where may the public vector key be used?