Associated Data Is Covered, Not Hidden
The associated data of an authenticated cipher is not encrypted and not part of the sealed value, but the tag covers it: the same key, nonce and message give the same ciphertext whatever the associated data is, and a different tag.
The question
An authenticated cipher has a fourth input beside the key, the nonce and the message: the associated data, for example a header that must be readable by everyone on the way and must still not be changed. How does the cipher treat it?
RFC 5116 section 2.1 calls it data "to be authenticated, but not encrypted". SP 800-38D section 5.2.1 says GCM protects the authenticity of the plaintext and the associated data and the confidentiality of the plaintext only. This lesson runs AES-128-GCM with three different associated data and compares what comes out. The key is test material.
Work it by hand
SP 800-38D section 7.1 (Algorithm 4) computes the ciphertext as C = GCTR_K(inc32(J0), P): a counter-mode encryption whose inputs are the key, the IV and the plaintext. The associated data A does not appear in that step. It enters only in the tag, through GHASH over A, the ciphertext and their lengths.
So seal the same message under the same key and nonce with the associated data hdr, other and nothing. The three ciphertexts should be the same bytes, since neither the key, the nonce nor the message changes. The three tags should differ, since the associated data does. A sealed value is as long as the message plus the tag, so the associated data is not inside it.
Run it
The program takes the key, the nonce, the message and three associated data texts, aad_a, aad_b and aad_c.
The loop of lines 8 to 19 seals the message once for each text with ssl.seal and the cipher name aes-128-gcm (line 9), cuts the sealed hex into ciphertext and tag (lines 10 to 12), counts a ciphertext the first time it is seen (lines 13 to 16) and adds a row with the first 12 hex digits of each part (lines 17 and 18). Line 20 returns the table and line 21 returns the number of distinct ciphertexts.

Public test material, generated for this lesson. Never use it for anything real.
let aads = str_list();
aads.add(aad_a);
aads.add(aad_b);
aads.add(aad_c);
let rows = str_list();
let seen = ",";
let distinct = 0;
for (i in range(0, 3)) {
let sealed = ssl.seal("aes-128-gcm", key, nonce, aads.at(i), message);
let cut = str_len(sealed) - 32;
let ct = str_substr(sealed, 0, cut);
let tag = str_substr(sealed, cut, 32);
if (str_find(seen, "," + ct + ",") < 0) {
distinct = distinct + 1;
seen = seen + ct + ",";
}
let label = "\"" + aads.at(i) + "\"";
rows.add(label + "|" + str_substr(ct, 0, 12) + "|" + str_substr(tag, 0, 12));
}
lmcode_return_put("rows", rows);
let answer = distinct;
{
"answer": 1,
"rows": [
"\"hdr\"|933a7a024924|b9b3ed94a54f",
"\"other\"|933a7a024924|e8153e8e3a4f",
"\"\"|933a7a024924|f067ebcdc098"
]
}You can change all six inputs. The key must be 16 bytes, otherwise line 9 stops with "Ssl.seal: key must be 16 bytes". An empty nonce stops line 9 with a message that starts "Ssl.seal: bad IV length"; the tool accepts other lengths, for example 2 or 16 bytes, but RFC 5116 section 5.1 specifies 12 bytes for AES-GCM, so keep 12. The message may be empty; the associated data may be any text, also empty.
Your turn
The program below is meant to return two numbers for two sealed values sealed_a and sealed_b of the same length, as hex: 1 or 0 for whether their ciphertext parts are equal, then 1 or 0 for whether their tags are equal. The last 16 bytes of a sealed value are its tag. Decide whether it does, and find the candidates that do. Check runs each candidate on the data shown and on five others.

Public test material, generated for this lesson. Never use it for anything real.
let a_cut = str_len(sealed_a) - 32;
let b_cut = str_len(sealed_b) - 32;
let ct_a = str_substr(sealed_a, 0, a_cut);
let ct_b = str_substr(sealed_b, 0, b_cut);
let tag_a = str_substr(sealed_a, a_cut, 32);
let tag_b = str_substr(sealed_b, b_cut, 32);
let ct = 0;
if (ct_a == ct_b) { ct = 1; }
let tg = 0;
if (tag_a == tag_b) { tg = 1; }
let answer = int_list();
answer.add(tg);
answer.add(ct);
{
"answer": [
0,
1
]
}sealed_a and sealed_b are the hex text of two values made by ssl.seal with aes-128-gcm, of the same length. The last 16 bytes of each are its tag; the bytes before are its ciphertext. Return a list of two numbers: 1 if the ciphertext parts are equal and 0 if not, then 1 if the tags are equal and 0 if not. Check runs each candidate on the data shown and on five others.
Read the result carefully
The associated data is readable by anyone who sees it; here it never travels in the sealed value, and a receiver needs it to open the value. The tag shows that the data was present when the value was sealed, and nothing else. Empty associated data is still an input: in the run above the tag with nothing differs from the tags with hdr and other.
The page does not show what a receiver does when the associated data is wrong; the next lessons show that the value is refused. The key and the nonce are test material, and the program stops with the engine's message when their sizes are wrong.
Recap
- The ciphertext of AES-GCM depends on key, nonce and plaintext, not on the associated data (SP 800-38D, section 7.1).
- The tag depends on the associated data as well: change it and the tag changes.
- The associated data is authenticated, not encrypted, and is not part of the sealed value.
- Equal ciphertext parts with different tags mean the same message under different associated data.