Skip to content

crypto: optimize private EC JWK import - #65893

Closed
panva wants to merge 2 commits into
nodejs:mainfrom
panva:crypto-ec-jwk-private-import
Closed

crypto: optimize private EC JWK import#65893
panva wants to merge 2 commits into
nodejs:mainfrom
panva:crypto-ec-jwk-private-import

Conversation

@panva

@panva panva commented Sep 7, 2026

Copy link
Copy Markdown
Member

Avoid creating temporary EVP objects and repeating key validation while retaining the private scalar range and public/private consistency checks.

Avoid creating temporary EVP objects and repeating key validation while
retaining the private scalar range and public/private consistency
checks.

Assisted-by: GitHub Copilot
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto
  • @nodejs/security-wg

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Sep 7, 2026
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Benchmark GHA (crypto / create-keyobject): https://github.com/nodejs/node/actions/runs/34165032480

Results

[!WARNING]
Do not take GHA benchmark results as face value, always confirm them
using a dedicated machine, e.g. Jenkins CI.

Benchmark results:

                                                                              confidence improvement accuracy (*)    (**)   (***)
crypto/create-keyobject.js n=1000 keyFormat='der-pkcs8' keyType='ec'                          1.95 %       ±8.35% ±11.00% ±14.12%
crypto/create-keyobject.js n=1000 keyFormat='der-pkcs8' keyType='ed25519'                    -0.17 %       ±7.22%  ±9.51% ±12.21%
crypto/create-keyobject.js n=1000 keyFormat='der-pkcs8' keyType='ml-dsa-44'                   0.83 %       ±5.83%  ±7.68%  ±9.86%
crypto/create-keyobject.js n=1000 keyFormat='der-pkcs8' keyType='rsa'                         1.05 %       ±8.14% ±10.73% ±13.77%
crypto/create-keyobject.js n=1000 keyFormat='der-spki' keyType='ec'                           0.02 %       ±8.43% ±11.11% ±14.26%
crypto/create-keyobject.js n=1000 keyFormat='der-spki' keyType='ed25519'                      2.13 %       ±8.49% ±11.19% ±14.36%
crypto/create-keyobject.js n=1000 keyFormat='der-spki' keyType='ml-dsa-44'                   -1.08 %       ±8.76% ±11.54% ±14.81%
crypto/create-keyobject.js n=1000 keyFormat='der-spki' keyType='rsa'                         -0.80 %       ±8.59% ±11.33% ±14.53%
crypto/create-keyobject.js n=1000 keyFormat='jwk-private' keyType='ec'               ***     47.39 %       ±8.33% ±10.99% ±14.11%
crypto/create-keyobject.js n=1000 keyFormat='jwk-private' keyType='ed25519'                   2.86 %       ±7.11%  ±9.38% ±12.03%
crypto/create-keyobject.js n=1000 keyFormat='jwk-private' keyType='ml-dsa-44'                -1.51 %       ±5.43%  ±7.16%  ±9.19%
crypto/create-keyobject.js n=1000 keyFormat='jwk-private' keyType='rsa'                      -0.82 %       ±6.39%  ±8.43% ±10.81%
crypto/create-keyobject.js n=1000 keyFormat='jwk-public' keyType='ec'                        -0.34 %       ±7.51%  ±9.90% ±12.70%
crypto/create-keyobject.js n=1000 keyFormat='jwk-public' keyType='ed25519'                   -0.71 %       ±8.13% ±10.71% ±13.74%
crypto/create-keyobject.js n=1000 keyFormat='jwk-public' keyType='ml-dsa-44'                  0.34 %       ±8.09% ±10.67% ±13.69%
crypto/create-keyobject.js n=1000 keyFormat='jwk-public' keyType='rsa'                       -1.36 %       ±7.55%  ±9.95% ±12.77%
crypto/create-keyobject.js n=1000 keyFormat='pkcs8' keyType='ec'                              0.23 %       ±8.17% ±10.77% ±13.82%
crypto/create-keyobject.js n=1000 keyFormat='pkcs8' keyType='ed25519'                        -0.65 %       ±6.77%  ±8.92% ±11.45%
crypto/create-keyobject.js n=1000 keyFormat='pkcs8' keyType='ml-dsa-44'                       0.12 %       ±5.74%  ±7.57%  ±9.71%
crypto/create-keyobject.js n=1000 keyFormat='pkcs8' keyType='rsa'                             0.82 %       ±7.22%  ±9.52% ±12.21%
crypto/create-keyobject.js n=1000 keyFormat='raw-private' keyType='ec'                       -0.75 %       ±6.70%  ±8.83% ±11.33%
crypto/create-keyobject.js n=1000 keyFormat='raw-private' keyType='ed25519'                   0.23 %       ±7.01%  ±9.24% ±11.86%
crypto/create-keyobject.js n=1000 keyFormat='raw-public' keyType='ec'                        -2.00 %       ±7.24%  ±9.54% ±12.25%
crypto/create-keyobject.js n=1000 keyFormat='raw-public' keyType='ed25519'                    2.26 %       ±8.44% ±11.12% ±14.27%
crypto/create-keyobject.js n=1000 keyFormat='raw-public' keyType='ml-dsa-44'                  2.17 %       ±8.91% ±11.74% ±15.06%
crypto/create-keyobject.js n=1000 keyFormat='raw-seed' keyType='ml-dsa-44'                   -0.97 %       ±5.43%  ±7.16%  ±9.19%
crypto/create-keyobject.js n=1000 keyFormat='spki' keyType='ec'                               1.37 %       ±8.44% ±11.12% ±14.27%
crypto/create-keyobject.js n=1000 keyFormat='spki' keyType='ed25519'                          1.09 %       ±8.85% ±11.66% ±14.97%
crypto/create-keyobject.js n=1000 keyFormat='spki' keyType='ml-dsa-44'                       -0.09 %       ±7.75% ±10.22% ±13.12%
crypto/create-keyobject.js n=1000 keyFormat='spki' keyType='rsa'                              0.61 %       ±8.46% ±11.16% ±14.31%

Be aware that when doing many comparisons the risk of a false-positive
result increases. In this case, there are 30 comparisons, you can thus
expect the following amount of false-positive results:
  1.50 false positives, when considering a   5% risk acceptance (*, **, ***),
  0.30 false positives, when considering a   1% risk acceptance (**, ***),
  0.03 false positives, when considering a 0.1% risk acceptance (***)

[!WARNING]
Do not take GHA benchmark results as face value, always confirm them
using a dedicated machine, e.g. Jenkins CI.

@panva panva added crypto Issues and PRs related to the crypto subsystem. performance Issues and PRs related to the performance of Node.js. labels Sep 7, 2026
@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.17%. Comparing base (8d1d7b6) to head (29482d8).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
src/crypto/crypto_ec.cc 25.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65893      +/-   ##
==========================================
- Coverage   90.18%   90.17%   -0.01%     
==========================================
  Files         771      771              
  Lines      265097   265099       +2     
  Branches    50358    50359       +1     
==========================================
- Hits       239083   239061      -22     
- Misses      16961    16967       +6     
- Partials     9053     9071      +18     
Files with missing lines Coverage Δ
src/crypto/crypto_ec.cc 68.95% <25.00%> (+0.53%) ⬆️

... and 29 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@panva panva added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Sep 8, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@panva
panva marked this pull request as draft September 8, 2026 09:51
@panva
panva marked this pull request as ready for review September 8, 2026 09:54
@panva panva closed this Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. crypto Issues and PRs related to the crypto subsystem. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. performance Issues and PRs related to the performance of Node.js.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants