Skip to content

Return an error for wrongly sized Ed25519 public keys in rust_crypto - #548

Open
akashchamp wants to merge 1 commit into
Keats:masterfrom
akashchamp:fix-eddsa-key-length
Open

akashchamp wants to merge 1 commit into
Keats:masterfrom
akashchamp:fix-eddsa-key-length

Conversation

@akashchamp

Copy link
Copy Markdown

Fixes #547

EdDSAVerifier::new in the rust_crypto backend 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 return InvalidEddsaKey like 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 with aws_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.

@arckoor arckoor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits, but otherwise lgtm

Comment thread tests/eddsa/mod.rs Resolved
Comment thread tests/eddsa/mod.rs Resolved
Comment thread tests/eddsa/mod.rs Resolved
Comment thread tests/eddsa/mod.rs Resolved
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
akashchamp force-pushed the fix-eddsa-key-length branch from 04f34e8 to c2e84de Compare October 27, 2026 10:46

@arckoor arckoor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I forgot about this for so long, one more thing and then it can be merged

Comment thread tests/eddsa/mod.rs
Comment on lines +204 to +208
if cfg!(feature = "rust_crypto") {
assert_eq!(res.unwrap_err().kind(), &ErrorKind::InvalidEddsaKey);
} else {
assert!(!res.unwrap());
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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.

rust_crypto EdDSA verifier panics on short public keys and truncates long ones

2 participants