Skip to content

crypto: optimize getBytesOfRS for EC keys - #65889

Closed
panva wants to merge 1 commit into
nodejs:mainfrom
panva:crypto-get-bytes-of-rs
Closed

crypto: optimize getBytesOfRS for EC keys#65889
panva wants to merge 1 commit into
nodejs:mainfrom
panva:crypto-get-bytes-of-rs

Conversation

@panva

@panva panva commented Sep 7, 2026

Copy link
Copy Markdown
Member

We only need the group order bit count here, which OpenSSL already caches on the key. Use that instead of reconstructing the group and decoding the public point.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
@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
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

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

@nodejs-github-bot nodejs-github-bot added dependencies PRs that add, update, or configure Node.js dependencies. 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 / webcrypto-sign): https://github.com/nodejs/node/actions/runs/34160449761

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/webcrypto-sign.js n=1000 keyReuse='shared' mode='parallel' keyType='ec'                       ***     20.99 %      ±11.10% ±14.64% ±18.79%
crypto/webcrypto-sign.js n=1000 keyReuse='shared' mode='parallel' keyType='ed25519'                          -0.29 %       ±9.11% ±12.01% ±15.41%
crypto/webcrypto-sign.js n=1000 keyReuse='shared' mode='parallel' keyType='ml-dsa-44'                         1.08 %       ±9.32% ±12.29% ±15.77%
crypto/webcrypto-sign.js n=1000 keyReuse='shared' mode='parallel' keyType='rsa-pss'                           0.63 %       ±5.66%  ±7.47%  ±9.58%
crypto/webcrypto-sign.js n=1000 keyReuse='shared' mode='parallel' keyType='rsassa-pkcs1-v1_5'                 1.14 %       ±5.92%  ±7.80% ±10.01%
crypto/webcrypto-sign.js n=1000 keyReuse='shared' mode='serial' keyType='ec'                          **     18.23 %      ±11.20% ±14.77% ±18.95%
crypto/webcrypto-sign.js n=1000 keyReuse='shared' mode='serial' keyType='ed25519'                             1.14 %       ±9.47% ±12.49% ±16.02%
crypto/webcrypto-sign.js n=1000 keyReuse='shared' mode='serial' keyType='ml-dsa-44'                           0.89 %       ±8.78% ±11.58% ±14.86%
crypto/webcrypto-sign.js n=1000 keyReuse='shared' mode='serial' keyType='rsa-pss'                             0.59 %      ±10.16% ±13.39% ±17.18%
crypto/webcrypto-sign.js n=1000 keyReuse='shared' mode='serial' keyType='rsassa-pkcs1-v1_5'                   0.25 %      ±10.17% ±13.41% ±17.21%
crypto/webcrypto-sign.js n=1000 keyReuse='unique' mode='parallel' keyType='ec'                       ***     18.38 %      ±10.72% ±14.13% ±18.14%
crypto/webcrypto-sign.js n=1000 keyReuse='unique' mode='parallel' keyType='ed25519'                           2.71 %       ±9.02% ±11.89% ±15.25%
crypto/webcrypto-sign.js n=1000 keyReuse='unique' mode='parallel' keyType='ml-dsa-44'                        -1.05 %       ±9.11% ±12.00% ±15.40%
crypto/webcrypto-sign.js n=1000 keyReuse='unique' mode='parallel' keyType='rsa-pss'                           0.91 %       ±5.39%  ±7.11%  ±9.12%
crypto/webcrypto-sign.js n=1000 keyReuse='unique' mode='parallel' keyType='rsassa-pkcs1-v1_5'                 1.37 %       ±4.92%  ±6.48%  ±8.32%

Be aware that when doing many comparisons the risk of a false-positive
result increases. In this case, there are 15 comparisons, you can thus
expect the following amount of false-positive results:
  0.75 false positives, when considering a   5% risk acceptance (*, **, ***),
  0.15 false positives, when considering a   1% risk acceptance (**, ***),
  0.01 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.

@meixg meixg added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 8, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 8, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@panva panva added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Sep 8, 2026
@panva panva closed this Sep 8, 2026
@panva
panva deleted the crypto-get-bytes-of-rs branch September 8, 2026 11:17
@panva

panva commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

Superseded by #65908

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. dependencies PRs that add, update, or configure Node.js dependencies. 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.

4 participants