Skip to content

Commit 14edfbe

Browse files
Un-nest Ed25519 cryptocb cases from HAVE_CURVE25519
1 parent 2d1b25a commit 14edfbe

6 files changed

Lines changed: 108 additions & 1 deletion

File tree

.github/workflows/build-and-test-refactor.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ jobs:
5353
- name: Build and test refactor DMA ASAN LMS verify-only XMSS full
5454
run: cd test-refactor/posix && make clean && make -j DMA=1 ASAN=1 LMS_VERIFY_ONLY=1 WOLFSSL_DIR=../../wolfssl && make run
5555

56+
# Build and test with Ed25519 enabled but Curve25519 disabled
57+
- name: Build and test refactor DMA ASAN NOCURVE25519
58+
run: cd test-refactor/posix && make clean && make -j DMA=1 ASAN=1 NOCURVE25519=1 WOLFSSL_DIR=../../wolfssl && make run
59+
5660
# Build and test ASAN build, with wolfCrypt tests enabled.
5761
- name: Build and test refactor ASAN TESTWOLFCRYPT
5862
run: cd test-refactor/posix && make clean && make -j ASAN=1 TESTWOLFCRYPT=1 WOLFSSL_DIR=../../wolfssl && make run

src/wh_client_cryptocb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ int wh_Client_CryptoCbStd(int devId, wc_CryptoInfo* info, void* inCtx)
426426
*out_len = len;
427427
}
428428
} break;
429+
#endif /* HAVE_CURVE25519 */
429430

430431
#ifdef HAVE_ED25519
431432
case WC_PK_TYPE_ED25519_KEYGEN: {
@@ -488,7 +489,6 @@ int wh_Client_CryptoCbStd(int devId, wc_CryptoInfo* info, void* inCtx)
488489
}
489490
} break;
490491
#endif /* HAVE_ED25519 */
491-
#endif /* HAVE_CURVE25519 */
492492

493493
#if defined(WOLFSSL_HAVE_MLKEM)
494494
case WC_PK_TYPE_PQC_KEM_KEYGEN:

test-refactor/client-server/wh_test_crypto_ed25519.c

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,94 @@ static int _whTest_CryptoEd25519ServerKey(whClientContext* ctx)
361361
return ret;
362362
}
363363

