Skip to content

Allow setAuthTag() after update() for GCM Decipheriv - #8392

Merged
jasnell merged 1 commit into
mainfrom
littledivy/2026-11-12-gcm-late-auth-tag
Nov 12, 2026
Merged

jasnell merged 1 commit into
mainfrom
littledivy/2026-11-12-gcm-late-auth-tag

Conversation

@littledivy

Copy link
Copy Markdown
Member

A node:crypto GCM Decipheriv threw No auth tag provided from update() unless setAuthTag() had been called first. Node only needs the tag before final() for GCM, so streaming decryption, where the tag arrives last, failed. ssh2's aes*-gcm@openssh.com does this, so GCM SSH connections from a Worker failed on the first encrypted packet. Fixes #8123.

In this patch:

  • update() passes the auth tag to BoringSSL only if it has already been set. final() already passes it when update() didn't, and still throws No auth tag provided if it was never set.
  • CCM still requires the tag before any data, since that mode checks it during update().
before after
update(ct), then setAuthTag(tag), then final() throws No auth tag provided decrypts
same with a wrong tag throws No auth tag provided final() throws Authentication failed
update(ct), then final() with no tag throws No auth tag provided final() throws No auth tag provided

This only lets a call order that used to throw work as it does in Node, so it has no compatibility flag. chacha20-poly1305 goes through the one-shot EVP_AEAD path and still needs the tag before its single update().

A node:crypto GCM Decipheriv threw "No auth tag provided" from
update() unless setAuthTag() had been called first. Node only needs
the tag before final() for GCM, so streaming decryption, where the tag
arrives last, failed. ssh2's aes*-gcm@openssh.com does this, so GCM SSH
connections from a Worker failed on the first encrypted packet.

In this patch:

- update() passes the auth tag to BoringSSL only if it has already
  been set. final() already passes it when update() didn't, and still
  throws "No auth tag provided" if it was never set.
- CCM still requires the tag before any data, since that mode checks
  it during update().

This only lets a call order that used to throw work as it does in
Node, so it has no compatibility flag. chacha20-poly1305 goes through
the one-shot EVP_AEAD path and still needs the tag before its single
update().

Fixes #8123
@littledivy
littledivy requested review from a team as code owners November 12, 2026 12:38

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved — Small, well-scoped fix that matches Node's GCM behaviour. CCM keeps its early tag check, final() still requires a tag, and tests cover the new call orders.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

📋 Code Quality: ✅ LGTM

No issues found.

  • update(): passes the auth tag only if it has been set. Without one, CCM still throws No auth tag provided, and GCM goes ahead.
  • final(): passes the tag if update() didn't, and throws No auth tag provided if no tag was ever set.
  • Tests: they cover the late-tag, wrong-tag and missing-tag cases for the AES-GCM variants.

📝 Documentation: ✅ LGTM

No documentation issues. The new code comment accurately describes the CCM and GCM tag requirements.


Reviewed commit: 4107c4a8

@jasnell
jasnell merged commit ed4256a into main Nov 12, 2026
23 checks passed
@jasnell
jasnell deleted the littledivy/2026-11-12-gcm-late-auth-tag branch November 12, 2026 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug Report — Runtime APIs: node:crypto GCM decipher requires setAuthTag() before update(); Node allows it any time before final()

2 participants