Skip to content

Commit 74a8154

Browse files
MarkAtwoodclaude
andcommitted
Fix ChaCha20-Poly1305 Final() to allow empty plaintext and AAD
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: #10040 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 922d04b commit 74a8154

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

wolfcrypt/src/chacha20_poly1305.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ int wc_ChaCha20Poly1305_Final(ChaChaPoly_Aead* aead,
275275
if (aead == NULL || outAuthTag == NULL) {
276276
return BAD_FUNC_ARG;
277277
}
278-
if (aead->state != CHACHA20_POLY1305_STATE_AAD &&
278+
if (aead->state != CHACHA20_POLY1305_STATE_READY &&
279+
aead->state != CHACHA20_POLY1305_STATE_AAD &&
279280
aead->state != CHACHA20_POLY1305_STATE_DATA) {
280281
return BAD_STATE_E;
281282
}

0 commit comments

Comments
 (0)