Skip to content

Add SLH-DSA (FIPS 205) to the FIPS module - #3842

Open
jakemas wants to merge 1 commit into
aws:mainfrom
jakemas:slh-dsa-pr1
Open

jakemas wants to merge 1 commit into
aws:mainfrom
jakemas:slh-dsa-pr1

Conversation

@jakemas

@jakemas jakemas commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Context and motivation

SLH-DSA (FIPS 205) is NIST's stateless hash-based signature standard. Its security rests only on the hash function, which makes it a conservative choice for long-lived signatures such as CA and firmware signing.

Description of changes

Adds SLH-DSA to the FIPS module in crypto/fipsmodule/slh_dsa, with the SHAKE-128s, SHAKE-192s and SHAKE-256s parameter sets. It is a port of slhdsa-c (4745143) onto AWS-LC's SHAKE.

  • Key generation, pure SLH-DSA with context strings, and HashSLH-DSA (SHAKE128 for 128s only, or SHAKE256).
  • The FIPS 205 internal functions, used by the tests.
  • Secret intermediates are cleansed (FIPS 205, Section 3.1).

There is no EVP or TLS support in this PR, and SLH-DSA is not an approved FIPS service yet.

Testing

  • NIST ACVP-Server vectors for keyGen, sigGen and sigVer on all three parameter sets.
  • Negative and API tests.
  • Signing is slow, so crypto_test runs a subset of the signing tests. The rest run natively from util/all_tests.json, not under valgrind or SDE.

Review considerations

  • No public API. The new module functions are registered as PRIVATE symbols.
  • FileTest's line buffer grows to 112 KB, as in BoringSSL, so that SHAKE-256s signatures fit.

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.

github-actions[bot]

This comment was marked as resolved.

@jakemas
jakemas force-pushed the slh-dsa-pr1 branch 2 times, most recently from 9b8f306 to e96c73e Compare November 25, 2026 01:25
@github-actions

Copy link
Copy Markdown
Contributor

🔒 Security Review — View Report

Please review before merging.

@jakemas
jakemas force-pushed the slh-dsa-pr1 branch 2 times, most recently from f3ddecf to 139a726 Compare November 25, 2026 02:43
@codecov-commenter

codecov-commenter commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.56474% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.38%. Comparing base (56d0552) to head (63d1809).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
crypto/fipsmodule/slh_dsa/slh_dsa.c 98.92% 3 Missing ⚠️
crypto/fipsmodule/slh_dsa/slh_dsa_test.cc 99.72% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           main    #3842       +/-   ##
=========================================
+ Coverage      0   79.38%   +79.38%     
=========================================
  Files         0      724      +724     
  Lines         0   137836   +137836     
  Branches      0    19950    +19950     
=========================================
+ Hits          0   109420   +109420     
- Misses        0    27351    +27351     
- Partials      0     1065     +1065     

☔ 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.

@jakemas
jakemas marked this pull request as ready for review November 30, 2026 21:27
@jakemas
jakemas requested a review from a team as a code owner November 30, 2026 21:27
Add SLH-DSA with the SHAKE-128s, SHAKE-192s and SHAKE-256s parameter
sets in crypto/fipsmodule/slh_dsa. It is a port of slhdsa-c
(pq-code-package/slhdsa-c@4745143) onto AWS-LC's SHAKE implementation.

This covers key generation, pure SLH-DSA with context strings,
HashSLH-DSA with SHAKE128 (SLH-DSA-SHAKE-128s only) or SHAKE256, and
the FIPS 205 internal functions used by the tests. Secret intermediates
are cleansed. There is no EVP or TLS support yet, and SLH-DSA is not an
approved FIPS service.

