Refactor EC key padding length lookup into shared cryptoECC helper; add BN-254 support#27
Merged
Merged
Conversation
Refactor EC key padding length lookup into shared cryptoECC helper; add BN-254 support
There was a problem hiding this comment.
Pull request overview
This PR centralizes ECC curve element byte-length resolution into cryptoECC to eliminate duplicated per-curve tables in ECDH/ECDSA padding logic, and extends that shared lookup to include BN-254 (32-byte elements). It also updates the QUnit ECDH/ECDSA tests to cover BN-254 and to reference the shared helper, and regenerates the distribution bundle accordingly.
Changes:
- Added
cryptoECC.curveElementLength(curveName)(case-insensitive) and a sharedcurveElementLengthstable including"BN-254": 32. - Updated ECDH/ECDSA
generateKeyand JWKimportKeypadding logic to usecryptoECC.curveElementLength(...)instead of inline tables. - Added BN-254 generateKey coverage in ECDH/ECDSA tests and removed duplicated test-side curve-length tables.
Reviewed changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/cryptoECC.js |
Introduces shared curve element-length lookup (including BN-254) and exports it from cryptoECC. |
src/ecdh.js |
Replaces inline curve-length table with cryptoECC.curveElementLength(...) for key padding in generate/import (JWK). |
src/ecdsa.js |
Replaces inline curve-length table with cryptoECC.curveElementLength(...) for key padding in generate/import (JWK). |
test/Test.Ecdh.js |
Adds BN-254 generateKey test and switches length assertions to the shared helper. |
test/Test.Ecdsa.js |
Adds BN-254 generateKey test and switches length assertions to the shared helper. |
dist/msrcrypto.js |
Regenerated bundle reflecting the shared helper + call-site updates. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The #26 change replaced the tests' own curve-length tables with calls to cryptoECC.curveElementLength(). cryptoECC is an internal module inside the UMD bundle and is not exposed as a global, so SubtleTests.html threw ReferenceError: cryptoECC is not defined. Restore independent test-local tables (keeping the new BN-254 entry); the production de-duplication in ecdh.js/ecdsa.js/cryptoECC.js is unaffected.
zaverucha
approved these changes
Jun 29, 2026
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.
PR #25’s leading-zero padding logic introduced four duplicated curve-length tables in ECDH/ECDSA, and all four omitted
BN-254. This change consolidates curve element-length resolution into a single shared source and makes lookups case-insensitive to avoid drift and mismatches.Shared curve element-length source in
cryptoECCcurveElementLengthsinsrc/cryptoECC.jswith the full supported set, including"BN-254": 32.cryptoECC.curveElementLength(curveName)to normalize viatoUpperCase()and return the fixed element byte length.Replaced duplicated
partLentables (4 call sites)src/ecdh.jsgenerateKeyimportKey(p.format === "jwk")src/ecdsa.jsgenerateKeyimportKey(p.format === "jwk")cryptoECC.curveElementLength(...)instead of inline object literals.Targeted BN-254 coverage updates in existing ECC tests
test/Test.Ecdh.jsandtest/Test.Ecdsa.js.cryptoECC.curveElementLength(...)directly instead of duplicatedecdhKeyLengths/ecdsaKeyLengthstables.Rebuilt distribution bundle
dist/msrcrypto.jsanddist/msrcrypto.min.jsso the published bundle includes the fix.Example of the lookup change: