-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ext/crypto): support cross-curve ECDSA sign and verify #28574
Conversation
Signed-off-by: Gene Parmesan Thomas <201852096+gopoto@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
ext/crypto/lib.rs
Outdated
.ok_or_else(JsErrorBox::not_supported)?; | ||
match named_curve { | ||
CryptoNamedCurve::P256 => { | ||
use p256::ecdsa::{Signature as P256Signature, VerifyingKey}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: move these to top level. makes refactors easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call; moved the nested use
for SigningKey
, Signature
, and VerifyingKey
out of the match arms into top-level imports (with appropriate aliases), and imported PrehashSigner
/PrehashVerifier
at the top of the module. This makes the code cleaner and easier to refactor.
Signed-off-by: gopoto <201852096+gopoto@users.noreply.github.com>
Fixes: #20198
Overview
The Web Crypto implementation has been artificially limiting
ECDSA
to only the “recommended” curve/hash pairs (P‑256/SHA‑256
andP‑384/SHA‑384
). The underlyingring
APIs enforced those pairs, so any attempt to verify signatures produced with different digests (e.g.P‑384
withSHA‑256
) failed with a “Not implemented” error.This PR rewires the ECDSA sign/verify path to use RustCrypto’s
ecdsa
crate instead ofring
, computes digests separately, and uses the prehash signing/verifying API so that anysha1
,sha256
,sha384
orsha512
can be used with either curve. The JSSubtleCrypto
bindings were updated to drop the hard coded checks, and a new unit test exercisesP‑384 + SHA‑256
to ensure non‑matching combos now round trip.Changes
ext/crypto/lib.rs
: switch ECDSA sign/verify to useecdsa
prehash interfaces; parse signatures as rawr||s
; generate rawr||s
output.ext/crypto/Cargo.toml
: bring inecdsa
andsignature
crates and enable relevant features.ext/crypto/00_crypto.js
: remove curve/hash guards from ECDSA sign/verify.tests/unit/webcrypto_test.ts
: addECDSA
cross‑hash test.cargo build -p deno --offline
). Warnings about unusedring
imports remain but can be cleaned up separately.Testing
Run the unit suite and observe the new test case:
The new
testEcdsaCrossHashAlgorithms
uses the existing P‑384 test vectors to sign withSHA‑256
and verifies correctly. All existing tests continue to pass.Notes
This change broadens
ECDSA
compatibility without affectingRSA
,HMAC
orEdDSA
. Further cleanups (removing unusedring
imports, adding P‑521, etc.) could be tackled separately.Please let me know if any further adjustments are needed.
This PR was generated by an AI system in collaboration with maintainers: @dsherret