364+
/* Signs and verifies through the wolfCrypt API on a key whose private material
365+
* lives only in the server, so the crypto callback must handle the operation.
366+
* A software fallback has no private scalar and returns BAD_FUNC_ARG. */
367+
static int _whTest_CryptoEd25519CryptoCbHsmKey(whClientContext* ctx)
368+
{
369+
int devId = WH_CLIENT_DEVID(ctx);
370+
int ret = 0;
371+
WC_RNG rng[1];
372+
ed25519_key key[1] = {0};
373+
ed25519_key pubKey[1] = {0};
374+
whKeyId signKeyId = WH_KEYID_ERASED;
375+
whKeyId verifyKeyId = WH_KEYID_ERASED;
376+
byte msg[] = "Ed25519 cryptocb dispatch message";
377+
byte sig[ED25519_SIG_SIZE];
378+
word32 sigSz = sizeof(sig);
379+
int verified = 0;
380+
uint8_t label[] = "Ed25519 CryptoCb Key";
381+
382+
ret = wc_InitRng_ex(rng, NULL, devId);
383+
if (ret != 0) {
384+
WH_ERROR_PRINT("Failed to wc_InitRng_ex %d\n", ret);
385+
return ret;
386+
}
387+
388+
ret = wc_ed25519_init_ex(key, NULL, devId);
389+
if (ret != 0) {
390+
WH_ERROR_PRINT("Failed to initialize Ed25519 key: %d\n", ret);
391+
(void)wc_FreeRng(rng);
392+
return ret;
393+
}
394+
395+
ret = wc_ed25519_init_ex(pubKey, NULL, devId);
396+
if (ret != 0) {
397+
WH_ERROR_PRINT("Failed to initialize Ed25519 public key: %d\n", ret);
398+
wc_ed25519_free(key);
399+
(void)wc_FreeRng(rng);
400+
return ret;
401+
}
402+
403+
ret = wc_ed25519_make_key(rng, ED25519_KEY_SIZE, key);
404+
if (ret != 0) {
405+
WH_ERROR_PRINT("Failed to generate Ed25519 key: %d\n", ret);
406+
}
407+
else {
408+
ret = whTest_Ed25519ImportToServer(ctx, devId, key, pubKey, label,
409+
sizeof(label), &signKeyId,
410+
&verifyKeyId);
411+
}
412+
413+
if (ret == 0) {
414+
sigSz = sizeof(sig);
415+
ret = wc_ed25519_sign_msg(msg, (word32)sizeof(msg), sig, &sigSz, key);
416+
if (ret != 0) {
417+
WH_ERROR_PRINT("wc_ed25519_sign_msg on server key failed: %d\n",
418+
ret);
419+
}
420+
}
421+
422+
if (ret == 0) {
423+
ret = wc_ed25519_verify_msg(sig, sigSz, msg, (word32)sizeof(msg),
424+
&verified, pubKey);
425+
if (ret != 0) {
426+
WH_ERROR_PRINT("wc_ed25519_verify_msg on server key failed: %d\n",
427+
ret);
428+
}
429+
else if (verified != 1) {
430+
WH_ERROR_PRINT("Server key Ed25519 signature did not verify\n");
431+
ret = -1;
432+
}
433+
}
434+
435+
if (!WH_KEYID_ISERASED(signKeyId)) {
436+
(void)wh_Client_KeyEvict(ctx, signKeyId);
437+
}
438+
if (!WH_KEYID_ISERASED(verifyKeyId)) {
439+
(void)wh_Client_KeyEvict(ctx, verifyKeyId);
440+
}
441+
442+
if (ret == 0) {
443+
WH_TEST_PRINT("Ed25519 CRYPTOCB DEVID=0x%X SUCCESS\n", devId);
444+
}
445+
446+
wc_ed25519_free(pubKey);
447+
wc_ed25519_free(key);
448+
(void)wc_FreeRng(rng);
449+
return ret;
450+
}
451+
364452
#ifdef WOLFHSM_CFG_DMA
365453
static int _whTest_CryptoEd25519Dma(whClientContext* ctx)
366454
{
@@ -731,6 +819,7 @@ int whTest_Crypto_Ed25519(whClientContext* ctx)
731819
{
732820
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoEd25519Inline(ctx));
733821
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoEd25519ServerKey(ctx));
822+
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoEd25519CryptoCbHsmKey(ctx));
734823
#ifdef WOLFHSM_CFG_DMA
735824
WH_TEST_RETURN_ON_FAIL(_whTest_CryptoEd25519Dma(ctx));
736825
#endif

test-refactor/posix/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ ifeq ($(DMA),1)
100100
DEF += -DWOLFHSM_CFG_DMA
101101
endif
102102

103+
# Build without Curve25519, leaving Ed25519 enabled
104+
ifeq ($(NOCURVE25519),1)
105+
DEF += -DWOLFHSM_CFG_TEST_NO_CURVE25519
106+
endif
107+
103108
# Build LMS/XMSS in verify-only mode (omits private-key, sign, and keygen
104109
# paths). May be combined to exercise the mixed (one verify-only) case.
105110
ifeq ($(LMS_VERIFY_ONLY),1)

test/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ ifeq ($(NOCRYPTO),1)
130130
DEF += -DWOLFHSM_CFG_NO_CRYPTO
131131
endif
132132

133+
# Build without Curve25519, leaving Ed25519 enabled
134+
ifeq ($(NOCURVE25519),1)
135+
DEF += -DWOLFHSM_CFG_TEST_NO_CURVE25519
136+
endif
137+
133138
# Enable scan-build
134139
ifeq ($(SCAN),1)
135140
SCAN_LOG = scan_test.log

test/config/user_settings.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@
107107
#define ECC_SHAMIR
108108

109109
/** Curve25519 Options */
110+
/* Curve25519 and Ed25519 are independent options. Allow a build that omits
111+
* Curve25519 so the Ed25519-only configuration stays exercised. */
112+
#ifndef WOLFHSM_CFG_TEST_NO_CURVE25519
110113
#define HAVE_CURVE25519
114+
#endif
111115

112116
/** DH and DHE Options */
113117
#define NO_DH

0 commit comments

Comments
 (0)