Repository navigation
fix(ext/node): DSA keygen with arbitrary modulusLength - #34206
Merged
Merged
Conversation
The `dsa` crate only exposes a fixed set of `KeySize` variants
(1024/160, 2048/224, 2048/256, 3072/256), so
`crypto.generateKeyPair('dsa', { modulusLength: 2049, divisorLength: 256 })`
rejected anything outside that list. Node accepts arbitrary bit
lengths.
Generate the (p, q, g) parameters in-tree by mirroring the algorithm
the `dsa` crate uses internally (FIPS 186-4 §A.1.1.2 for p/q,
Appendix A.2.1 for g), then hand them to `Components::from_components`
which has public visibility. This sidesteps the crate's
`pub(crate)` `KeySize` fields without forking it.
Enables `parallel/test-crypto-keygen-bit-length.js` in the
node compat suite.
Co-Authored-By: Divy Srivastava <me@littledivy.com>
Member
|
@divybot resolve conflicts |
Co-Authored-By: Divy Srivastava <me@littledivy.com>
littledivy
enabled auto-merge (squash)
May 18, 2026 03:35
6 tasks done
littledivy
added a commit
to crowlKats/deno
that referenced
this pull request
Jun 10, 2026
## Summary
`crypto.generateKeyPair('dsa', { modulusLength: N })` previously only
worked for the four fixed sizes the Rust `dsa` crate exposes via
`KeySize` (1024/160, 2048/224, 2048/256, 3072/256). Anything else —
including the 2049/256 pair Node.js's test suite exercises — was
rejected with `TypeError: Invalid modulusLength+divisorLength
combination`.
This patch:
- Vendors the `(p, q, g)` parameter generation in
`ext/node_crypto/keys.rs` so it accepts arbitrary `L` and `N`. The
algorithm is the same one the `dsa` crate uses internally (FIPS 186-4
§A.1.1.2 for the prime pair, Appendix A.2.1 for the unverified
generator). The resulting components are handed to
`dsa::Components::from_components` — that constructor is public, so we
sidestep the crate's `pub(crate)` `KeySize` fields without forking the
crate or pinning on an upstream PR.
- Adds basic input validation (L > N ≥ 2, both fit in `u32`).
- Enables `parallel/test-crypto-keygen-bit-length.js` in
`tests/node_compat/config.jsonc`.
Verified locally: DSA 2049/256 keygen succeeds (~1.7s), sign/verify
round-trips, and PKCS#8 PEM export works.
Closes denoland/orchid#135
## Test plan
- [x] `cargo test --test node_compat -- test-crypto-keygen-bit-length`
passes
- [x] `cargo clippy -p deno_node_crypto --all-targets` clean
- [x] DSA 2049/256 sign+verify round-trip works
- [x] DSA 2049/256 PKCS#8 PEM export works
Co-authored-by: divybot <divybot@users.noreply.github.com>
Co-authored-by: Divy Srivastava <me@littledivy.com>
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
crypto.generateKeyPair('dsa', { modulusLength: N })previously only worked for the four fixed sizes the Rustdsacrate exposes viaKeySize(1024/160, 2048/224, 2048/256, 3072/256). Anything else — including the 2049/256 pair Node.js's test suite exercises — was rejected withTypeError: Invalid modulusLength+divisorLength combination.This patch:
(p, q, g)parameter generation inext/node_crypto/keys.rsso it accepts arbitraryLandN. The algorithm is the same one thedsacrate uses internally (FIPS 186-4 §A.1.1.2 for the prime pair, Appendix A.2.1 for the unverified generator). The resulting components are handed todsa::Components::from_components— that constructor is public, so we sidestep the crate'spub(crate)KeySizefields without forking the crate or pinning on an upstream PR.u32).parallel/test-crypto-keygen-bit-length.jsintests/node_compat/config.jsonc.Verified locally: DSA 2049/256 keygen succeeds (~1.7s), sign/verify round-trips, and PKCS#8 PEM export works.
Closes denoland/orchid#135
Test plan
cargo test --test node_compat -- test-crypto-keygen-bit-lengthpassescargo clippy -p deno_node_crypto --all-targetsclean