Skip to content

[v26.x backport] crypto: discover hashes and ciphers from providers - #65596

Open
panva wants to merge 2 commits into
nodejs:v26.x-stagingfrom
panva:provider-backports-26
Open

[v26.x backport] crypto: discover hashes and ciphers from providers#65596
panva wants to merge 2 commits into
nodejs:v26.x-stagingfrom
panva:provider-backports-26

Conversation

@panva

@panva panva commented Aug 27, 2026

Copy link
Copy Markdown
Member

Backports #65484 to v26.x

panva added 2 commits August 27, 2026 19:13
Enumerate usable digests and aliases from activated OpenSSL 3 providers
rather than relying only on the legacy digest registry. Normalize
provider aliases, omit numeric OIDs and NULL, and validate them against
the active default property query. Preserve legacy names and the OpenSSL
1.1.1 and BoringSSL paths.

Expose KECCAK-KMAC-128, KECCAK-256, SHA256-192, and other provider
digests. Add `functionName` and `customization` options for cSHAKE
digests in `createHash()` and `crypto.hash()` with OpenSSL 4.0 or later.

Resolve provider-only digest names across hashing, HMAC, KDF, signing,
verification, and RSA digest options. Keep ordinary hash construction
and one-shot hashing on the original binding arities and direct
initialization paths. Use parameterized setup only when cSHAKE options
are supplied.

Lazily cache successful provider fetches per Environment.
Index entries by case-insensitive query, canonical, and alias names.
Deduplicate owners by provider and canonical identity. Return borrowed
pointers on warm hits.

Introduce a process-wide FIPS-state generation that advances only after
successful, state-changing `setFips()` calls. Use it to invalidate
per-Environment digest caches and refresh `getHashes()` snapshots in the
main thread and workers. Keep cache IDs monotonic across invalidation
because JavaScript Realms can retain them. Existing hash contexts can
finish across a transition.

Release provider owners before unloading worker addon DSOs. Document
provider-dependent availability and operation-specific restrictions.
Add known-answer vectors, option validation, provider resolution,
property-query, FIPS transition, worker, snapshot, and cross-API
coverage.

Refs: nodejs#62982
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: nodejs#65484
Fixes: nodejs#43040
Fixes: nodejs#64866
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Enumerate usable ciphers and aliases from activated OpenSSL 3 providers
instead of maintaining lists of provider-only algorithms. Skip numeric
OID aliases and filter NULL, TLS composite, multiblock, and
encrypt-then-MAC implementations that the Cipher APIs cannot use.
Preserve the OpenSSL 1.1.1 and BoringSSL paths.

Expose CBC-CTS, SM4-GCM, SM4-CCM, SM4-XTS, and additional AES key wrap
implementations. Add `ctsMode` (CS1/CS2/CS3) and `xtsStandard`
(GB/IEEE) options for selecting provider CTS and SM4-XTS variants.

Keep ordinary cipher construction on the original binding and legacy
lookup paths.

Lazily cache successful provider fetches per Environment for
string initialization and `getCipherInfo()`.
Index entries by case-insensitive query, canonical, and alias names.
Deduplicate owners by provider and canonical identity. Return borrowed
pointers on warm hits.

Use the shared process-wide FIPS-state generation to invalidate
per-Environment cipher caches and refresh `getCiphers()` snapshots in
the main thread and workers. Existing cipher contexts retain their
implementation and can finish across a transition. Release provider
owners before unloading worker addon DSOs.

Enforce one-shot updates for CBC-CTS, AES key wrap, SIV/GCM-SIV, and
CCM decryption. Reject finalization without required input or CCM tags,
and defer authentication failures to `final()`. Document streaming and
XTS data-unit constraints.

Add known-answer vectors, option validation, provider round trips,
cache, worker, snapshot, FIPS transition, and construction benchmark
coverage.

Fixes: nodejs#43040
Fixes: nodejs#64866
Refs: nodejs#62982
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: nodejs#65484
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
@panva
panva requested a review from aduh95 August 27, 2026 17:15
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

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

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. v26.x Issues that can be reproduced on v26.x or PRs targeting the v26.x-staging branch. labels Aug 27, 2026
@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.07942% with 199 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.34%. Comparing base (ca26282) to head (7938ca5).
⚠️ Report is 343 commits behind head on v26.x-staging.

Files with missing lines Patch % Lines
src/crypto/crypto_hash.cc 65.94% 53 Missing and 41 partials ⚠️
src/crypto/crypto_util.cc 11.86% 52 Missing ⚠️
lib/internal/crypto/hash.js 40.62% 36 Missing and 2 partials ⚠️
src/crypto/crypto_util.h 0.00% 5 Missing ⚠️
src/crypto/crypto_cipher.cc 94.44% 0 Missing and 3 partials ⚠️
src/crypto/crypto_rsa.cc 70.00% 0 Missing and 3 partials ⚠️
lib/internal/crypto/util.js 95.45% 2 Missing ⚠️
src/crypto/crypto_context.cc 71.42% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##           v26.x-staging   #65596      +/-   ##
=================================================
+ Coverage          90.24%   90.34%   +0.10%     
=================================================
  Files                729      744      +15     
  Lines             242760   250889    +8129     
  Branches           46044    47899    +1855     
=================================================
+ Hits              219073   226673    +7600     
- Misses             15133    15515     +382     
- Partials            8554     8701     +147     
Files with missing lines Coverage Δ
lib/internal/crypto/cipher.js 98.18% <100.00%> (+0.16%) ⬆️
src/crypto/crypto_aes.h 33.33% <ø> (ø)
src/crypto/crypto_chacha20_poly1305.cc 56.81% <100.00%> (ø)
src/crypto/crypto_cipher.h 68.47% <ø> (ø)
src/crypto/crypto_hash.h 25.00% <ø> (ø)
src/env.cc 85.36% <100.00%> (-0.11%) ⬇️
src/env.h 98.21% <ø> (ø)
lib/internal/crypto/util.js 97.44% <95.45%> (+0.36%) ⬆️
src/crypto/crypto_context.cc 72.34% <71.42%> (+0.06%) ⬆️
src/crypto/crypto_cipher.cc 79.57% <94.44%> (+2.86%) ⬆️
... and 5 more

... and 151 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. v26.x Issues that can be reproduced on v26.x or PRs targeting the v26.x-staging branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants