Skip to content

SLH-DSA: add EVP_PKEY_SLHDSA - #3879

Draft
jakemas wants to merge 1 commit into
feat/slh-dsa-2-keccakfrom
feat/slh-dsa-3-evp
Draft

jakemas wants to merge 1 commit into
feat/slh-dsa-2-keccakfrom
feat/slh-dsa-3-evp

Conversation

@jakemas

@jakemas jakemas commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Context and motivation

Stacked on #3878, which is stacked on #3877.

#3877 adds SLH-DSA (FIPS 205) to the FIPS module, with no public API. This PR makes it usable through EVP.

Description of changes

Adds the EVP_PKEY_SLHDSA key type. As for ML-DSA, the NID selects the parameter set. As in RFC 9909, it also selects the mode:

  • Pure SLH-DSA keys use NID_SLH_DSA_SHAKE_{128,192,256}s.
  • HashSLH-DSA keys use NID_SLH_DSA_SHAKE_128s_WITH_SHAKE128 and NID_SLH_DSA_SHAKE_{192,256}s_WITH_SHAKE256, and are bound to that pre-hash function.

New functions: EVP_PKEY_CTX_slhdsa_set_params, EVP_PKEY_slhdsa_new_raw_public_key, EVP_PKEY_slhdsa_new_raw_private_key and EVP_PKEY_slhdsa_get_type.

RFC 9909, Section 8 says a key may only be used in its own mode, so:

  • EVP_DigestSign and EVP_DigestVerify are one-shot. They use pure SLH-DSA for a pure key, and HashSLH-DSA for a HashSLH-DSA key.
  • EVP_PKEY_sign and EVP_PKEY_verify take the digest (SHAKE128(M, 256) or SHAKE256(M, 512)), and only HashSLH-DSA keys support them.
  • EVP_PKEY_CTX_set_signature_md accepts only a HashSLH-DSA key's own pre-hash function. A pure key rejects any digest.

All of these take the context string from EVP_PKEY_CTX_set1_signature_context_string.

Importing a raw private key regenerates PK.root and rejects the key if it does not match. EVP_PKEY_check does the same, and EVP_PKEY_public_check accepts any SLH-DSA public key.

The new objects are NID_SLHDSA (no OID), the pure SLH-DSA NIDs at 2.16.840.1.101.3.4.3.{26,28,30}, and the HashSLH-DSA NIDs at 2.16.840.1.101.3.4.3.{41,43,45}, with OpenSSL 3.5's names.

Also adds SLH-DSA to bssl speed, and bumps AWSLC_API_VERSION to 39.

SubjectPublicKeyInfo and PKCS #8 encoding come in the next PR. SLH-DSA is still not an approved FIPS service.

Testing

  • p_slhdsa_test.cc runs the ACVP signature vectors through EVP. It also covers key generation, raw key import and export, both signing interfaces in both modes, context strings, mode and digest mismatches, and key checks, and checks that SLH-DSA is not reported as an approved service.
  • obj_test.cc checks the new NIDs, names and OIDs.
  • As in Add SLH-DSA (FIPS 205) to the FIPS module #3877, the tests that sign many times are disabled by default and run natively from util/all_tests.json, not under valgrind or SDE.

Review considerations

  • This adds public API in evp.h and nid.h: NIDs 1001 to 1007, and four functions.
  • SpeedDigestSignNID in tool/speed.cc, which ML-DSA uses, now shares its timing code with SLH-DSA, and it checks the return value of EVP_PKEY_CTX_pqdsa_set_params.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

Add an EVP key type for SLH-DSA. As for ML-DSA, the NID selects the
parameter set; it also selects the mode, as in RFC 9909:

  EVP_PKEY_CTX_slhdsa_set_params(ctx, NID_SLH_DSA_SHAKE_128s);
  EVP_PKEY_slhdsa_new_raw_public_key(nid, in, len);
  EVP_PKEY_slhdsa_new_raw_private_key(nid, in, len);
  EVP_PKEY_slhdsa_get_type(pkey);

Pure SLH-DSA keys use NID_SLH_DSA_SHAKE_{128,192,256}s. HashSLH-DSA keys
use NID_SLH_DSA_SHAKE_128s_WITH_SHAKE128 and
NID_SLH_DSA_SHAKE_{192,256}s_WITH_SHAKE256, and are bound to that
pre-hash function. RFC 9909, Section 8 says a key may only be used in
its own mode, so:

- EVP_DigestSign and EVP_DigestVerify are one-shot. They sign the message
  with pure SLH-DSA, or with HashSLH-DSA for a HashSLH-DSA key.
- EVP_PKEY_sign and EVP_PKEY_verify take the digest, SHAKE128(M, 256) or
  SHAKE256(M, 512), and only HashSLH-DSA keys support them.
- EVP_PKEY_CTX_set_signature_md accepts only a HashSLH-DSA key's own
  pre-hash function. A pure key rejects any digest at initialization.

All of these use the context string set by
EVP_PKEY_CTX_set1_signature_context_string.

Importing a raw private key regenerates PK.root and rejects the key if it
does not match. EVP_PKEY_check does the same for SLH-DSA keys, and
EVP_PKEY_public_check accepts any SLH-DSA public key.

The new objects are NID_SLHDSA, which has no OID; the pure SLH-DSA NIDs
at 2.16.840.1.101.3.4.3.{26,28,30}; and the HashSLH-DSA NIDs at
2.16.840.1.101.3.4.3.{41,43,45}. They use OpenSSL 3.5's names.

