Skip to content

Commit eb65361

Browse files
committed
wolfcrypt/test/test.c:
* tweaks to xmss_test() for compatibility with WOLFSSL_NO_MALLOC && NO_WOLFSSL_MEMORY; * fixes for return codes in dilithium_test(). wolfssl/wolfcrypt/dilithium.h: add !WC_NO_CONSTRUCTORS gate around wc_dilithium_new() and wc_dilithium_delete() prototypes, to match gating in implementation.
1 parent 16e45f9 commit eb65361

2 files changed

Lines changed: 41 additions & 9 deletions

File tree

wolfcrypt/test/test.c

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49412,41 +49412,41 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dilithium_test(void)
4941249412
#ifndef WOLFSSL_DILITHIUM_NO_VERIFY
4941349413
ret = dilithium_param_44_vfy_test();
4941449414
if (ret != 0)
49415-
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
49415+
ERROR_OUT(ret, out);
4941649416
#endif
4941749417
#endif
4941849418
#ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
4941949419
ret = dilithium_param_test(WC_ML_DSA_44, &rng);
4942049420
if (ret != 0)
49421-
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
49421+
ERROR_OUT(ret, out);
4942249422
#endif
4942349423
#endif
4942449424
#ifndef WOLFSSL_NO_ML_DSA_65
4942549425
#ifdef WOLFSSL_WC_DILITHIUM
4942649426
#ifndef WOLFSSL_DILITHIUM_NO_VERIFY
4942749427
ret = dilithium_param_65_vfy_test();
4942849428
if (ret != 0)
49429-
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
49429+
ERROR_OUT(ret, out);
4943049430
#endif
4943149431
#endif
4943249432
#ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
4943349433
ret = dilithium_param_test(WC_ML_DSA_65, &rng);
4943449434
if (ret != 0)
49435-
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
49435+
ERROR_OUT(ret, out);
4943649436
#endif
4943749437
#endif
4943849438
#ifndef WOLFSSL_NO_ML_DSA_87
4943949439
#ifdef WOLFSSL_WC_DILITHIUM
4944049440
#ifndef WOLFSSL_DILITHIUM_NO_VERIFY
4944149441
ret = dilithium_param_87_vfy_test();
4944249442
if (ret != 0)
49443-
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
49443+
ERROR_OUT(ret, out);
4944449444
#endif
4944549445
#endif
4944649446
#ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
4944749447
ret = dilithium_param_test(WC_ML_DSA_87, &rng);
4944849448
if (ret != 0)
49449-
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
49449+
ERROR_OUT(ret, out);
4945049450
#endif
4945149451
#endif
4945249452

@@ -49456,7 +49456,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dilithium_test(void)
4945649456
!defined(WOLFSSL_DILITHIUM_NO_VERIFY))
4945749457
ret = dilithium_decode_test();
4945849458
if (ret != 0) {
49459-
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
49459+
ERROR_OUT(ret, out);
4946049460
}
4946149461
#endif /* (WOLFSSL_DILITHIUM_PUBLIC_KEY && !WOLFSSL_DILITHIUM_NO_VERIFY) ||
4946249462
* (WOLFSSL_DILITHIUM_PRIVATE_KEY && !WOLFSSL_DILITHIUM_NO_SIGN) */
@@ -49503,8 +49503,13 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test(void)
4950349503
word32 skSz = 0;
4950449504
word32 sigSz = 0;
4950549505
word32 bufSz = 0;
49506-
unsigned char * sk = NULL;
49507-
unsigned char * old_sk = NULL;
49506+
#ifdef WOLFSSL_NO_MALLOC
49507+
static byte sk[2048];
49508+
static byte old_sk[2048];
49509+
#else
49510+
byte * sk = NULL;
49511+
byte * old_sk = NULL;
49512+
#endif
4950849513
const char * msg = "XMSS post quantum signature test";
4950949514
word32 msgSz = (word32) XSTRLEN(msg);
4951049515
#if WOLFSSL_XMSS_MIN_HEIGHT <= 10
@@ -49516,7 +49521,11 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test(void)
4951649521
#else
4951749522
const char * param = "XMSSMT-SHA2_60/12_256";
4951849523
#endif
49524+
#ifdef WOLFSSL_NO_MALLOC
49525+
static byte sig[4096];
49526+
#else
4951949527
byte * sig = NULL;
49528+
#endif
4952049529
int ret2 = -1;
4952149530
int ret = WC_TEST_RET_ENC_NC;
4952249531
WOLFSSL_ENTER("xmss_test");
@@ -49553,8 +49562,13 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test(void)
4955349562
if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); }
4955449563

