Skip to content

Fix HPKE decryption ciphertext length validation#14391

Merged
reaperhulk merged 1 commit intomainfrom
claude/fix-hpke-ciphertext-length-mnYTq
Feb 27, 2026
Merged

Fix HPKE decryption ciphertext length validation#14391
reaperhulk merged 1 commit intomainfrom
claude/fix-hpke-ciphertext-length-mnYTq

Conversation

@alex
Copy link
Member

@alex alex commented Feb 27, 2026

Summary

This PR fixes the ciphertext length validation in HPKE decryption to account for the authentication tag size.

Key Changes

  • Added AES_128_GCM_NT constant (16 bytes) to aead_params module to represent the AES-128-GCM authentication tag length
  • Updated the ciphertext length check in Suite::decrypt() to validate that the ciphertext is at least X25519_NENC + AES_128_GCM_NT bytes, rather than just X25519_NENC bytes

Details

The previous validation was insufficient as it only checked for the encapsulated key size but did not account for the authentication tag that must be present in the ciphertext. This could allow invalid ciphertexts to pass the length check and potentially cause issues during decryption. The fix ensures the ciphertext contains both the encapsulated key and the authentication tag before attempting decryption.

https://claude.ai/code/session_01EGLxxnHUgfiStRV9BzFJxo

The minimum ciphertext length check only validated against X25519_NENC
(32 bytes) but didn't account for the 16-byte AES-GCM authentication
tag. This allowed 32-47 byte ciphertexts to pass the early check and
proceed through the full DH exchange and HKDF key schedule before
AES-GCM correctly rejected them. Add AES_128_GCM_NT constant and
include it in the check to avoid wasted computation on trivially
invalid inputs.

https://claude.ai/code/session_01EGLxxnHUgfiStRV9BzFJxo
@reaperhulk reaperhulk merged commit c3deb39 into main Feb 27, 2026
67 checks passed
@reaperhulk reaperhulk deleted the claude/fix-hpke-ciphertext-length-mnYTq branch February 27, 2026 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants