From 42cceddc23987d2b7490e1c47a1a42f5849fec62 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Wed, 13 Aug 2025 17:47:37 +0200 Subject: [PATCH 1/2] crypto: support SLH-DSA KeyObject, sign, and verify --- deps/ncrypto/ncrypto.cc | 24 +++++ doc/api/crypto.md | 61 ++++++++---- lib/internal/crypto/keygen.js | 51 ++++++---- src/crypto/crypto_keys.cc | 36 +++++++ src/env_properties.h | 12 +++ test/fixtures/keys/Makefile | 96 +++++++++++++++++++ .../keys/slh_dsa_sha2_128f_private.pem | 4 + .../keys/slh_dsa_sha2_128f_public.pem | 4 + .../keys/slh_dsa_sha2_128s_private.pem | 4 + .../keys/slh_dsa_sha2_128s_public.pem | 4 + .../keys/slh_dsa_sha2_192f_private.pem | 5 + .../keys/slh_dsa_sha2_192f_public.pem | 4 + .../keys/slh_dsa_sha2_192s_private.pem | 5 + .../keys/slh_dsa_sha2_192s_public.pem | 4 + .../keys/slh_dsa_sha2_256f_private.pem | 6 ++ .../keys/slh_dsa_sha2_256f_public.pem | 4 + .../keys/slh_dsa_sha2_256s_private.pem | 6 ++ .../keys/slh_dsa_sha2_256s_public.pem | 4 + .../keys/slh_dsa_shake_128f_private.pem | 4 + .../keys/slh_dsa_shake_128f_public.pem | 4 + .../keys/slh_dsa_shake_128s_private.pem | 4 + .../keys/slh_dsa_shake_128s_public.pem | 4 + .../keys/slh_dsa_shake_192f_private.pem | 5 + .../keys/slh_dsa_shake_192f_public.pem | 4 + .../keys/slh_dsa_shake_192s_private.pem | 5 + .../keys/slh_dsa_shake_192s_public.pem | 4 + .../keys/slh_dsa_shake_256f_private.pem | 6 ++ .../keys/slh_dsa_shake_256f_public.pem | 4 + .../keys/slh_dsa_shake_256s_private.pem | 6 ++ .../keys/slh_dsa_shake_256s_public.pem | 4 + .../test-crypto-pqc-key-objects-slh-dsa.js | 74 ++++++++++++++ .../test-crypto-pqc-keygen-slh-dsa.js | 54 +++++++++++ .../test-crypto-pqc-sign-verify-slh-dsa.mjs | 63 ++++++++++++ 33 files changed, 542 insertions(+), 37 deletions(-) create mode 100644 test/fixtures/keys/slh_dsa_sha2_128f_private.pem create mode 100644 test/fixtures/keys/slh_dsa_sha2_128f_public.pem create mode 100644 test/fixtures/keys/slh_dsa_sha2_128s_private.pem create mode 100644 test/fixtures/keys/slh_dsa_sha2_128s_public.pem create mode 100644 test/fixtures/keys/slh_dsa_sha2_192f_private.pem create mode 100644 test/fixtures/keys/slh_dsa_sha2_192f_public.pem create mode 100644 test/fixtures/keys/slh_dsa_sha2_192s_private.pem create mode 100644 test/fixtures/keys/slh_dsa_sha2_192s_public.pem create mode 100644 test/fixtures/keys/slh_dsa_sha2_256f_private.pem create mode 100644 test/fixtures/keys/slh_dsa_sha2_256f_public.pem create mode 100644 test/fixtures/keys/slh_dsa_sha2_256s_private.pem create mode 100644 test/fixtures/keys/slh_dsa_sha2_256s_public.pem create mode 100644 test/fixtures/keys/slh_dsa_shake_128f_private.pem create mode 100644 test/fixtures/keys/slh_dsa_shake_128f_public.pem create mode 100644 test/fixtures/keys/slh_dsa_shake_128s_private.pem create mode 100644 test/fixtures/keys/slh_dsa_shake_128s_public.pem create mode 100644 test/fixtures/keys/slh_dsa_shake_192f_private.pem create mode 100644 test/fixtures/keys/slh_dsa_shake_192f_public.pem create mode 100644 test/fixtures/keys/slh_dsa_shake_192s_private.pem create mode 100644 test/fixtures/keys/slh_dsa_shake_192s_public.pem create mode 100644 test/fixtures/keys/slh_dsa_shake_256f_private.pem create mode 100644 test/fixtures/keys/slh_dsa_shake_256f_public.pem create mode 100644 test/fixtures/keys/slh_dsa_shake_256s_private.pem create mode 100644 test/fixtures/keys/slh_dsa_shake_256s_public.pem create mode 100644 test/parallel/test-crypto-pqc-key-objects-slh-dsa.js create mode 100644 test/parallel/test-crypto-pqc-keygen-slh-dsa.js create mode 100644 test/pummel/test-crypto-pqc-sign-verify-slh-dsa.mjs diff --git a/deps/ncrypto/ncrypto.cc b/deps/ncrypto/ncrypto.cc index 290c3a816fe310..419824b3891f38 100644 --- a/deps/ncrypto/ncrypto.cc +++ b/deps/ncrypto/ncrypto.cc @@ -25,6 +25,18 @@ constexpr static PQCMapping pqc_mappings[] = { {"ML-KEM-512", EVP_PKEY_ML_KEM_512}, {"ML-KEM-768", EVP_PKEY_ML_KEM_768}, {"ML-KEM-1024", EVP_PKEY_ML_KEM_1024}, + {"SLH-DSA-SHA2-128f", EVP_PKEY_SLH_DSA_SHA2_128F}, + {"SLH-DSA-SHA2-128s", EVP_PKEY_SLH_DSA_SHA2_128S}, + {"SLH-DSA-SHA2-192f", EVP_PKEY_SLH_DSA_SHA2_192F}, + {"SLH-DSA-SHA2-192s", EVP_PKEY_SLH_DSA_SHA2_192S}, + {"SLH-DSA-SHA2-256f", EVP_PKEY_SLH_DSA_SHA2_256F}, + {"SLH-DSA-SHA2-256s", EVP_PKEY_SLH_DSA_SHA2_256S}, + {"SLH-DSA-SHAKE-128f", EVP_PKEY_SLH_DSA_SHAKE_128F}, + {"SLH-DSA-SHAKE-128s", EVP_PKEY_SLH_DSA_SHAKE_128S}, + {"SLH-DSA-SHAKE-192f", EVP_PKEY_SLH_DSA_SHAKE_192F}, + {"SLH-DSA-SHAKE-192s", EVP_PKEY_SLH_DSA_SHAKE_192S}, + {"SLH-DSA-SHAKE-256f", EVP_PKEY_SLH_DSA_SHAKE_256F}, + {"SLH-DSA-SHAKE-256s", EVP_PKEY_SLH_DSA_SHAKE_256S}, }; #endif @@ -2545,6 +2557,18 @@ bool EVPKeyPointer::isOneShotVariant() const { case EVP_PKEY_ML_DSA_44: case EVP_PKEY_ML_DSA_65: case EVP_PKEY_ML_DSA_87: + case EVP_PKEY_SLH_DSA_SHA2_128F: + case EVP_PKEY_SLH_DSA_SHA2_128S: + case EVP_PKEY_SLH_DSA_SHA2_192F: + case EVP_PKEY_SLH_DSA_SHA2_192S: + case EVP_PKEY_SLH_DSA_SHA2_256F: + case EVP_PKEY_SLH_DSA_SHA2_256S: + case EVP_PKEY_SLH_DSA_SHAKE_128F: + case EVP_PKEY_SLH_DSA_SHAKE_128S: + case EVP_PKEY_SLH_DSA_SHAKE_192F: + case EVP_PKEY_SLH_DSA_SHAKE_192S: + case EVP_PKEY_SLH_DSA_SHAKE_256F: + case EVP_PKEY_SLH_DSA_SHAKE_256S: #endif return true; default: diff --git a/doc/api/crypto.md b/doc/api/crypto.md index a95a2a4173f32f..765b3d505e6f0c 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -77,23 +77,35 @@ try { The following table lists the asymmetric key types recognized by the [`KeyObject`][] API: -| Key Type | Description | OID | -| --------------------------- | -------------- | ----------------------- | -| `'dh'` | Diffie-Hellman | 1.2.840.113549.1.3.1 | -| `'dsa'` | DSA | 1.2.840.10040.4.1 | -| `'ec'` | Elliptic curve | 1.2.840.10045.2.1 | -| `'ed25519'` | Ed25519 | 1.3.101.112 | -| `'ed448'` | Ed448 | 1.3.101.113 | -| `'ml-dsa-44'`[^openssl35] | ML-DSA-44 | 2.16.840.1.101.3.4.3.17 | -| `'ml-dsa-65'`[^openssl35] | ML-DSA-65 | 2.16.840.1.101.3.4.3.18 | -| `'ml-dsa-87'`[^openssl35] | ML-DSA-87 | 2.16.840.1.101.3.4.3.19 | -| `'ml-kem-1024'`[^openssl35] | ML-KEM-1024 | 2.16.840.1.101.3.4.4.3 | -| `'ml-kem-512'`[^openssl35] | ML-KEM-512 | 2.16.840.1.101.3.4.4.1 | -| `'ml-kem-768'`[^openssl35] | ML-KEM-768 | 2.16.840.1.101.3.4.4.2 | -| `'rsa-pss'` | RSA PSS | 1.2.840.113549.1.1.10 | -| `'rsa'` | RSA | 1.2.840.113549.1.1.1 | -| `'x25519'` | X25519 | 1.3.101.110 | -| `'x448'` | X448 | 1.3.101.111 | +| Key Type | Description | OID | +| ---------------------------------- | ------------------ | --------------------------- | +| `'dh'` | Diffie-Hellman | 1.2.840.113549.1.3.1 | +| `'dsa'` | DSA | 1.2.840.10040.4.1 | +| `'ec'` | Elliptic curve | 1.2.840.10045.2.1 | +| `'ed25519'` | Ed25519 | 1.3.101.112 | +| `'ed448'` | Ed448 | 1.3.101.113 | +| `'ml-dsa-44'`[^openssl35] | ML-DSA-44 | 2.16.840.1.101.3.4.3.17 | +| `'ml-dsa-65'`[^openssl35] | ML-DSA-65 | 2.16.840.1.101.3.4.3.18 | +| `'ml-dsa-87'`[^openssl35] | ML-DSA-87 | 2.16.840.1.101.3.4.3.19 | +| `'ml-kem-1024'`[^openssl35] | ML-KEM-1024 | 2.16.840.1.101.3.4.4.3 | +| `'ml-kem-512'`[^openssl35] | ML-KEM-512 | 2.16.840.1.101.3.4.4.1 | +| `'ml-kem-768'`[^openssl35] | ML-KEM-768 | 2.16.840.1.101.3.4.4.2 | +| `'rsa-pss'` | RSA PSS | 1.2.840.113549.1.1.10 | +| `'rsa'` | RSA | 1.2.840.113549.1.1.1 | +| `'slh-dsa-sha2-128f'`[^openssl35] | SLH-DSA-SHA2-128f | OID 2.16.840.1.101.3.4.3.21 | +| `'slh-dsa-sha2-128s'`[^openssl35] | SLH-DSA-SHA2-128s | OID 2.16.840.1.101.3.4.3.22 | +| `'slh-dsa-sha2-192f'`[^openssl35] | SLH-DSA-SHA2-192f | OID 2.16.840.1.101.3.4.3.23 | +| `'slh-dsa-sha2-192s'`[^openssl35] | SLH-DSA-SHA2-192s | OID 2.16.840.1.101.3.4.3.24 | +| `'slh-dsa-sha2-256f'`[^openssl35] | SLH-DSA-SHA2-256f | OID 2.16.840.1.101.3.4.3.25 | +| `'slh-dsa-sha2-256s'`[^openssl35] | SLH-DSA-SHA2-256s | OID 2.16.840.1.101.3.4.3.26 | +| `'slh-dsa-shake-128f'`[^openssl35] | SLH-DSA-SHAKE-128f | OID 2.16.840.1.101.3.4.3.27 | +| `'slh-dsa-shake-128s'`[^openssl35] | SLH-DSA-SHAKE-128s | OID 2.16.840.1.101.3.4.3.28 | +| `'slh-dsa-shake-192f'`[^openssl35] | SLH-DSA-SHAKE-192f | OID 2.16.840.1.101.3.4.3.29 | +| `'slh-dsa-shake-192s'`[^openssl35] | SLH-DSA-SHAKE-192s | OID 2.16.840.1.101.3.4.3.30 | +| `'slh-dsa-shake-256f'`[^openssl35] | SLH-DSA-SHAKE-256f | OID 2.16.840.1.101.3.4.3.31 | +| `'slh-dsa-shake-256s'`[^openssl35] | SLH-DSA-SHAKE-256s | OID 2.16.840.1.101.3.4.3.32 | +| `'x25519'` | X25519 | 1.3.101.110 | +| `'x448'` | X448 | 1.3.101.111 | ## Class: `Certificate` @@ -2046,6 +2058,9 @@ Other key details might be exposed via this API using additional attributes.