Authenticated Encryption with Associated Data
Authenticated encryption with associated data (AEAD) is a cryptographic operation that encrypts a message while detecting changes to it and to selected data that remains readable. The readable data is called associated data: for example, a protocol version, record type, or HTTP-like header.
AEAD produces two important outputs: ciphertext, which hides the plaintext, and an authentication tag, a short value used to detect tampering. It also takes a nonce, a value that must not be reused with the same key.
The problem AEAD solves
Encryption alone provides confidentiality: someone who intercepts the ciphertext should not be able to read the plaintext. But encryption by itself does not necessarily provide integrity. An attacker may be able to alter ciphertext and cause the decrypted result to change in a useful or dangerous way, without knowing the key.
A separate integrity check can detect changes, but systems then have to compose encryption and authentication correctly. They also need to authenticate information that must remain visible to intermediaries. Encrypting every field is often impractical: routers, protocol handlers, and storage systems may need to inspect a record type or version before processing the hidden body.
AEAD handles these needs as one operation:
- Plaintext is encrypted into ciphertext.
- The ciphertext is checked for modification.
- Associated data is checked for modification but is not encrypted.
- Decryption fails if any checked input is wrong.
This is why AEAD appears in modern protocol stacks and libraries, often through names such as AES-GCM or ChaCha20-Poly1305.
Confidentiality hides the message. Integrity makes alteration detectable. AEAD provides both, but it does not by itself prevent replaying an old, valid message.
The inputs and outputs
An AEAD encryption operation uses a secret key, the plaintext, a nonce, and optional associated data. The key is shared by the parties that need to encrypt or decrypt; it must remain secret.
The nonce is a per-message value that helps make each encryption invocation distinct. It usually does not need to be secret, so a sender can transmit it alongside the ciphertext. “Nonce” means “number used once,” and that name is a requirement, not merely a suggestion: for a given key, the same nonce must not be used twice.
Associated data is supplied as exact bytes. It might contain a record number, protocol version, content type, or unencrypted header. AEAD includes those bytes when calculating the authentication tag, but does not put them through the encryption step. A receiver needs the same associated data bytes to verify the message.
The result is typically:
nonce, ciphertext, authentication tag
The nonce and tag are not secret. The key is. The associated data is normally sent or stored separately because its purpose is to remain readable.
What encryption and decryption do
Conceptually, encryption looks like this:
ciphertext, tag = AEAD_Encrypt(key, nonce, plaintext, associated_data)
The algorithm uses the key and nonce to transform the plaintext into ciphertext. It also computes a tag over the ciphertext and the associated data. The tag binds those values together: changing either the hidden body or the readable headers should make verification fail.
Decryption takes all of the corresponding values:
plaintext = AEAD_Decrypt(key, nonce, ciphertext, tag, associated_data)
The receiver first verifies the tag. Only if verification succeeds should it accept the plaintext. An invalid tag means that the ciphertext, tag, associated data, nonce, or key is wrong—or that somebody modified the message. The application should treat this as a failed message, not as a request to continue with partially decrypted bytes.
This also explains a common integration failure. If one side authenticates a header as type:request and the other reconstructs it with different bytes, different capitalization, whitespace, encoding, or field ordering, verification fails. Associated data is not “whatever looks equivalent”; both sides must agree on its exact representation.
Why nonce reuse is dangerous
AEAD’s guarantees depend on nonce uniqueness under the same key. Reusing a nonce can break confidentiality, integrity, or both. It is not enough that the nonce be unpredictable; it must also not collide.
Many encryption modes generate ciphertext using a key-and-nonce-derived stream. If the same stream is used for two plaintexts, an attacker can combine the ciphertexts to cancel the stream and learn the relationship between the plaintexts. In simplified form, if ciphertexts are produced by XORing plaintexts with the same keystream:
ciphertext1 XOR ciphertext2 = plaintext1 XOR plaintext2
That may reveal information directly, especially when one plaintext has predictable structure. It can also help recover portions of messages when an attacker knows or guesses one of them.
Nonce reuse can be even worse for the authentication part. In AES-GCM, repeated nonces expose relationships in the authentication calculations and can allow an attacker to construct valid-looking tags after collecting suitable messages. The exact consequences depend on the algorithm and the messages, but the important engineering rule is simple: never reuse a nonce with a key. Treat a nonce failure as a key-compromise-level incident for the affected data, not as a minor formatting bug.
Managing nonces in real systems
A counter is often safer than independently generated random nonces: persist or coordinate the counter so that workers and restarts cannot produce the same value under one key. Random nonces can work when they are long enough and collision risk is explicitly managed, but “random” does not prove uniqueness—especially across processes, machines, or restored snapshots.
The nonce should travel with each encrypted record, and the protocol should specify its size, construction, and ownership. Key rotation can limit the amount of data exposed by an operational mistake, but it does not make accidental reuse acceptable.
AEAD also does not authenticate a sender’s identity by itself. Anyone holding the key can create valid messages, and anyone who can replay a valid message can replay it unless the protocol adds sequence numbers, expiration, or other replay defenses. AEAD supplies a strong building block: hidden plaintext, tamper detection, and tamper detection for readable associated data—provided the key is protected and each nonce is used only once.