[kem] Reject invalid hybrid key lengths without panicking - #1560
Draft
bshastry wants to merge 3 commits into
Draft
[kem] Reject invalid hybrid key lengths without panicking#1560bshastry wants to merge 3 commits into
bshastry wants to merge 3 commits into
Conversation
bshastry
marked this pull request as ready for review
August 1, 2026 19:10
bshastry
marked this pull request as draft
August 2, 2026 09:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Root cause and impact
The variant-specific decoders sliced at the ML-KEM component boundary before checking the input's total length. Inputs shorter than 2,400 bytes for
X25519MlKem768Draft00PrivateKey, or shorter than 1,184 bytes for the two hybrid public-key types, therefore caused an indexing panic instead of returning the existingInvalidPrivateKeyorInvalidPublicKeyerror.The public
PrivateKey::decodeandPublicKey::decodeentry points delegate to these functions. This is an input-validation and availability issue for callers that decode untrusted keys without isolating Rust panics; it does not bypass key validation or compromise cryptographic secrets.The fix first converts the complete input slice to a reference to the expected-size byte array. Only after that succeeds is the key split into its two components.
Validation
cargo test -p libcrux-kem --lockedcargo check -p libcrux-kem --no-default-features --lockedrustfmt --checkStrict Clippy with
-D warningsalso reaches the package, but is currently blocked by pre-existinglarge_enum_variantanduseless_conversionwarnings in unchanged code.AI assistance disclosure
OpenAI Codex was used to locate and reproduce the unchecked-slice behavior, implement the focused patch, write the regression tests, and draft this description. The concrete behavior and patch were validated with the commands above. This pull request is opened as a draft for final human review.