Refactor EC key padding length lookup into shared cryptoECC helper; add BN-254 support#26
Merged
ljoy913 merged 3 commits intoJun 28, 2026
Conversation
Copilot
AI
changed the title
[WIP] Fix padding logic for BN-254 keys and remove duplication
Refactor EC key padding length lookup into shared cryptoECC helper; add BN-254 support
Jun 27, 2026
zaverucha
requested changes
Jun 27, 2026
zaverucha
left a comment
There was a problem hiding this comment.
The test code in Test.Ecdsa.js and Test.Ecdh.js duplicates the tables (ecdhKeyLengths and ecdsaKeyLengths) rather than using cryptoECC.curveElementLength.
zaverucha
approved these changes
Jun 27, 2026
ljoy913
approved these changes
Jun 28, 2026
ljoy913
added a commit
that referenced
this pull request
Jun 28, 2026
ljoy913
added a commit
that referenced
this pull request
Jun 28, 2026
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.
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.Example of the lookup change: