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 — crypto: remove key mutexes by panva · Pull Request #66413 · nodejs/node

crypto: remove key mutexes #66413

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 6 commits into nodejs:main from panva:crypto-key-mutexes
+523 −40
Closed

crypto: remove key mutexes #66413

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit Hold shift + click to select a range
cd65dcf
crypto: skip secret key mutex allocation
panva Sep 30, 2026
71df230
crypto: remove RSA-OAEP key locking
panva Sep 30, 2026
32b22fd
crypto: remove KEM key locking
panva Sep 30, 2026
3f46289
crypto: remove verify setup key locking
panva Sep 30, 2026
286570b
crypto: remove key export and metadata locks
panva Sep 30, 2026
61f8982
crypto: isolate provider EC PKCS8 encoding
panva Oct 1, 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 RSA-OAEP key locking
RSA_Cipher delegates to ncrypto::Rsa with a new EVP_PKEY_CTX per
operation. Padding, digests, labels, and output buffers belong to that
context. OpenSSL and BoringSSL synchronize RSA blinding and Montgomery
caches internally.

The lock was introduced for early OpenSSL 3 key downgrading that cleared
shared provider fields. Current OpenSSL publishes a separate legacy
cache under its own lock.

Cover cold shared CryptoKeys and worker clones with concurrent
encrypt/decrypt, synchronous KeyObject aliases, and checked plaintexts.

Refs: #36825
Refs: https://docs.openssl.org/3.5/man7/openssl-threads/
Signed-off-by: Filip Skokan <[email protected]>
Assisted-by: Codex
  • Loading branch information

Uh oh!

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

@panva
panva committed Sep 30, 2026
commit 71df230a8dcf5e121575746079f336abe057a601

There are no files selected for viewing

1 change: 0 additions & 1 deletion 1 src/crypto/crypto_rsa.cc
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ WebCryptoCipherStatus RSA_Cipher(Environment* env,
const ByteSource& in,
ByteSource* out) {
CHECK_NE(key_data.GetKeyType(), kKeyTypeSecret);
Mutex::ScopedLock lock(key_data.mutex());
const auto& m_pkey = key_data.GetAsymmetricKey();
const ncrypto::Rsa::CipherParams nparams{
.padding = params.padding,
Expand Down
109 changes: 109 additions & 0 deletions 109 test/parallel/test-webcrypto-rsa-shared-key.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
'use strict';

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

const assert = require('assert');
const {
createPrivateKey,
createPublicKey,
privateDecrypt,
publicEncrypt,
} = require('crypto');
const { once } = require('events');
const { Worker, parentPort, workerData } = require('worker_threads');
const fixtures = require('../common/fixtures');
const { subtle } = globalThis.crypto;

const algorithm = { name: 'RSA-OAEP', hash: 'SHA-256' };
const label = Buffer.from('shared RSA-OAEP key');
const plaintext = Buffer.from('concurrent key reuse');

async function encrypt({ publicKey, publicCryptoKey }) {
const operations = Array.from({ length: 4 }, () =>
subtle.encrypt({ name: 'RSA-OAEP', label }, publicCryptoKey, plaintext));

// Exercise the synchronous API while the shared CryptoKey jobs are queued.
operations.push(publicEncrypt({
key: publicKey,
oaepHash: 'sha256',
oaepLabel: label,
}, plaintext));

const ciphertexts = await Promise.all(operations);
for (const ciphertext of ciphertexts)
assert.strictEqual(ciphertext.byteLength, 256);
return ciphertexts;
}

async function decrypt({ privateKey, privateCryptoKey }, ciphertexts) {
const operations = ciphertexts.map((ciphertext) =>
subtle.decrypt({ name: 'RSA-OAEP', label }, privateCryptoKey, ciphertext));

for (const ciphertext of ciphertexts) {
assert.deepStrictEqual(privateDecrypt({
key: privateKey,
oaepHash: 'sha256',
oaepLabel: label,
}, Buffer.from(ciphertext)), plaintext);
}

for (const result of await Promise.all(operations))
assert.deepStrictEqual(Buffer.from(result), plaintext);
}

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 ciphertexts = await encrypt(workerData.keys);
waitForStart(barrier, 1);
await decrypt(workerData.keys, ciphertexts);
}

async function runMain() {
const publicKey = createPublicKey(fixtures.readKey('rsa_public_2048.pem'));
const privateKey = createPrivateKey(fixtures.readKey('rsa_private_2048.pem'));
const keys = {
publicKey,
privateKey,
publicCryptoKey: publicKey.toCryptoKey(algorithm, false, ['encrypt']),
privateCryptoKey: privateKey.toCryptoKey(algorithm, false, ['decrypt']),
};
const barrier = new Int32Array(new SharedArrayBuffer(8));
const workers = Array.from({ length: 3 }, () => new Worker(__filename, {
workerData: { test: 'rsa-shared-key', keys, barrier: barrier.buffer },
}));
const exits = workers.map((worker) => once(worker, 'exit'));

// Clones retain the same backing keys. Release every worker together so
// their first encryption and decryption also exercise cold key state.
const ready = await Promise.all(
workers.map((worker) => once(worker, 'message')));
for (const [phase] of ready)
assert.strictEqual(phase, 0);
const decryptReady = workers.map((worker) => once(worker, 'message'));
Atomics.store(barrier, 0, 1);
Atomics.notify(barrier, 0);
const ciphertexts = await encrypt(keys);

for (const [phase] of await Promise.all(decryptReady))
assert.strictEqual(phase, 1);
Atomics.store(barrier, 1, 1);
Atomics.notify(barrier, 1);
await decrypt(keys, ciphertexts);

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

if (workerData?.test === 'rsa-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.