Skip to content

p256,P384,P521: reject keys as bytes if out of curve range#43

Merged
MichaelMure merged 3 commits into
masterfrom
reject-out-range
Jun 23, 2026
Merged

p256,P384,P521: reject keys as bytes if out of curve range#43
MichaelMure merged 3 commits into
masterfrom
reject-out-range

Conversation

@MichaelMure

@MichaelMure MichaelMure commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Note

Medium Risk
Stricter crypto key parsing can reject previously accepted malformed keys (especially EC JWK d and RSA e=1), which is desirable for security but may break callers relying on lax behavior.

Overview
Tightens key import validation for NIST EC curves and RSA public material.

P-256, P-384, and P-521: PrivateKeyFromBytes now rejects scalars outside [1, N−1] (zero and curve order N), with matching unit tests and JWK tests that expect unmarshaling invalid d values to fail.

RSA: PublicKeyFromNE rejects exponents < 2 (e.g. e = 1). New tests cover PKCS1/NE/NEDPQ round-trips and rejection of bad modulus/exponent inputs (empty, wrong size, even modulus, even exponent, exponent too large for int64).

Reviewed by Cursor Bugbot for commit 8d239bb. Bugbot is set up for automated code reviews on this repo. Configure here.

dovydas55
dovydas55 previously approved these changes Jun 23, 2026
Base automatically changed from reject-wrong-curve to master June 23, 2026 09:37
@MichaelMure MichaelMure dismissed dovydas55’s stale review June 23, 2026 09:37

The base branch was changed.

rsa: add missing exponent too small check
@MichaelMure MichaelMure merged commit 40f62fd into master Jun 23, 2026
7 checks passed
@MichaelMure MichaelMure deleted the reject-out-range branch June 23, 2026 09:40
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