GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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.

Sign up for GitHub

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

Closed
panva wants to merge 11 commits into nodejs:v24.x-staging from panva:backport-v24-20261024

Uh oh!

There was an error while loading. Please reload this page.

Closed

[v24.x backport] crypto, test, and tooling fixes #66970

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

Clear filters
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
Diff view
Prev Previous commit
Next Next commit
crypto: remove KEM key locking
ncrypto::KEM creates a new EVP_PKEY_CTX per operation. Parameters,
entropy, scratch buffers, and outputs are private to each call. ML-KEM
expansion finishes during import, and operations read an immutable key.
EC and X25519 retain read-only recipient keys. RSA synchronizes mutable
caches internally.

Remove the outer locks serializing jobs that share a KeyObject or
CryptoKey. Cover cold keys and worker clones across RSA, EC, X25519, and
ML-KEM, checking every resulting shared secret.

Refs: https://docs.openssl.org/3.5/man7/openssl-threads/
Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
PR-URL: #66413
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@panva
panva committed Oct 28, 2026
commit 138ed26178c5962232f8b543f44f959022b73d1b

There are no files selected for viewing

2 changes: 0 additions & 2 deletions 2 src/crypto/crypto_kem.cc
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ KEMEncapsulateJob::KEMEncapsulateJob(Environment* env,
void KEMEncapsulateJob::DoThreadPoolWork() {
ncrypto::ClearErrorOnReturn clear_error_on_return;
AdditionalParams* params = CryptoJob<KEMEncapsulateTraits>::params();
Mutex::ScopedLock lock(params->key.mutex());
auto result = ncrypto::KEM::Encapsulate(params->key.GetAsymmetricKey());
if (result) {
out_.emplace();
Expand Down Expand Up @@ -228,7 +227,6 @@ bool KEMDecapsulateTraits::DeriveBits(Environment* env,
const KEMConfiguration& params,
ByteSource* out,
CryptoJobMode mode) {
Mutex::ScopedLock lock(params.key.mutex());
const auto& private_key = params.key.GetAsymmetricKey();

return DoKEMDecapsulate(env, private_key, params.ciphertext, out, mode);
Expand Down
140 changes: 140 additions & 0 deletions 140 test/parallel/test-crypto-kem-shared-key.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
'use strict';

const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

const assert = require('assert');
const {
createPrivateKey,
createPublicKey,
encapsulate,
decapsulate,
} = require('crypto');
const { once } = require('events');
const { promisify } = require('util');
const { Worker, parentPort, workerData } = require('worker_threads');
const { hasOpenSSL, hasFIPS, isBoringSSL } = require('../common/crypto');
const fixtures = require('../common/fixtures');
const { subtle } = globalThis.crypto;

if (!hasOpenSSL(3) && !isBoringSSL)
common.skip('requires OpenSSL >= 3 or BoringSSL');

const encapsulateAsync = promisify(encapsulate);
const decapsulateAsync = promisify(decapsulate);

async function encapsulateKeys(keys) {
const operations = Array.from({ length: 4 }, () =>
encapsulateAsync(keys.publicKey));
operations.push(encapsulate(keys.publicKey));
if (keys.publicCryptoKey) {
operations.push(subtle.encapsulateBits('ML-KEM-768', keys.publicCryptoKey));
}

const results = await Promise.all(operations);
for (const { sharedKey, ciphertext } of results) {
assert.strictEqual(sharedKey.byteLength, keys.sharedSecretLength);
assert.strictEqual(ciphertext.byteLength, keys.ciphertextLength);
}
return results;
}

async function decapsulateKeys(keys, results) {
const operations = results.map(common.mustCall(async ({ sharedKey, ciphertext }) => {
const result = await decapsulateAsync(keys.privateKey, ciphertext);
assert.deepStrictEqual(result, Buffer.from(sharedKey));
}, results.length));

for (const { sharedKey, ciphertext } of results) {
assert.deepStrictEqual(
decapsulate(keys.privateKey, ciphertext), Buffer.from(sharedKey));
if (keys.privateCryptoKey) {
operations.push(subtle.decapsulateBits(
'ML-KEM-768', keys.privateCryptoKey, ciphertext,
).then((result) => {
assert.deepStrictEqual(Buffer.from(result), Buffer.from(sharedKey));
}));
}
}

await Promise.all(operations);
}

function waitForStart(barrier, phase) {
parentPort.postMessage(phase);
Atomics.wait(barrier, phase, 0);
}

async function runWorker() {
const barrier = new Int32Array(workerData.barrier);
waitForStart(barrier, 0);
const results = await encapsulateKeys(workerData.keys);
waitForStart(barrier, 1);
await decapsulateKeys(workerData.keys, results);
}

async function testKeys(keys) {
const barrier = new Int32Array(new SharedArrayBuffer(8));
const workers = Array.from({ length: 3 }, () => new Worker(__filename, {
workerData: { test: 'kem-shared-key', keys, barrier: barrier.buffer },
}));
const exits = workers.map((worker) => once(worker, 'exit'));

// Synchronize each phase before the backing keys have been used for it.
const ready = await Promise.all(
workers.map((worker) => once(worker, 'message')));
for (const [phase] of ready)
assert.strictEqual(phase, 0);
const decapsulateReady = workers.map((worker) => once(worker, 'message'));
Atomics.store(barrier, 0, 1);
Atomics.notify(barrier, 0);
const results = await encapsulateKeys(keys);

for (const [phase] of await Promise.all(decapsulateReady))
assert.strictEqual(phase, 1);
Atomics.store(barrier, 1, 1);
Atomics.notify(barrier, 1);
await decapsulateKeys(keys, results);

for (const [code] of await Promise.all(exits))
assert.strictEqual(code, 0);
}

async function runMain() {
const types = [];
if (hasOpenSSL(3)) {
types.push(['rsa', 'rsa', 256, 256]);
}
if (hasOpenSSL(3, 2) && !hasFIPS(3)) {
types.push(['ec', 'ec_p256', 32, 65], ['x25519', 'x25519', 32, 32]);
}
if (hasOpenSSL(3, 5) || isBoringSSL) {
types.push(['ml-kem-768', 'ml_kem_768', 32, 1088]);
}

for (const [type, prefix, sharedSecretLength, ciphertextLength] of types) {
const suffix = type === 'rsa' ? '_2048' : '';
const privateSuffix = type === 'ml-kem-768' ? '_seed_only' : suffix;
const publicKey = createPublicKey(fixtures.readKey(
`${prefix}_public${suffix}.pem`));
const privateKey = createPrivateKey(fixtures.readKey(
`${prefix}_private${privateSuffix}.pem`));
const keys = {
publicKey, privateKey, sharedSecretLength, ciphertextLength,
};
if (type === 'ml-kem-768') {
keys.publicCryptoKey = publicKey.toCryptoKey(
'ML-KEM-768', false, ['encapsulateBits']);
keys.privateCryptoKey = privateKey.toCryptoKey(
'ML-KEM-768', false, ['decapsulateBits']);
}
await testKeys(keys);
}
}

if (workerData?.test === 'kem-shared-key') {
runWorker().then(common.mustCall());
} else {
runMain().then(common.mustCall());
}
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.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.