Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/build-and-test-refactor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
padelsbach marked this conversation as resolved.

# 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
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 19 additions & 10 deletions src/wh_server_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions test-refactor/posix/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading