Repository navigation
Conversation
9b8f306 to
e96c73e
Compare
|
🔒 Security Review — View Report Please review before merging. |
f3ddecf to
139a726
Compare
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
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.
| // 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 | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| // 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); |
There was a problem hiding this comment.
nit: this comment describes RunACVPSigGen, so I think the RunACVPKeyGen declaration should move above it.
| 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); | ||
| } |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
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.There is no EVP or TLS support in this PR, and SLH-DSA is not an approved FIPS service yet.
Testing
crypto_testruns a subset of the signing tests. The rest run natively fromutil/all_tests.json, not under valgrind or SDE.Review considerations
PRIVATEsymbols.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.