Encoding keys as SubjectPublicKeyInfo or PKCS #8 is not yet supported.
SLH-DSA remains a non-approved service.

Also add SLH-DSA to bssl speed, and bump AWSLC_API_VERSION to 39.
SpeedDigestSignNID, used by ML-DSA, is refactored to share the timing
code, and now checks the EVP_PKEY_CTX_pqdsa_set_params return value.
@jakemas
jakemas added this pull request to stack #3881 December 3, 2026 20:12

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

EXPECT_EQ(EVP_PKEY_size(pkey.get()), (int)GetParam().signature_bytes);
EXPECT_EQ(EVP_PKEY_bits(pkey.get()), 8 * (int)GetParam().public_key_bytes);

size_t len;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'len' is not initialized [cppcoreguidelines-init-variables]

Suggested change
size_t len;
size_t len = 0;

ASSERT_TRUE(EVP_PKEY_set_type(empty.get(), EVP_PKEY_SLHDSA));
EXPECT_EQ(EVP_PKEY_size(empty.get()), 0);
EXPECT_EQ(EVP_PKEY_bits(empty.get()), 0);
size_t len;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'len' is not initialized [cppcoreguidelines-init-variables]

Suggested change
size_t len;
size_t len = 0;

@@ -24,6 +24,7 @@ DEFINE_LOCAL_DATA(struct fips_evp_pkey_methods, AWSLC_fips_evp_pkey_methods) {
out->methods[6] = EVP_PKEY_kem_pkey_meth();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'out' [clang-diagnostic-error]

  out->methods[6] = EVP_PKEY_kem_pkey_meth();
  ^

@@ -24,6 +24,7 @@ DEFINE_LOCAL_DATA(struct fips_evp_pkey_methods, AWSLC_fips_evp_pkey_methods) {
out->methods[6] = EVP_PKEY_kem_pkey_meth();
out->methods[7] = EVP_PKEY_pqdsa_pkey_meth();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'out' [clang-diagnostic-error]

  out->methods[7] = EVP_PKEY_pqdsa_pkey_meth();
  ^

@@ -24,6 +24,7 @@ DEFINE_LOCAL_DATA(struct fips_evp_pkey_methods, AWSLC_fips_evp_pkey_methods) {
out->methods[6] = EVP_PKEY_kem_pkey_meth();
out->methods[7] = EVP_PKEY_pqdsa_pkey_meth();
out->methods[8] = EVP_PKEY_ed25519ph_pkey_meth();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'out' [clang-diagnostic-error]

  out->methods[8] = EVP_PKEY_ed25519ph_pkey_meth();
  ^

out->methods[6] = EVP_PKEY_kem_pkey_meth();
out->methods[7] = EVP_PKEY_pqdsa_pkey_meth();
out->methods[8] = EVP_PKEY_ed25519ph_pkey_meth();
out->methods[9] = EVP_PKEY_slhdsa_pkey_meth();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'out' [clang-diagnostic-error]

  out->methods[9] = EVP_PKEY_slhdsa_pkey_meth();
  ^

}

SLHDSA_KEY *SLHDSA_KEY_new(int nid) {
int hash_nid;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'hash_nid' is not initialized [cppcoreguidelines-init-variables]

Suggested change
int hash_nid;
int hash_nid = 0;

const SLHDSA_PKEY_CTX *dctx = ctx->data;
const uint8_t *context = dctx->context_len > 0 ? dctx->context : NULL;
const size_t sk_len = slh_dsa_private_key_bytes(key->params);
int ok;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'ok' is not initialized [cppcoreguidelines-init-variables]

Suggested change
int ok;
int ok = 0;

const SLHDSA_PKEY_CTX *dctx = ctx->data;
const uint8_t *context = dctx->context_len > 0 ? dctx->context : NULL;
const size_t pk_len = slh_dsa_public_key_bytes(key->params);
int ok;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'ok' is not initialized [cppcoreguidelines-init-variables]

Suggested change
int ok;
int ok = 0;

OPENSSL_PUT_ERROR(EVP, EVP_R_INVALID_OPERATION);
return 0;
}
int hash_nid;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'hash_nid' is not initialized [cppcoreguidelines-init-variables]

Suggested change
int hash_nid;
int hash_nid = 0;

@jakemas
jakemas force-pushed the feat/slh-dsa-3-evp branch from 8c9dd0e to 7d1a1cc Compare December 3, 2026 22:16
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.50129% with 35 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (feat/slh-dsa-2-keccak@4d6be8c). Learn more about missing BASE report.

Files with missing lines Patch % Lines
crypto/fipsmodule/evp/p_slhdsa.c 92.17% 23 Missing ⚠️
crypto/evp_extra/evp_asn1.c 66.66% 6 Missing ⚠️
crypto/evp_extra/p_slhdsa_test.cc 98.52% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@                   Coverage Diff                    @@
##             feat/slh-dsa-2-keccak    #3879   +/-   ##
========================================================
  Coverage                         ?   79.26%           
========================================================
  Files                            ?      727           
  Lines                            ?   137287           
  Branches                         ?    19704           
========================================================
  Hits                             ?   108821           
  Misses                           ?    27418           
  Partials                         ?     1048           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

🔒 Security Review — View Report

Please review before merging.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants