Repository navigation
Return an error for wrongly sized Ed25519 public keys in rust_crypto - #548
Open
akashchamp wants to merge 1 commit into
Open
akashchamp wants to merge 1 commit into
akashchamp wants to merge 1 commit into
Conversation
arckoor
requested changes
Oct 26, 2026
arckoor
left a comment
Collaborator
There was a problem hiding this comment.
Some nits, but otherwise lgtm
EdDSAVerifier::new sliced the key bytes with [..32] before converting them to a fixed-size array, so keys shorter than 32 bytes panicked and longer keys were silently truncated and accepted. Convert the whole slice instead so both cases return InvalidEddsaKey. Fixes Keats#547
akashchamp
force-pushed
the
fix-eddsa-key-length
branch
from
October 27, 2026 10:46
04f34e8 to
c2e84de
Compare
arckoor
requested changes
Nov 6, 2026
arckoor
left a comment
Collaborator
There was a problem hiding this comment.
Sorry I forgot about this for so long, one more thing and then it can be merged
Comment on lines
+204
to
+208
| if cfg!(feature = "rust_crypto") { | ||
| assert_eq!(res.unwrap_err().kind(), &ErrorKind::InvalidEddsaKey); | ||
| } else { | ||
| assert!(!res.unwrap()); | ||
| } |
Collaborator
There was a problem hiding this comment.
Suggested change
| if cfg!(feature = "rust_crypto") { | |
| assert_eq!(res.unwrap_err().kind(), &ErrorKind::InvalidEddsaKey); | |
| } else { | |
| assert!(!res.unwrap()); | |
| } | |
| if cfg!(feature = "aws_lc_rs") { | |
| assert!(!res.unwrap()); | |
| } else { | |
| assert_eq!(res.unwrap_err().kind(), &ErrorKind::InvalidEddsaKey); | |
| } |
aws_lc_rs is the only provider I am aware of where we don't immediately try to construct a pubkey from the bytes, all the others (i.e. also jsonwebtoken-openssl and -botan) should immediately reject this
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.
Fixes #547
EdDSAVerifier::newin therust_cryptobackend sliced the public key with[..32]before converting it to&[u8; 32], so a key shorter than 32 bytes panicked with an out-of-range index and a longer key was silently truncated to its first 32 bytes and accepted. This converts the whole slice instead, so both cases now returnInvalidEddsaKeylike the other malformed-key paths.Added two tests (16-byte and 33-byte public keys) that fail on master with
rust_crypto(panic /Ok(true)) and pass with this change; they also pass withaws_lc_rs, which already rejected these keys at verification time.Verified locally:
cargo fmt --check,cargo clippy --all-targets --features {rust_crypto,aws_lc_rs} -- -D warnings,cargo test --features {rust_crypto,aws_lc_rs}with and without default features, plus the eddsa tests on 1.88.0.