Skip to content

Fix missing tag_size entry for sm4-128-gcm causing zero tag for chacha20/xchacha20 AEAD ciphers#3044

Open
Copilot wants to merge 2 commits into
masterfrom
copilot/fix-code-for-review-comment
Open

Fix missing tag_size entry for sm4-128-gcm causing zero tag for chacha20/xchacha20 AEAD ciphers#3044
Copilot wants to merge 2 commits into
masterfrom
copilot/fix-code-for-review-comment

Conversation

Copilot AI commented Jun 28, 2026

Copy link
Copy Markdown

When sm4-128-gcm was inserted at index 3 in the AEAD cipher tables and AEAD_CIPHER_NUM was bumped, supported_aead_ciphers_tag_size was left with only 4 entries. With 5 ciphers but 4 tag-size entries, chacha20-ietf-poly1305 (now index 4) and xchacha20-ietf-poly1305 (index 5) silently got a zero tag size — breaking authentication tag append/verify for those ciphers entirely.

Changes

  • src/aead.hAEAD_CIPHER_NUM 4→5 (5→6 with xchacha)
  • src/aead.c
    • Add #define SM4128GCM 3; renumber CHACHA20POLY1305IETF to 4, XCHACHA20POLY1305IETF to 5
    • Add "sm4-128-gcm" / "SM4-128-GCM" to name tables
    • Fix supported_aead_ciphers_tag_size — add missing entry so all 5 slots are populated:
      // Before (4 entries, AEAD_CIPHER_NUM=5 → chacha20 tag_size=0):
      static const int supported_aead_ciphers_tag_size[AEAD_CIPHER_NUM] = {
          16, 16, 16, 16,
      };
      // After:
      static const int supported_aead_ciphers_tag_size[AEAD_CIPHER_NUM] = {
          16, 16, 16, 16, 16,  // aes-128, aes-192, aes-256, sm4-128, chacha20
      };
    • Update nonce/key size tables; add SM4128GCM case to encrypt/decrypt switches
  • src/stream.hSTREAM_CIPHER_NUM 21→23
  • src/stream.c — Add SM4_128_CBC (index 13) and SM4_128_CTR (index 14); shift existing defines; populate mbedTLS name, nonce, and key size arrays
  • src/utils.c — Add SM4 ciphers to usage() output

… in AEAD cipher table

PR #2424 review comment fix: supported_aead_ciphers_tag_size was not updated
when sm4-128-gcm was added, causing chacha20-ietf-poly1305 and xchacha20-ietf-poly1305
to receive a zero tag size, breaking AEAD encryption/decryption.
Copilot AI changed the title [WIP] Fix code based on review comment Fix missing tag_size entry for sm4-128-gcm causing zero tag for chacha20/xchacha20 AEAD ciphers Jun 28, 2026
Copilot AI requested a review from madeye June 28, 2026 09:50
@madeye madeye marked this pull request as ready for review June 28, 2026 10:50
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.

2 participants