diff --git a/.github/workflows/build-and-test-refactor.yml b/.github/workflows/build-and-test-refactor.yml index 4656b4a5a..bbcc32fbc 100644 --- a/.github/workflows/build-and-test-refactor.yml +++ b/.github/workflows/build-and-test-refactor.yml @@ -53,6 +53,17 @@ jobs: - name: Build and test refactor DMA ASAN LMS verify-only XMSS full run: cd test-refactor/posix && make clean && make -j DMA=1 ASAN=1 LMS_VERIFY_ONLY=1 WOLFSSL_DIR=../../wolfssl && make run + # Build and test with ML-DSA in verify-only mode + - name: Build and test refactor DMA ASAN MLDSA verify-only + run: cd test-refactor/posix && make clean && make -j DMA=1 ASAN=1 MLDSA_VERIFY_ONLY=1 WOLFSSL_DIR=../../wolfssl && make run + + # Build and test with ML-DSA verify-only and a reduced keycache buffer. + # 4096 < MLDSA_MAX_BOTH_KEY_DER_SIZE(7520) so this would fail the static + # assert without MLDSA_VERIFY_ONLY; it passes because verify-only only + # needs MLDSA_MAX_PUB_KEY_DER_SIZE(2614). LMS/XMSS full keys fit in 4096. + - name: Build and test refactor DMA ASAN MLDSA verify-only reduced keycache + run: cd test-refactor/posix && make clean && make -j DMA=1 ASAN=1 MLDSA_VERIFY_ONLY=1 KEYCACHE_BIG_BUFSIZE=4096 WOLFSSL_DIR=../../wolfssl && make run + # Build and test ASAN build, with wolfCrypt tests enabled. - name: Build and test refactor ASAN TESTWOLFCRYPT run: cd test-refactor/posix && make clean && make -j ASAN=1 TESTWOLFCRYPT=1 WOLFSSL_DIR=../../wolfssl && make run diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index d1af2729b..396433e6b 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -53,6 +53,17 @@ jobs: - name: Build and test DMA ASAN LMS verify-only XMSS full run: cd test && make clean && make -j DMA=1 ASAN=1 LMS_VERIFY_ONLY=1 WOLFSSL_DIR=../wolfssl && make run + # Build and test with ML-DSA in verify-only mode + - name: Build and test DMA ASAN MLDSA verify-only + run: cd test && make clean && make -j DMA=1 ASAN=1 MLDSA_VERIFY_ONLY=1 WOLFSSL_DIR=../wolfssl && make run + + # Build and test with ML-DSA verify-only and a reduced keycache buffer. + # 4096 < MLDSA_MAX_BOTH_KEY_DER_SIZE(7520) so this would fail the static + # assert without MLDSA_VERIFY_ONLY; it passes because verify-only only + # needs MLDSA_MAX_PUB_KEY_DER_SIZE(2614). LMS/XMSS full keys fit in 4096. + - name: Build and test DMA ASAN MLDSA verify-only reduced keycache + run: cd test && make clean && make -j DMA=1 ASAN=1 MLDSA_VERIFY_ONLY=1 KEYCACHE_BIG_BUFSIZE=4096 WOLFSSL_DIR=../wolfssl && make run + # Build and test ASAN build, with wolfCrypt tests enabled. - name: Build and test ASAN TESTWOLFCRYPT run: cd test && make clean && make -j ASAN=1 TESTWOLFCRYPT=1 WOLFSSL_DIR=../wolfssl && make run diff --git a/src/wh_server_crypto.c b/src/wh_server_crypto.c index b35e8e4a0..23b00ccfe 100644 --- a/src/wh_server_crypto.c +++ b/src/wh_server_crypto.c @@ -768,11 +768,16 @@ int wh_Server_CacheExportCurve25519Key(whServerContext* server, whKeyId keyId, #endif /* HAVE_CURVE25519 */ #ifdef WOLFSSL_HAVE_MLDSA -/* The big key cache buffer must be able to hold a full ML-DSA keypair DER, - * otherwise wh_Server_MlDsaKeyCacheImport() can never succeed. */ +/* When verify-only, the server caches only the public key DER. Otherwise it + * must be able to hold a full keypair DER (public + private). */ +#if defined(WOLFSSL_DILITHIUM_VERIFY_ONLY) || defined(WOLFSSL_MLDSA_VERIFY_ONLY) +#define WH_SERVER_MLDSA_MAX_CACHE_DER_SIZE MLDSA_MAX_PUB_KEY_DER_SIZE +#else +#define WH_SERVER_MLDSA_MAX_CACHE_DER_SIZE MLDSA_MAX_BOTH_KEY_DER_SIZE +#endif WH_UTILS_STATIC_ASSERT( - WOLFHSM_CFG_SERVER_KEYCACHE_BIG_BUFSIZE >= MLDSA_MAX_BOTH_KEY_DER_SIZE, - "WOLFHSM_CFG_SERVER_KEYCACHE_BIG_BUFSIZE too small for ML-DSA keypair DER"); + WOLFHSM_CFG_SERVER_KEYCACHE_BIG_BUFSIZE >= WH_SERVER_MLDSA_MAX_CACHE_DER_SIZE, + "WOLFHSM_CFG_SERVER_KEYCACHE_BIG_BUFSIZE too small for ML-DSA key DER"); int wh_Server_MlDsaKeyCacheImport(whServerContext* ctx, wc_MlDsaKey* key, whKeyId keyId, whNvmFlags flags, @@ -788,14 +793,12 @@ int wh_Server_MlDsaKeyCacheImport(whServerContext* ctx, wc_MlDsaKey* key, return WH_ERROR_BADARGS; } - /* The key may hold a full keypair, in which case - * wh_Crypto_MlDsaSerializeKeyDer() encodes both the public and private key - * (wc_MlDsaKey_KeyToDer()), so size for both keys, not just the private key. */ ret = wh_Server_KeystoreGetCacheSlotChecked( - ctx, keyId, MLDSA_MAX_BOTH_KEY_DER_SIZE, &cacheBuf, &cacheMeta); + ctx, keyId, WH_SERVER_MLDSA_MAX_CACHE_DER_SIZE, &cacheBuf, &cacheMeta); if (ret == WH_ERROR_OK) { - ret = wh_Crypto_MlDsaSerializeKeyDer(key, MLDSA_MAX_BOTH_KEY_DER_SIZE, - cacheBuf, &der_size); + ret = wh_Crypto_MlDsaSerializeKeyDer(key, + WH_SERVER_MLDSA_MAX_CACHE_DER_SIZE, + cacheBuf, &der_size); WH_DEBUG_SERVER_VERBOSE("keyId:%u, ret:%d\n", keyId, ret); } @@ -4718,6 +4721,7 @@ static int _HandleMlDsaKeyGen(whServerContext* ctx, uint16_t magic, int devId, #ifdef WOLFSSL_MLDSA_NO_MAKE_KEY (void)ctx; (void)magic; + (void)devId; (void)cryptoDataIn; (void)inSize; (void)cryptoDataOut; @@ -4828,6 +4832,7 @@ static int _HandleMlDsaSign(whServerContext* ctx, uint16_t magic, int devId, #ifdef WOLFSSL_MLDSA_NO_SIGN (void)ctx; (void)magic; + (void)devId; (void)cryptoDataIn; (void)inSize; (void)cryptoDataOut; @@ -4935,6 +4940,7 @@ static int _HandleMlDsaVerify(whServerContext* ctx, uint16_t magic, int devId, #ifdef WOLFSSL_MLDSA_NO_VERIFY (void)ctx; (void)magic; + (void)devId; (void)cryptoDataIn; (void)inSize; (void)cryptoDataOut; @@ -6370,6 +6376,7 @@ static int _HandleMlDsaKeyGenDma(whServerContext* ctx, uint16_t magic, #ifdef WOLFSSL_MLDSA_NO_MAKE_KEY (void)ctx; (void)magic; + (void)devId; (void)cryptoDataIn; (void)inSize; (void)cryptoDataOut; @@ -6491,6 +6498,7 @@ static int _HandleMlDsaSignDma(whServerContext* ctx, uint16_t magic, int devId, #ifdef WOLFSSL_MLDSA_NO_SIGN (void)ctx; (void)magic; + (void)devId; (void)cryptoDataIn; (void)inSize; (void)cryptoDataOut; @@ -6625,6 +6633,7 @@ static int _HandleMlDsaVerifyDma(whServerContext* ctx, uint16_t magic, #ifdef WOLFSSL_MLDSA_NO_VERIFY (void)ctx; (void)magic; + (void)devId; (void)cryptoDataIn; (void)inSize; (void)cryptoDataOut; diff --git a/test-refactor/posix/Makefile b/test-refactor/posix/Makefile index 3169736ad..6cacff622 100644 --- a/test-refactor/posix/Makefile +++ b/test-refactor/posix/Makefile @@ -110,6 +110,14 @@ ifeq ($(XMSS_VERIFY_ONLY),1) DEF += -DWOLFSSL_XMSS_VERIFY_ONLY endif +ifeq ($(MLDSA_VERIFY_ONLY),1) + DEF += -DWOLFSSL_MLDSA_VERIFY_ONLY +endif + +ifneq ($(KEYCACHE_BIG_BUFSIZE),) + DEF += -DWOLFHSM_CFG_SERVER_KEYCACHE_BIG_BUFSIZE=$(KEYCACHE_BIG_BUFSIZE) +endif + # Support a SHE-capable build ifeq ($(SHE),1) DEF += -DWOLFHSM_CFG_SHE_EXTENSION diff --git a/test/Makefile b/test/Makefile index faf251850..c76e877a7 100644 --- a/test/Makefile +++ b/test/Makefile @@ -152,6 +152,14 @@ ifeq ($(XMSS_VERIFY_ONLY),1) DEF += -DWOLFSSL_XMSS_VERIFY_ONLY endif +ifeq ($(MLDSA_VERIFY_ONLY),1) + DEF += -DWOLFSSL_MLDSA_VERIFY_ONLY +endif + +ifneq ($(KEYCACHE_BIG_BUFSIZE),) + DEF += -DWOLFHSM_CFG_SERVER_KEYCACHE_BIG_BUFSIZE=$(KEYCACHE_BIG_BUFSIZE) +endif + # Support a SHE-capable build ifeq ($(SHE),1) DEF += -DWOLFHSM_CFG_SHE_EXTENSION