GeezerVison is showing github.com — [v24.x backport] crypto, test, and tooling fixes by panva · Pull Request #66970 · nodejs/node
[v24.x backport] crypto, test, and tooling fixes
#66970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b36ce76
tools: use self-repository references
panva Sep 13, 2026
b6709c1
crypto: use current FIPS state for availability
panva Sep 23, 2026
d0c0275
crypto: use internal random buffer bounds
panva Sep 22, 2026
f233bab
test: reduce expensive crypto test variants
panva Sep 25, 2026
2b7a132
crypto: separate conversion from validation
panva Sep 22, 2026
9194871
crypto: use backend cSHAKE and KMAC
panva Sep 23, 2026
ec18142
crypto: improve random synchronous number generation performance
mertcanaltin Oct 3, 2026
2559033
test: scope Blob WPT failures to big-endian
panva Sep 26, 2026
8ec2cb9
test: honor allowed WPT promise rejections
panva Sep 26, 2026
138ed26
crypto: remove KEM key locking
panva Sep 30, 2026
4afe009
crypto: remove key export and metadata locks
panva Sep 30, 2026
File filter
Filter by extension
.cc
(5)
.cjs
(1)
.gyp
(1)
.h
(3)
.js
(25)
.md
(1)
.mjs
(5)
.ts
(1)
All 8 file types selected
Deleted files
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
crypto: use current FIPS state for availability
Refresh conditional algorithm registration on FIPS changes and use the
current state for parameter restrictions.
Use per-algorithm availability checks in normalization and native named
key generation. Remove getPqcKeyTypes().
Enable supports() tests under FIPS and cover state transitions in warmed
workers.
Signed-off-by: Filip Skokan <[email protected] >
Assisted-by: Codex
PR-URL: #66160
Reviewed-By: James M Snell <[email protected] >
Reviewed-By: Matteo Collina <[email protected] >
Loading branch information
Uh oh!
There was an error while loading. Please reload this page.
panva
committed
Oct 28, 2026
commit b6709c1a29aece9ad8abf584bb9558c58cb0e8ea
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -3251,12 +3251,6 @@ const KeyAlgorithm* KeyAlgorithm::FromName(const char* name) {
return nullptr;
}
void KeyAlgorithm::ForEachPqc(Callback callback) {
for (const auto* algorithm : kKeyAlgorithms) {
if (algorithm->isPqc() && algorithm->isAvailable()) callback(*algorithm);
}
}
bool KeyAlgorithm::isRsa() const {
return this == &RSA || this == &RSA_PSS;
}
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -1121,8 +1121,6 @@ class KeyAlgorithm final {
// Look up a canonical name case-insensitively, including unavailable
// algorithms.
static const KeyAlgorithm* FromName(const char* name);
using Callback = std::function<void(const KeyAlgorithm&)>;
static void ForEachPqc(Callback callback);
const char* name() const { return name_; }
const char* keyTypeName() const {
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -4,15 +4,13 @@ const {
FunctionPrototypeCall,
ObjectDefineProperty,
SafeArrayIterator,
StringPrototypeToLowerCase,
} = primordials;
const {
DhKeyPairGenJob,
DsaKeyPairGenJob,
EcKeyPairGenJob,
NamedKeyPairGenJob,
getPqcKeyTypes,
RsaKeyPairGenJob,
SecretKeyGenJob,
kCryptoJobAsync,
Expand Down
Expand Up
@@ -160,17 +158,6 @@ function parseKeyEncoding(keyType, options = kEmptyObject) {
];
}
const namedKeyPairs = {
'__proto__': null,
'ed25519': 'Ed25519',
'ed448': 'Ed448',
'x25519': 'X25519',
'x448': 'X448',
};
for (const name of new SafeArrayIterator(getPqcKeyTypes())) {
namedKeyPairs[StringPrototypeToLowerCase(name)] = name;
}
function createJob(mode, type, options) {
validateString(type, 'type');
Expand Down
Expand Up
@@ -339,12 +326,8 @@ function createJob(mode, type, options) {
generator == null ? 2 : generator,
...encoding);
}
default: {
if (namedKeyPairs[type] === undefined) {
throw new ERR_INVALID_ARG_VALUE('type', type, 'must be a supported key type');
}
return new NamedKeyPairGenJob(mode, namedKeyPairs[type], ...encoding);
}
default:
return new NamedKeyPairGenJob(mode, type, ...encoding);
}
}
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -50,10 +50,19 @@ const {
getFipsCrypto,
getFipsCryptoGeneration,
KmacJob,
getPqcKeyTypes ,
isKeyAlgorithmAvailable ,
} = internalBinding('crypto');
const isFips = getFipsCrypto() === 1;
let fips;
let fipsGeneration;
function isFips() {
const generation = getFipsCryptoGeneration();
if (fipsGeneration !== generation) {
fips = getFipsCrypto() === 1;
fipsGeneration = generation;
}
return fips;
}
const { getOptionValue } = require('internal/options');
Expand Down
Expand Up
@@ -122,6 +131,9 @@ let _hashCache;
let _macCache;
if (isBuildingSnapshot()) {
addSerializeCallback(() => {
fips = undefined;
fipsGeneration = undefined;
supportedAlgorithmsGeneration = undefined;
_hashCache = undefined;
_macCache = undefined;
});
Expand Down
Expand Up
@@ -491,53 +503,69 @@ const kAlgorithmDefinitions = {
},
};
// Conditionally supported algorithms
const pqcKeyTypes = getPqcKeyTypes();
const conditionalAlgorithms = {
'AES-OCB': !!hasAesOcbMode,
'Argon2d': !!Argon2Job,
'Argon2i': !!Argon2Job,
'Argon2id': !!Argon2Job,
'ChaCha20-Poly1305': process.features.openssl_is_boringssl ||
ArrayPrototypeIncludes(getCiphers(), 'chacha20-poly1305'),
'cSHAKE128': !process.features.openssl_is_boringssl ||
ArrayPrototypeIncludes(getHashes(), 'shake128'),
'cSHAKE256': !process.features.openssl_is_boringssl ||
ArrayPrototypeIncludes(getHashes(), 'shake256'),
'Ed448': !process.features.openssl_is_boringssl,
'KMAC128': !!KmacJob,
'KMAC256': !!KmacJob,
'KT128': !isFips,
'KT256': !isFips,
'ML-DSA-44': ArrayPrototypeIncludes(pqcKeyTypes, 'ML-DSA-44'),
'ML-DSA-65': ArrayPrototypeIncludes(pqcKeyTypes, 'ML-DSA-65'),
'ML-DSA-87': ArrayPrototypeIncludes(pqcKeyTypes, 'ML-DSA-87'),
'ML-KEM-512': ArrayPrototypeIncludes(pqcKeyTypes, 'ML-KEM-512'),
'ML-KEM-768': ArrayPrototypeIncludes(pqcKeyTypes, 'ML-KEM-768'),
'ML-KEM-1024': ArrayPrototypeIncludes(pqcKeyTypes, 'ML-KEM-1024'),
'MLKEM768-P256': !isFips && ArrayPrototypeIncludes(pqcKeyTypes, 'ML-KEM-768') &&
(!process.features.openssl_is_boringssl ||
(ArrayPrototypeIncludes(getHashes(), 'sha3-256') &&
ArrayPrototypeIncludes(getHashes(), 'shake256'))),
'MLKEM768-X25519': !isFips && ArrayPrototypeIncludes(pqcKeyTypes, 'ML-KEM-768') &&
(!process.features.openssl_is_boringssl ||
(ArrayPrototypeIncludes(getHashes(), 'sha3-256') &&
ArrayPrototypeIncludes(getHashes(), 'shake256'))),
'MLKEM1024-P384': !isFips && ArrayPrototypeIncludes(pqcKeyTypes, 'ML-KEM-1024') &&
(!process.features.openssl_is_boringssl ||
(ArrayPrototypeIncludes(getHashes(), 'sha3-256') &&
ArrayPrototypeIncludes(getHashes(), 'shake256'))),
'SHA3-256': !process.features.openssl_is_boringssl ||
ArrayPrototypeIncludes(getHashes(), 'sha3-256'),
'SHA3-384': !process.features.openssl_is_boringssl ||
ArrayPrototypeIncludes(getHashes(), 'sha3-384'),
'SHA3-512': !process.features.openssl_is_boringssl ||
ArrayPrototypeIncludes(getHashes(), 'sha3-512'),
'TurboSHAKE128': !isFips,
'TurboSHAKE256': !isFips,
'X448': !process.features.openssl_is_boringssl,
};
function has(algorithms, name) {
return ArrayPrototypeIncludes(algorithms, name);
}
// Re-evaluated when the active FIPS state changes.
function getConditionalAlgorithms() {
const mlKem768 = isKeyAlgorithmAvailable('ML-KEM-768');
const mlKem1024 = isKeyAlgorithmAvailable('ML-KEM-1024');
const ciphers = getCiphers();
const hashes = getHashes();
const macs = getMacs();
const fips = isFips();
return {
'AES-OCB': !!hasAesOcbMode &&
(has(ciphers, 'aes-128-ocb') ||
has(ciphers, 'aes-192-ocb') ||
has(ciphers, 'aes-256-ocb')),
'Argon2d': !!Argon2Job && !fips,
'Argon2i': !!Argon2Job && !fips,
'Argon2id': !!Argon2Job && !fips,
'ChaCha20-Poly1305': process.features.openssl_is_boringssl ||
has(ciphers, 'chacha20-poly1305'),
'cSHAKE128': has(hashes, 'shake128'),
'cSHAKE256': has(hashes, 'shake256'),
'Ed25519': isKeyAlgorithmAvailable('Ed25519'),
'Ed448': isKeyAlgorithmAvailable('Ed448'),
'KMAC128': !!KmacJob && has(macs, 'kmac128'),
'KMAC256': !!KmacJob && has(macs, 'kmac256'),
'KT128': !fips,
'KT256': !fips,
'ML-DSA-44': isKeyAlgorithmAvailable('ML-DSA-44'),
'ML-DSA-65': isKeyAlgorithmAvailable('ML-DSA-65'),
'ML-DSA-87': isKeyAlgorithmAvailable('ML-DSA-87'),
'ML-KEM-512': isKeyAlgorithmAvailable('ML-KEM-512'),
'ML-KEM-768': mlKem768,
'ML-KEM-1024': mlKem1024,
'MLKEM768-P256': !fips && mlKem768 &&
(!process.features.openssl_is_boringssl ||
(has(hashes, 'sha3-256') &&
has(hashes, 'shake256'))),
'MLKEM768-X25519': !fips && mlKem768 &&
(!process.features.openssl_is_boringssl ||
(has(hashes, 'sha3-256') &&
has(hashes, 'shake256'))),
'MLKEM1024-P384': !fips && mlKem1024 &&
(!process.features.openssl_is_boringssl ||
(has(hashes, 'sha3-256') &&
has(hashes, 'shake256'))),
'SHA-1': has(hashes, 'sha1'),
'SHA-256': has(hashes, 'sha256'),
'SHA-384': has(hashes, 'sha384'),
'SHA-512': has(hashes, 'sha512'),
'SHA3-256': has(hashes, 'sha3-256'),
'SHA3-384': has(hashes, 'sha3-384'),
'SHA3-512': has(hashes, 'sha3-512'),
'TurboSHAKE128': !fips,
'TurboSHAKE256': !fips,
'X25519': isKeyAlgorithmAvailable('X25519'),
'X448': isKeyAlgorithmAvailable('X448'),
};
}
// Experimental algorithms that emit warnings.
const experimentalAlgorithmsWithWarnings = [
Expand Down
Expand Up
@@ -575,6 +603,7 @@ const experimentalAlgorithmsWithWarnings = [
// Also builds a parallel Map<UPPERCASED_NAME, canonicalName> per operation
// for O(1) case-insensitive algorithm name lookup in normalizeAlgorithm.
function createSupportedAlgorithms(algorithmDefs) {
const conditionalAlgorithms = getConditionalAlgorithms();
// Detached below rather than declared `__proto__: null`: V8 puts that
// literal form in dictionary mode, slowing every registry lookup.
const result = {};
Expand Down
Expand Up
@@ -622,8 +651,16 @@ function createSupportedAlgorithms(algorithmDefs) {
return { algorithms: result, nameMap };
}
const { algorithms: kSupportedAlgorithms, nameMap: kAlgorithmNameMap } =
createSupportedAlgorithms(kAlgorithmDefinitions);
let supportedAlgorithms;
let supportedAlgorithmsGeneration;
function getSupportedAlgorithms() {
const generation = getFipsCryptoGeneration();
if (supportedAlgorithmsGeneration !== generation) {
supportedAlgorithms = createSupportedAlgorithms(kAlgorithmDefinitions);
supportedAlgorithmsGeneration = generation;
}
return supportedAlgorithms;
}
const simpleAlgorithmDictionaries = {
AesCbcParams: { iv: 'BufferSource' },
Expand Down
Expand Up
@@ -685,7 +722,7 @@ function validateMaxBufferLength(data, name, max = kMaxBufferLength) {
}
function validateKmacKeyLength(length) {
if ((length < 32 || length % 8) && isFips)
if ((length < 32 || length % 8) && isFips() )
throw lazyDOMException('Invalid key length', 'NotSupportedError');
}
Expand Down
Expand Up
@@ -745,16 +782,16 @@ function normalizeAlgorithm(algorithm, op) {
webidl ??= require('internal/crypto/webidl');
// 1.
const registeredAlgorithms = kSupportedAlgorithms[op];
// 2. 3.
const initialAlg = webidl.converters.Algorithm(algorithm,
kNormalizeAlgorithmOpts);
const { algorithms, nameMap } = getSupportedAlgorithms();
const registeredAlgorithms = algorithms[op];
// 4.
let algName = initialAlg.name;
// 5. Case-insensitive lookup via pre-built Map (O(1) instead of O(n)).
const canonicalName = kAlgorithmNameMap [op]?.get(
const canonicalName = nameMap [op]?.get(
StringPrototypeToUpperCase(algName));
if (canonicalName === undefined)
throw lazyDOMException('Unrecognized algorithm name', 'NotSupportedError');
Expand Down
Expand Up
@@ -1229,7 +1266,9 @@ module.exports = {
toBuf,
kNamedCurveAliases,
kSupportedAlgorithms,
get kSupportedAlgorithms() {
return getSupportedAlgorithms().algorithms;
},
isFips,
normalizeAlgorithm,
normalizeHashName,
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -1775,7 +1775,6 @@ class SubtleCrypto {
}
// Implements https://wicg.github.io/webcrypto-modern-algos/#SubtleCrypto-method-supports
// TODO(panva): Make supports() account for the active FIPS state.
static supports(operation, algorithm, lengthOrAdditionalAlgorithm = null) {
webidl ??= require('internal/crypto/webidl');
const prefix = "Failed to execute 'supports' on 'SubtleCrypto'";
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -42,9 +42,6 @@ const {
type,
} = require('internal/webidl');
const { getFipsCrypto } = internalBinding('crypto');
const kRsaKeyGenMinimumModulusLength = getFipsCrypto() === 1 ? 2048 : 512;
function validateByteLength(buf, name, target) {
if (getBufferSourceByteLength(buf) !== target) {
throw lazyDOMException(
Expand Down
Expand Up
@@ -168,6 +165,7 @@ const dictRsaKeyGenParams = [
converter: (V, opts) =>
converters['unsigned long'](V, enforceRangeOptions(opts)),
validator: (modulusLength) => {
const kRsaKeyGenMinimumModulusLength = isFips() ? 2048 : 512;
if (modulusLength < kRsaKeyGenMinimumModulusLength) {
throw lazyDOMException(
`algorithm.modulusLength must be at least ${kRsaKeyGenMinimumModulusLength}`,
Expand Down
Expand Up
@@ -294,7 +292,7 @@ function validateCShakeFunctionName(V) {
const length = getBufferSourceByteLength(V);
if (length === 0) return;
if (!isFips) {
if (!isFips() ) {
const bytes = getBufferSourceBytes(V);
for (let i = 0; i < kCShakeFunctionNames.length; i++) {
const functionName = kCShakeFunctionNames[i];
Expand All
@@ -314,7 +312,7 @@ function validateCShakeFunctionName(V) {
}
function validateCShakeCustomization(V) {
if (isFips && getBufferSourceByteLength(V) !== 0)
if (isFips() && getBufferSourceByteLength(V) !== 0)
throw lazyDOMException(
'Unsupported CShakeParams customization',
'NotSupportedError');
Expand Down
Expand Up
@@ -778,7 +776,7 @@ converters.KmacParams = createDictionaryConverter(
converter: (V, opts) =>
converters['unsigned long'](V, enforceRangeOptions(opts)),
validator: (V) => {
if ((V === 0 || V % 8) && isFips)
if ((V === 0 || V % 8) && isFips() )
throw lazyDOMException(
'Invalid KmacParams outputLength',
'NotSupportedError');
Expand Down
2 changes: 0 additions & 2 deletions
2
node.gyp
Original file line number
Diff line number
Diff line change
Expand Up
@@ -394,7 +394,6 @@
'src/crypto/crypto_cipher.cc',
'src/crypto/crypto_context.cc',
'src/crypto/crypto_ec.cc',
'src/crypto/crypto_pqc.cc',
'src/crypto/crypto_kem.cc',
'src/crypto/crypto_hmac.cc',
'src/crypto/crypto_kmac.cc',
Expand Down
Expand Up
@@ -433,7 +432,6 @@
'src/crypto/crypto_tls.h',
'src/crypto/crypto_context.h',
'src/crypto/crypto_ec.h',
'src/crypto/crypto_pqc.h',
'src/crypto/crypto_hkdf.h',
'src/crypto/crypto_pbkdf2.h',
'src/crypto/crypto_sig.h',
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -46,7 +46,6 @@ following table:
| `crypto_keys` | Utilities for using and generating secret, private, and public keys. |
| `crypto_mac` | Provider-generic MAC implementations. |
| `crypto_pbkdf2` | PBKDF2 key / bit generation implementation. |
| `crypto_pqc` | Post-quantum algorithm enumeration. |
| `crypto_rsa` | RSA Key Generation functions. |
| `crypto_scrypt` | Scrypt key / bit generation implementation. |
| `crypto_sig` | General digital signature and verification utilities. |
Expand Down
Expand Up
@@ -205,10 +204,11 @@ Public input validation remains specific to each API: PQC JWK `alg` values use
exact canonical names such as `ML-DSA-44`, while raw imports require exact public
`asymmetricKeyType` values such as `ml-dsa-44`.
The internal JavaScript binding exposes `getPqcKeyTypes()` for the available
known PQC algorithm names in their canonical spelling. Named key generation
passes algorithm names to `NamedKeyPairGenJob`, which resolves the name to a static
`KeyAlgorithm` descriptor. Asymmetric key IDs are not exposed to JavaScript.
The internal JavaScript binding exposes `isKeyAlgorithmAvailable()` to check
whether a known key algorithm is available from the current backend. Named key
generation passes algorithm names to `NamedKeyPairGenJob`, which resolves the
name to a static `KeyAlgorithm` descriptor. Asymmetric key IDs are not exposed to
JavaScript.
Real EC curve and ASN.1/OID NIDs still have their own uses. The EC generation
path keeps Ed/X algorithm descriptors separate from curve NIDs while preserving
Expand Down
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.