Commit 3ea95474bef for nodejs

commit 3ea95474bef89fddc6d1980049935d6b96588052
Author: Filip Skokan <panva.ip@gmail.com>
Date:   Sun Nov 15 10:46:27 2026 +0100

    crypto: wire up SLH-DSA with BoringSSL

    Map SLH-DSA-SHA2-128s and SLH-DSA-SHAKE-256f to the native key IDs and
    raw-key descriptors for key generation, raw and JWK operations, and
    one-shot signatures with contexts.

    Run the existing cases for these variants with JWK fixtures on
    BoringSSL, whose generic key parsers omit SLH-DSA.

    Signed-off-by: Filip Skokan <panva.ip@gmail.com>
    Assisted-by: Codex
    PR-URL: https://github.com/nodejs/node/pull/67483
    Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
    Reviewed-By: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>

diff --git a/deps/ncrypto/ncrypto.cc b/deps/ncrypto/ncrypto.cc
index 322e16279ad..001f366ce12 100644
--- a/deps/ncrypto/ncrypto.cc
+++ b/deps/ncrypto/ncrypto.cc
@@ -3636,6 +3636,8 @@ const BoringSSLKeyAlgorithm kBoringSSLKeyAlgorithms[] = {
     {KeyAlgorithm::ML_DSA_87.name(), EVP_PKEY_ML_DSA_87, EVP_pkey_ml_dsa_87},
     {KeyAlgorithm::ML_KEM_768.name(), EVP_PKEY_ML_KEM_768, EVP_pkey_ml_kem_768},
     {KeyAlgorithm::ML_KEM_1024.name(), EVP_PKEY_ML_KEM_1024, EVP_pkey_ml_kem_1024},
+    {KeyAlgorithm::SLH_DSA_SHA2_128S.name(), EVP_PKEY_SLH_DSA_SHA2_128S, EVP_pkey_slh_dsa_sha2_128s},
+    {KeyAlgorithm::SLH_DSA_SHAKE_256F.name(), EVP_PKEY_SLH_DSA_SHAKE_256F, EVP_pkey_slh_dsa_shake_256f},
 };
 // NOLINTEND(whitespace/line_length)
 // clang-format on
