Repository navigation
Conversation
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.
| 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; |
There was a problem hiding this comment.
warning: variable 'len' is not initialized [cppcoreguidelines-init-variables]
| 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; |
There was a problem hiding this comment.
warning: variable 'len' is not initialized [cppcoreguidelines-init-variables]
| 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(); | |||
There was a problem hiding this comment.
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(); | |||
There was a problem hiding this comment.
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(); | |||
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
warning: variable 'hash_nid' is not initialized [cppcoreguidelines-init-variables]
| 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; |
There was a problem hiding this comment.
warning: variable 'ok' is not initialized [cppcoreguidelines-init-variables]
| 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; |
There was a problem hiding this comment.
warning: variable 'ok' is not initialized [cppcoreguidelines-init-variables]
| int ok; | |
| int ok = 0; |
| OPENSSL_PUT_ERROR(EVP, EVP_R_INVALID_OPERATION); | ||
| return 0; | ||
| } | ||
| int hash_nid; |
There was a problem hiding this comment.
warning: variable 'hash_nid' is not initialized [cppcoreguidelines-init-variables]
| int hash_nid; | |
| int hash_nid = 0; |
8c9dd0e to
7d1a1cc
Compare
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
|
🔒 Security Review — View Report Please review before merging. |
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_SLHDSAkey type. As for ML-DSA, the NID selects the parameter set. As in RFC 9909, it also selects the mode:NID_SLH_DSA_SHAKE_{128,192,256}s.NID_SLH_DSA_SHAKE_128s_WITH_SHAKE128andNID_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_keyandEVP_PKEY_slhdsa_get_type.RFC 9909, Section 8 says a key may only be used in its own mode, so:
EVP_DigestSignandEVP_DigestVerifyare one-shot. They use pure SLH-DSA for a pure key, and HashSLH-DSA for a HashSLH-DSA key.EVP_PKEY_signandEVP_PKEY_verifytake the digest (SHAKE128(M, 256) or SHAKE256(M, 512)), and only HashSLH-DSA keys support them.EVP_PKEY_CTX_set_signature_mdaccepts 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_checkdoes the same, andEVP_PKEY_public_checkaccepts 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 bumpsAWSLC_API_VERSIONto 39.SubjectPublicKeyInfo and PKCS #8 encoding come in the next PR. SLH-DSA is still not an approved FIPS service.
Testing
p_slhdsa_test.ccruns 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.ccchecks the new NIDs, names and OIDs.util/all_tests.json, not under valgrind or SDE.Review considerations
evp.handnid.h: NIDs 1001 to 1007, and four functions.SpeedDigestSignNIDintool/speed.cc, which ML-DSA uses, now shares its timing code with SLH-DSA, and it checks the return value ofEVP_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.