Skip to content

Commit 76e5415

Browse files
committed
test: update ChaCha20-Poly1305 bad-state test for empty-plaintext fix
Replace the READY-state BAD_STATE_E assertion (which the fix renders obsolete) with a positive Wycheproof tc2 test: empty plaintext + empty AAD through the streaming API must produce the correct authentication tag per RFC 8439 Section 2.8.
1 parent 5e899a1 commit 76e5415

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

wolfcrypt/test/test.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10766,6 +10766,22 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha20_poly1305_aead_test(void)
1076610766
0x39, 0x23, 0x36, 0xfe, 0xa1, 0x85, 0x1f, 0x38
1076710767
};
1076810768

10769+
/* Wycheproof tc2: empty plaintext + empty AAD (valid per RFC 8439 §2.8) */
10770+
WOLFSSL_SMALL_STACK_STATIC const byte key_tc2[] = {
10771+
0x80, 0xba, 0x31, 0x92, 0xc8, 0x03, 0xce, 0x96,
10772+
0x5e, 0xa3, 0x71, 0xd5, 0xff, 0x07, 0x3c, 0xf0,
10773+
0xf4, 0x3b, 0x6a, 0x2a, 0xb5, 0x76, 0xb2, 0x08,
10774+
0x42, 0x6e, 0x11, 0x40, 0x9c, 0x09, 0xb9, 0xb0
10775+
};
10776+
WOLFSSL_SMALL_STACK_STATIC const byte iv_tc2[] = {
10777+
0x4d, 0xa5, 0xbf, 0x8d, 0xfd, 0x58, 0x52, 0xc1,
10778+
0xea, 0x12, 0x37, 0x9d
10779+
};
10780+
WOLFSSL_SMALL_STACK_STATIC const byte authTag_tc2[] = {
10781+
0x76, 0xac, 0xb3, 0x42, 0xcf, 0x31, 0x66, 0xa5,
10782+
0xb6, 0x3c, 0x0c, 0x0e, 0xa1, 0x38, 0x3c, 0x8d
10783+
};
10784+
1076910785
byte generatedCiphertext[265]; /* max plaintext2/cipher2 */
1077010786
byte generatedPlaintext[265]; /* max plaintext2/cipher2 */
1077110787
byte generatedAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];
@@ -10969,10 +10985,16 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha20_poly1305_aead_test(void)
1096910985
err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
1097010986
if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
1097110987
return WC_TEST_RET_ENC_EC(err);
10972-
aead.state = CHACHA20_POLY1305_STATE_READY;
10988+
/* Wycheproof tc2: empty plaintext + empty AAD must succeed (RFC 8439 §2.8) */
10989+
err = wc_ChaCha20Poly1305_Init(&aead, key_tc2, iv_tc2,
10990+
CHACHA20_POLY1305_AEAD_ENCRYPT);
10991+
if (err != 0)
10992+
return WC_TEST_RET_ENC_EC(err);
1097310993
err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
10974-
if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
10994+
if (err != 0)
1097510995
return WC_TEST_RET_ENC_EC(err);
10996+
if (XMEMCMP(generatedAuthTag, authTag_tc2, sizeof(authTag_tc2)) != 0)
10997+
return WC_TEST_RET_ENC_NC;
1097610998

1097710999
XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
1097811000
XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));

0 commit comments

Comments
 (0)