diff --git a/test/parallel/test-crypto-pqc-key-objects-slh-dsa.js b/test/parallel/test-crypto-pqc-key-objects-slh-dsa.js
index 3f0dbc73ba5..9aae5cacbfc 100644
--- a/test/parallel/test-crypto-pqc-key-objects-slh-dsa.js
+++ b/test/parallel/test-crypto-pqc-key-objects-slh-dsa.js
@@ -107,13 +107,21 @@ for (const asymmetricKeyType of [
     assert.throws(() => createPrivateKey(keys.private), {
       code: isBoringSSL ? 'ERR_OSSL_EVP_UNSUPPORTED_ALGORITHM' : 'ERR_OSSL_UNSUPPORTED',
     });
-  } else {
-    const publicKey = createPublicKey(keys.public);
+  }
+
+  const supported = hasOpenSSL(3, 5) ||
+    (isBoringSSL && (asymmetricKeyType === 'slh-dsa-sha2-128s' ||
+                    asymmetricKeyType === 'slh-dsa-shake-256f'));
+  if (supported) {
+    const publicKey = createPublicKey(isBoringSSL ?
+      { format: 'jwk', key: keys.jwk } : keys.public);
+    const privateKey = createPrivateKey(isBoringSSL ?
+      { format: 'jwk', key: keys.jwk } : keys.private);
     assertPublicKey(publicKey);

-    const pubFromPriv = createPublicKey(keys.private);
+    const pubFromPriv = createPublicKey(isBoringSSL ? privateKey : keys.private);
     assertPublicKey(pubFromPriv);
-    assertPrivateKey(createPrivateKey(keys.private));
+    assertPrivateKey(privateKey);
     assert.strictEqual(pubFromPriv.equals(publicKey), true);

     // JWK import error tests
diff --git a/test/parallel/test-crypto-pqc-keygen-slh-dsa.js b/test/parallel/test-crypto-pqc-keygen-slh-dsa.js
index a8e480818cd..2d3fc3c578b 100644
--- a/test/parallel/test-crypto-pqc-keygen-slh-dsa.js
+++ b/test/parallel/test-crypto-pqc-keygen-slh-dsa.js
@@ -4,31 +4,27 @@ const common = require('../common');
 if (!common.hasCrypto)
   common.skip('missing crypto');

-const { hasOpenSSL } = require('../common/crypto');
+const { hasOpenSSL, isBoringSSL } = require('../common/crypto');

 const assert = require('assert');
 const {
   generateKeyPair,
 } = require('crypto');

-if (!hasOpenSSL(3, 5)) {
-  for (const asymmetricKeyType of [
-    'slh-dsa-sha2-128f', 'slh-dsa-sha2-128s', 'slh-dsa-sha2-192f', 'slh-dsa-sha2-192s',
-    'slh-dsa-sha2-256f', 'slh-dsa-sha2-256s', 'slh-dsa-shake-128f', 'slh-dsa-shake-128s',
-    'slh-dsa-shake-192f', 'slh-dsa-shake-192s', 'slh-dsa-shake-256f', 'slh-dsa-shake-256s',
-  ]) {
+for (const asymmetricKeyType of [
+  'slh-dsa-sha2-128f', 'slh-dsa-sha2-128s', 'slh-dsa-sha2-192f', 'slh-dsa-sha2-192s',
+  'slh-dsa-sha2-256f', 'slh-dsa-sha2-256s', 'slh-dsa-shake-128f', 'slh-dsa-shake-128s',
+  'slh-dsa-shake-192f', 'slh-dsa-shake-192s', 'slh-dsa-shake-256f', 'slh-dsa-shake-256s',
+]) {
+  const supported = hasOpenSSL(3, 5) ||
+    (isBoringSSL && (asymmetricKeyType === 'slh-dsa-sha2-128s' ||
+                    asymmetricKeyType === 'slh-dsa-shake-256f'));
+  if (!supported) {
     assert.throws(() => generateKeyPair(asymmetricKeyType, common.mustNotCall()), {
       code: 'ERR_INVALID_ARG_VALUE',
       message: /The argument 'type' must be a supported key type/
     });
-  }
-} else {
-  for (const asymmetricKeyType of [
-    'slh-dsa-sha2-128f', 'slh-dsa-sha2-128s', 'slh-dsa-sha2-192f', 'slh-dsa-sha2-192s',
-    'slh-dsa-sha2-256f', 'slh-dsa-sha2-256s', 'slh-dsa-shake-128f', 'slh-dsa-shake-128s',
-    'slh-dsa-shake-192f', 'slh-dsa-shake-192s', 'slh-dsa-shake-256f', 'slh-dsa-shake-256s',
-  ]) {
-
+  } else {
     function assertJwk(jwk) {
       assert.strictEqual(jwk.kty, 'AKP');
       // SLH-DSA algorithm names keep the last character (f/s) lowercase.
diff --git a/test/pummel/test-crypto-pqc-sign-verify-slh-dsa.mjs b/test/pummel/test-crypto-pqc-sign-verify-slh-dsa.mjs
index 52b018e7028..98c6ef837e7 100644
--- a/test/pummel/test-crypto-pqc-sign-verify-slh-dsa.mjs
+++ b/test/pummel/test-crypto-pqc-sign-verify-slh-dsa.mjs
@@ -3,14 +3,14 @@ import * as common from '../common/index.mjs';
 if (!common.hasCrypto)
   common.skip('missing crypto');

-import { hasOpenSSL } from '../common/crypto.js';
+import { hasOpenSSL, isBoringSSL } from '../common/crypto.js';

-if (!hasOpenSSL(3, 5))
-  common.skip('requires OpenSSL >= 3.5');
+if (!hasOpenSSL(3, 5) && !isBoringSSL)
+  common.skip('requires OpenSSL >= 3.5 or BoringSSL');

 import * as assert from 'node:assert';
 import { promisify } from 'node:util';
-import { randomBytes, sign, verify } from 'node:crypto';
+import { createPrivateKey, createPublicKey, randomBytes, sign, verify } from 'node:crypto';
 import fixtures from '../common/fixtures.js';

 const pSign = promisify(sign);
@@ -34,10 +34,20 @@ for (const [asymmetricKeyType, sigLen] of [
   ['slh-dsa-shake-256f', 49856],
   ['slh-dsa-shake-256s', 29792],
 ]) {
+  if (isBoringSSL && asymmetricKeyType !== 'slh-dsa-sha2-128s' &&
+      asymmetricKeyType !== 'slh-dsa-shake-256f') {
+    common.printSkipMessage(`Skipping unsupported ${asymmetricKeyType}`);
+    continue;
+  }
   const keys = {
     public: fixtures.readKey(getKeyFileName(asymmetricKeyType, 'public'), 'ascii'),
     private: fixtures.readKey(getKeyFileName(asymmetricKeyType, 'private'), 'ascii'),
   };
+  if (isBoringSSL) {
+    const jwk = JSON.parse(fixtures.readKey(`${asymmetricKeyType}.json`));
+    keys.public = createPublicKey({ format: 'jwk', key: jwk });
+    keys.private = createPrivateKey({ format: 'jwk', key: jwk });
+  }

   const data = randomBytes(32);
   // Start the async signature before the sync work to overlap the two.
@@ -59,8 +69,10 @@ for (const [asymmetricKeyType, sigLen] of [
     assert.strictEqual(await pVerify(undefined, data, keys.public, signature), true);
   }

-  assert.throws(() => sign('sha256', data, keys.private), { code: 'ERR_OSSL_INVALID_DIGEST' });
+  const code = isBoringSSL ?
+    'ERR_OSSL_EVP_COMMAND_NOT_SUPPORTED' : 'ERR_OSSL_INVALID_DIGEST';
+  assert.throws(() => sign('sha256', data, keys.private), { code });
   assert.throws(
     () => verify('sha256', data, keys.public, Buffer.alloc(sigLen)),
-    { code: 'ERR_OSSL_INVALID_DIGEST' });
+    { code });
 }