Tests use a subset of the NIST ACVP vectors. Signing is slow, so the
tests that sign many times are disabled by default and run natively from
util/all_tests.json, not under valgrind or SDE. FileTest's line buffer is
raised to fit SHAKE-256s signatures, as in BoringSSL.
Comment thread crypto/fipsmodule/slh_dsa/slh_dsa.c Outdated
Comment on lines +159 to +187
// slh_dsa_scrub_stack overwrites the stack below the caller's frame. The
// hash functions and the WOTS+, XMSS and FORS computations leave intermediate
// values, some derived from SK.seed and SK.prf, in frames that have returned.
// FIPS 205, Section 3.1 requires them to be destroyed, so every exported
// operation calls this before returning. Without the scrub, the deepest
// operation writes about 6 KB below its caller on x86_64 and AArch64; the
// margin allows for other compilers and options. The |StackScrub| test checks
// that nothing is left.
//
// The scrub only covers frames below its caller, so each exported function
// does its work in an |OPENSSL_NOINLINE| helper and scrubs after it returns.
// Otherwise, with link-time optimization, the compiler can inline that work,
// and its secret temporaries, into the exported function's own frame.
//
// It must not be inlined, or analyzed across calls and removed, so GCC also
// gets |noipa|.
#define SLHDSA_STACK_SCRUB_BYTES 16384
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 8
__attribute__((noipa))
#endif
static OPENSSL_NOINLINE void slh_dsa_scrub_stack(void) {
uint8_t buf[SLHDSA_STACK_SCRUB_BYTES];
OPENSSL_cleanse(buf, sizeof(buf));
// |OPENSSL_cleanse| has no compiler barrier under |OPENSSL_NO_ASM|, so with
// link-time optimization the compiler can remove it as a dead store.
#if defined(__GNUC__) || defined(__clang__)
__asm__ __volatile__("" : : "r"(buf) : "memory");
#endif
}

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.

I don't think we should scrub dead stack frames here. Nothing else in the module does it (FIPS 203 and 204 have the same requirement to destroy intermediate values, and ML-KEM and ML-DSA meet it by zeroizing their buffers), and it makes every call, including verify, need 16 KB of stack while resting on frame-layout and inlining assumptions that only the Linux/macOS StackScrub test checks. IMO it would be better to drop slh_dsa_scrub_stack, the OPENSSL_NOINLINE _impl split and the test, and instead OPENSSL_cleanse the remaining intermediate buffers in wots.c, merkle.c and fors.c.

@jakemas jakemas Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I dropped the scrub, the _impl split and the test. wots.c, merkle.c and fors.c now cleanse their buffers instead. Signing speed didn't change on x86, Graviton3 or my Mac.

Comment on lines +157 to +164
// RunACVPSigGen verifies every signature generation vector through the
// interface it targets, which checks the library's own construction of M'.
// It also signs up to |max_signs| deterministic and |max_signs| hedged
// vectors with |slh_dsa_sign_internal| and a prefix built by
// |ExternalMessage|, because the library's external signing functions always
// use fresh randomness. Pre-hash vectors that the parameter set rejects are
// not signed.
void RunACVPKeyGen(size_t max_vectors);

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.

nit: this comment describes RunACVPSigGen, so I think the RunACVPKeyGen declaration should move above it.

@jakemas jakemas Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines +406 to +412
TEST_P(SLHDSATest, ACVPSigGenVerify) { RunACVPSigGen(/*max_signs=*/0); }

TEST_P(DISABLED_SLHDSASlowTest, ACVPSigGen) { RunACVPSigGen(/*max_signs=*/1); }

TEST_P(SLHDSATest, DISABLED_ACVPSigGenAll) {
RunACVPSigGen(/*max_signs=*/SIZE_MAX);
}

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.

crypto_test signs none of the sigGen vectors by default: ACVPSigGenVerify passes max_signs=0, and ACVPSigGen is in the disabled suite, where DISABLED_ACVPSigGenAll already covers it. I think we should either move ACVPSigGen back into SLHDSATest (perhaps for 128s only) or drop it, and update the comments that say a subset is signed by default (line 147 above, the README, and util/all_tests.json).

@jakemas jakemas Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved ACVPSigGen back into SLHDSATest. It now signs one deterministic and one hedged vector for 128s, and I fixed the comments, README and all_tests.json to match.

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.

3 participants