Skip to content

Fix ChaCha20-Poly1305 Final() to allow empty plaintext and AAD#10046

Open
MarkAtwood wants to merge 1 commit intowolfSSL:masterfrom
MarkAtwood:fix/chacha20poly1305-empty-plaintext
Open

Fix ChaCha20-Poly1305 Final() to allow empty plaintext and AAD#10046
MarkAtwood wants to merge 1 commit intowolfSSL:masterfrom
MarkAtwood:fix/chacha20poly1305-empty-plaintext

Conversation

@MarkAtwood
Copy link

Summary

  • wc_ChaCha20Poly1305_Final() rejected CHACHA20_POLY1305_STATE_READY with BAD_STATE_E, which occurs when neither UpdateAad nor UpdateData has been called (both AAD and plaintext are empty)
  • RFC 8439 Section 2.8 permits this and produces a well-defined authentication tag
  • Affects both the streaming API and the one-shot wc_ChaCha20Poly1305_Encrypt/Decrypt functions which call through it

Fixes #10040

Test plan

  • Verify existing ChaCha20-Poly1305 tests still pass
  • Confirm empty plaintext + empty AAD produces correct authentication tag
  • Verify Wycheproof test vectors tc 2 and tc 3 pass through the streaming API

🤖 Generated with Claude Code

wc_ChaCha20Poly1305_Final() rejected CHACHA20_POLY1305_STATE_READY
with BAD_STATE_E, which occurs when neither UpdateAad nor UpdateData
has been called (both AAD and plaintext are empty). RFC 8439 Section
2.8 permits this and produces a well-defined authentication tag.

Add CHACHA20_POLY1305_STATE_READY to the allowed states in Final().
When state is READY, aadLen and dataLen are both 0, so the existing
Poly1305_Pad, Poly1305_EncodeSizes, and Poly1305Final calls produce
the correct tag.

Fixes: wolfSSL#10040

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 23, 2026 15:13
Copy link
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

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

Many of the CI tests are failing now:

ChaCha20-Poly1305 AEAD test failed!
 error L=10590 code=0 (ok)
 [fiducial line numbers: 11340 31712 53140 66641]
Exiting main with return code: -1

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the ChaCha20-Poly1305 streaming finalization logic to permit generating an authentication tag when both plaintext and AAD are empty, aligning behavior with RFC 8439 and fixing the reported BAD_STATE_E error path.

Changes:

  • Allow wc_ChaCha20Poly1305_Final() to accept the CHACHA20_POLY1305_STATE_READY state (no prior AAD/data updates).
  • Preserve existing state validation for AAD and DATA states while continuing to reject other invalid states.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #10046

Scan targets checked: wolfcrypt-bugs, wolfcrypt-src

No new issues found in the changed files. ✅

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.

wc_ChaCha20Poly1305_Final rejects valid empty-plaintext + empty-AAD input (BAD_STATE_E)

5 participants