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
crypto: isolate provider EC PKCS8 encoding
OpenSSL's provider ec_pki_priv_to_der() temporarily changes EC_KEY
encoding flags on the input key. Concurrent PKCS8 exports can emit
inconsistent DER or affect a concurrent SEC1 export. The old Node key
mutex never covered this path.

Encode provider EC and SM2 keys through EVP_PKEY_dup(), preserving
encoding flags, point conversion form, parameters, and provider.
Legacy OpenSSL and BoringSSL already encode using local flags.

Restore concurrent KeyObject PKCS8 DER assertions and cover PEM and
SEC1 exports, including ECPrivateKey inputs without a public point.

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 Oct 1, 2026
commit 61f898263edee589130c41d3681195b638cc4ac2

There are no files selected for viewing

19 changes: 17 additions & 2 deletions 19 deps/ncrypto/ncrypto.cc
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -4401,11 +4401,26 @@ Result<BIOPointer, bool> EVPKeyPointer::writePrivateKey(
break;
}
case PKEncodingType::PKCS8: {
EVP_PKEY* export_key = get();
#if NCRYPTO_USE_OPENSSL3_PROVIDER
// OpenSSL's provider EC PKCS8 encoders temporarily change encoding flags.
// Use an independent key so concurrent exports do not change the source.
EVPKeyPointer key_copy;
if ((isA(KeyAlgorithm::EC) || isA(KeyAlgorithm::SM2)) &&
EVP_PKEY_get0_provider(get()) != nullptr) {
key_copy.reset(EVP_PKEY_dup(get()));
if (!key_copy) {
return Result<BIOPointer, bool>(false,
mark_pop_error_on_return.peekError());
}
export_key = key_copy.get();
}
#endif
switch (config.format) {
case PKFormatType::PEM: {
// Encode PKCS#8 as PEM.
err = PEM_write_bio_PKCS8PrivateKey(bio.get(),
get(),
export_key,
config.cipher,
passphrase.data,
passphrase.len,
Expand All @@ -4415,7 +4430,7 @@ Result<BIOPointer, bool> EVPKeyPointer::writePrivateKey(
}
case PKFormatType::DER: {
err = i2d_PKCS8PrivateKey_bio(bio.get(),
get(),
export_key,
config.cipher,
passphrase.data,
passphrase.len,
Expand Down
16 changes: 12 additions & 4 deletions 16 test/parallel/test-crypto-key-reuse-concurrent.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const signAsync = promisify(sign);
const verifyAsync = promisify(verify);
const ecdsa = { name: 'ECDSA', hash: 'SHA-256' };
const pkcs8 = { type: 'pkcs8', format: 'der' };
const pkcs8Pem = { type: 'pkcs8', format: 'pem' };
const sec1 = { type: 'sec1', format: 'der' };
const spki = { type: 'spki', format: 'der' };
const iterations = 16;

Expand All @@ -33,6 +35,8 @@ async function exercise({ keys, peer, expected }) {
key: expected.originalPrivate, ...pkcs8,
});
const referencePublic = createPublicKey({ key: expected.public, ...spki });
const referencePem = referencePrivate.export(pkcs8Pem);
const referenceSec1 = referencePrivate.export(sec1);

for (let i = 0; i < iterations; i++) {
const data = Buffer.from(`shared key operation ${i}`);
Expand Down Expand Up @@ -103,6 +107,10 @@ async function exercise({ keys, peer, expected }) {
}), Buffer.from(expected.compressedPublic));
assert.deepStrictEqual(
publicKey.export(spki), Buffer.from(expected.public));
assert.deepStrictEqual(
privateKey.export(pkcs8), Buffer.from(expected.originalPrivate));
assert.strictEqual(privateKey.export(pkcs8Pem), referencePem);
assert.deepStrictEqual(privateKey.export(sec1), referenceSec1);

if (keys.ecdsaPrivate === undefined) {
assert.deepStrictEqual(diffieHellman({
Expand Down Expand Up @@ -184,12 +192,12 @@ if (workerData?.sharedKeyTest) {
Atomics.notify(barrier, 0);
await Promise.all([exercise(data), ...exited]);

// Ordinary PKCS8 encoding temporarily changes EC encoding flags in some
// OpenSSL versions, so compare only after all shared-key users finish.
// WebCrypto export must add the public point on a copy and leave the
// original key's encoding flags unchanged.
// PKCS8 export must leave the source encoding flags unchanged, including
// whether SEC1 includes parameters and whether the public point is omitted.
assert.deepStrictEqual(
privateKey.export(pkcs8), Buffer.from(expected.originalPrivate));
assert.deepStrictEqual(privateKey.export(sec1),
createPrivateKey({ key: input, ...pkcs8 }).export(sec1));
}

(async () => {
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.
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.