4955549564
/* Allocate signature array. */
49565+
#ifdef WOLFSSL_NO_MALLOC
49566+
if (sigSz > sizeof(sig))
49567+
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
49568+
#else
4955649569
sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
4955749570
if (sig == NULL) { ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); }
49571+
#endif
4955849572

4955949573
bufSz = sigSz;
4956049574

@@ -49566,11 +49580,16 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test(void)
4956649580
#endif
4956749581

4956849582
/* Allocate current and old secret keys.*/
49583+
#ifdef WOLFSSL_NO_MALLOC
49584+
if (skSz > sizeof(sk))
49585+
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
49586+
#else
4956949587
sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
4957049588
if (sk == NULL) { ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); }
4957149589

4957249590
old_sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
4957349591
if (old_sk == NULL) { ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); }
49592+
#endif
4957449593

4957549594
XMEMSET(sk, 0, skSz);
4957649595
XMEMSET(old_sk, 0, skSz);
@@ -49631,6 +49650,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test(void)
4963149650
out:
4963249651

4963349652
/* Cleanup everything. */
49653+
#ifndef WOLFSSL_NO_MALLOC
4963449654
XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
4963549655
sig = NULL;
4963649656

@@ -49639,6 +49659,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test(void)
4963949659

4964049660
XFREE(old_sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
4964149661
old_sk = NULL;
49662+
#endif /* !WOLFSSL_NO_MALLOC */
4964249663

4964349664
wc_XmssKey_Free(&signingKey);
4964449665
wc_XmssKey_Free(&verifyKey);
@@ -50153,6 +50174,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test(void)
5015350174
int sigsLeft = 0;
5015450175
LmsKey signingKey;
5015550176
LmsKey verifyKey;
50177+
#if defined(WOLFSSL_NO_MALLOC) && defined(NO_WOLFSSL_MEMORY)
50178+
static byte signingKey_priv_data[4096];
50179+
#endif
5015650180
WC_RNG rng;
5015750181
word32 sigSz = 0;
5015850182
const char * msg = "LMS HSS post quantum signature test";
@@ -50208,6 +50232,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test(void)
5020850232

5020950233
ret = wc_LmsKey_Init(&signingKey, NULL, devId);
5021050234
if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); }
50235+
#if defined(WOLFSSL_NO_MALLOC) && defined(NO_WOLFSSL_MEMORY)
50236+
signingKey.priv_data = signingKey_priv_data;
50237+
#endif
5021150238

5021250239
ret = wc_LmsKey_Init(&verifyKey, NULL, devId);
5021350240
if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); }
@@ -50317,6 +50344,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test(void)
5031750344

5031850345
out:
5031950346

50347+
#if defined(WOLFSSL_NO_MALLOC) && defined(NO_WOLFSSL_MEMORY)
50348+
signingKey.priv_data = NULL;
50349+
#endif
5032050350
wc_LmsKey_Free(&signingKey);
5032150351
wc_LmsKey_Free(&verifyKey);
5032250352

wolfssl/wolfcrypt/dilithium.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,10 +797,12 @@ int wc_dilithium_verify_ctx_hash(const byte* sig, word32 sigLen,
797797
const byte* ctx, word32 ctxLen, int hashAlg, const byte* hash,
798798
word32 hashLen, int* res, dilithium_key* key);
799799

800+
#ifndef WC_NO_CONSTRUCTORS
800801
WOLFSSL_API
801802
dilithium_key* wc_dilithium_new(void* heap, int devId);
802803
WOLFSSL_API
803804
int wc_dilithium_delete(dilithium_key* key, dilithium_key** key_p);
805+
#endif /* !WC_NO_CONSTRUCTORS */
804806

805807
WOLFSSL_API
806808
int wc_dilithium_init(dilithium_key* key);

0 commit comments

Comments
 (0)