Skip to content

Commit 2a9b714

Browse files
committed
Add non-blocking ML-DSA and ML-KEM (WC_MLDSA_NONBLOCK, WC_MLKEM_NONBLOCK)
1 parent c131af0 commit 2a9b714

9 files changed

Lines changed: 2299 additions & 293 deletions

File tree

‎.github/configs/pq-all.json‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
"--enable-slhdsa=yes,small", "--enable-dilithium=yes,small",
2121
"--enable-dual-alg-certs", "--disable-qt",
2222
"CPPFLAGS=-pedantic -Wdeclaration-after-statement -Wnull-dereference -DWOLFCRYPT_TEST_LINT -DNO_WOLFSSL_CIPHER_SUITE_TEST -DTEST_LIBWOLFSSL_SOURCES_INCLUSION_SEQUENCE -DWOLFSSL_MLKEM_MAKEKEY_SMALL_MEM -DWOLFSSL_MLKEM_ENCAPSULATE_SMALL_MEM -DWOLFSSL_MLKEM_NO_LARGE_CODE -DWOLFSSL_MLDSA_SIGN_SMALL_MEM -DWOLFSSL_MLDSA_VERIFY_SMALL_MEM -DWOLFSSL_MLDSA_MAKE_KEY_SMALL_MEM -DWOLFSSL_MLDSA_NO_LARGE_CODE"]},
23+
{"name": "pq-nonblock-smallmem", "minutes": 4.0,
24+
"comment": "Non-blocking ML-DSA (WC_MLDSA_NONBLOCK) and ML-KEM (WC_MLKEM_NONBLOCK) built on the small-mem paths. make check runs mldsa_nonblock_test and mlkem_nonblock_test, which drive each operation's resumable MP_WOULDBLOCK state machine and confirm the result matches the blocking path.",
25+
"configure": ["--enable-dilithium=yes,small", "--enable-mlkem",
26+
"--enable-experimental",
27+
"CPPFLAGS=-pedantic -Wdeclaration-after-statement -Wnull-dereference -DWOLFSSL_MLDSA_SIGN_SMALL_MEM -DWOLFSSL_MLDSA_VERIFY_SMALL_MEM -DWOLFSSL_MLDSA_MAKE_KEY_SMALL_MEM -DWOLFSSL_MLDSA_NO_LARGE_CODE -DWC_MLDSA_NONBLOCK -DWOLFSSL_MLKEM_MAKEKEY_SMALL_MEM -DWOLFSSL_MLKEM_ENCAPSULATE_SMALL_MEM -DWC_MLKEM_NONBLOCK"]},
28+
{"name": "pq-nonblock-smallmem-dynkeys", "minutes": 2.5,
29+
"comment": "Non-blocking ML-KEM with the cached matrix A and dynamic key buffers: a resumed keygen must keep the vectors its first slice allocated, and encapsulation must read the cached matrix across yields",
30+
"configure": ["--enable-cryptonly", "--enable-mlkem", "--enable-smallstack",
31+
"CPPFLAGS=-DWOLFSSL_MLKEM_MAKEKEY_SMALL_MEM -DWOLFSSL_MLKEM_ENCAPSULATE_SMALL_MEM -DWC_MLKEM_NONBLOCK -DWOLFSSL_MLKEM_CACHE_A -DWOLFSSL_MLKEM_DYNAMIC_KEYS"]},
2332
{"name": "slhdsa-pqc-only", "minutes": 22.3,
2433
"comment": "PQC-only TLS 1.3: ML-KEM key exchange + SLH-DSA (FIPS 205) auth with RSA, ECC and DH disabled; exercises the SLH-DSA CertificateVerify path",
2534
"configure": ["--enable-mlkem", "--enable-slhdsa",

‎doc/dox_comments/header_files/wc_mldsa.h‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -672,9 +672,11 @@ int wc_MlDsaKey_Verify(wc_MlDsaKey* key, const byte* sig, word32 sigLen,
672672
/*!
673673
\ingroup ML_DSA
674674
675-
\brief Returns the size in bytes of the encoded private key for
676-
the parameter set selected on this key. Equivalent to
677-
wc_MlDsaKey_PrivSize() and provided for API compatibility.
675+
\brief Returns the size in bytes of the encoded private key alone
676+
(FIPS 204 sk) for the parameter set selected on this key. This is
677+
the length wc_MlDsaKey_ExportPrivRaw() writes and
678+
wc_MlDsaKey_ImportPrivRaw() expects. It is not the same value as
679+
wc_MlDsaKey_PrivSize(), which includes the public key.
678680
679681
\return Encoded private key size in bytes on success (positive
680682
value).
@@ -692,15 +694,21 @@ int wc_MlDsaKey_Size(wc_MlDsaKey* key);
692694
/*!
693695
\ingroup ML_DSA
694696
695-
\brief Returns the size in bytes of the encoded private key for
696-
the parameter set selected on this key.
697+
\brief Returns the size in bytes of the encoded private key with the
698+
encoded public key appended, for the parameter set selected on this
699+
key. This is wc_MlDsaKey_Size() plus wc_MlDsaKey_PubSize(), the
700+
length of the private-plus-public encoding that
701+
wc_MlDsaKey_ImportKey() and wc_MlDsaKey_PrivateKeyDecode() accept.
702+
The name is kept for compatibility with wc_dilithium_priv_size().
697703
698-
\return Encoded private key size on success (positive value).
704+
\return Encoded private-plus-public key size on success (positive
705+
value).
699706
\return BAD_FUNC_ARG if key is NULL or no parameter set is
700707
selected.
701708
702709
\param [in] key Pointer to a wc_MlDsaKey with parameters set.
703710
711+
\sa wc_MlDsaKey_Size
704712
\sa wc_MlDsaKey_PubSize
705713
\sa wc_MlDsaKey_GetPrivLen
706714
*/
@@ -743,18 +751,20 @@ int wc_MlDsaKey_SigSize(wc_MlDsaKey* key);
743751
/*!
744752
\ingroup ML_DSA
745753
746-
\brief Writes the encoded private key size into *len. Equivalent
747-
information to wc_MlDsaKey_PrivSize() but uses an out-parameter
748-
style.
754+
\brief Writes the size of the encoded private key with the public
755+
key appended into *len. Equivalent information to
756+
wc_MlDsaKey_PrivSize() but uses an out-parameter style. For the
757+
private key alone use wc_MlDsaKey_Size().
749758
750759
\return 0 on success.
751760
\return BAD_FUNC_ARG if key or len is NULL, or no parameter set is
752761
selected.
753762
754763
\param [in] key Pointer to a wc_MlDsaKey with parameters set.
755-
\param [out] len Receives the private key size in bytes.
764+
\param [out] len Receives the private-plus-public key size in bytes.
756765
757766
\sa wc_MlDsaKey_PrivSize
767+
\sa wc_MlDsaKey_Size
758768
*/
759769
int wc_MlDsaKey_GetPrivLen(wc_MlDsaKey* key, int* len);
760770

‎tests/api/test_mldsa.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,9 @@ int test_mldsa(void)
631631
ExpectIntEQ(wc_MlDsaKey_Size(key), WC_MLDSA_87_KEY_SIZE);
632632
#ifdef WOLFSSL_MLDSA_PUBLIC_KEY
633633
ExpectIntEQ(wc_MlDsaKey_PrivSize(key), WC_MLDSA_87_PRV_KEY_SIZE);
634+
/* PrivSize is the private key with the public key appended. */
635+
ExpectIntEQ(wc_MlDsaKey_PrivSize(key),
636+
wc_MlDsaKey_Size(key) + wc_MlDsaKey_PubSize(key));
634637
#endif
635638
#endif
636639
#ifdef WOLFSSL_MLDSA_PUBLIC_KEY

0 commit comments

Comments
 (0)