Skip to content

Commit 5c79ac7

Browse files
committed
test: close PQC MC/DC coverage gaps
1 parent 49b7f79 commit 5c79ac7

11 files changed

Lines changed: 819 additions & 11 deletions

‎tests/api/test_lms_xmss.c‎

Lines changed: 191 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,16 @@ static int test_lms_xmss_verify_cryptocb(int devIdArg, wc_CryptoInfo* info,
418418
if ((info != NULL) && (info->algo_type == WC_ALGO_TYPE_PK) &&
419419
(info->pk.type == WC_PK_TYPE_PQC_STATEFUL_SIG_VERIFY)) {
420420
test_lms_xmss_verify_calls++;
421+
#if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
422+
if (ctx != NULL) {
423+
int result = *(const int*)ctx;
424+
if (result < 0) {
425+
return result;
426+
}
427+
*info->pk.pqc_stateful_sig_verify.res = result;
428+
return 0;
429+
}
430+
#endif
421431
*info->pk.pqc_stateful_sig_verify.res = 1;
422432
return 0;
423433
}
@@ -591,18 +601,26 @@ int test_wc_LmsKey_reload_devid_verify(void)
591601
byte msg[] = "test message for LMS signing";
592602
byte* sig = NULL;
593603
word32 sigSz = 0;
604+
void* reply = NULL;
605+
#if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
606+
int verifyResult = 1;
607+
reply = &verifyResult;
608+
#endif
594609

595610
/* Zero so cleanup is safe if an early alloc failure skips init. */
596611
XMEMSET(&key, 0, sizeof(key));
597612
test_lms_xmss_verify_calls = 0;
598613

599614
ExpectIntEQ(wc_CryptoCb_RegisterDevice(TEST_LMS_XMSS_CRYPTOCB_DEVID,
600-
test_lms_xmss_verify_cryptocb, NULL), 0);
615+
test_lms_xmss_verify_cryptocb, reply), 0);
601616

602617
/* No read callback, so the reload leaves the state with the device. */
603618
ExpectIntEQ(wc_LmsKey_Init(&key, NULL, TEST_LMS_XMSS_CRYPTOCB_DEVID), 0);
604619
ExpectIntEQ(test_lms_set_params(&key), 0);
605620
ExpectIntEQ(wc_LmsKey_Reload(&key), 0);
621+
#if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
622+
ExpectIntEQ(wc_LmsKey_Reload(&key), WC_NO_ERR_TRACE(BAD_STATE_E));
623+
#endif
606624
ExpectNull(key.priv_data);
607625

608626
/* Only the signature length is checked before the device is asked, so the
@@ -614,6 +632,15 @@ int test_wc_LmsKey_reload_devid_verify(void)
614632
XMEMSET(sig, 0, sigSz);
615633
ExpectIntEQ(wc_LmsKey_Verify(&key, sig, sigSz, msg, sizeof(msg)), 0);
616634
ExpectIntEQ(test_lms_xmss_verify_calls, 1);
635+
#if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
636+
verifyResult = 0;
637+
ExpectIntEQ(wc_LmsKey_Verify(&key, sig, sigSz, msg, sizeof(msg)),
638+
WC_NO_ERR_TRACE(SIG_VERIFY_E));
639+
verifyResult = WC_NO_ERR_TRACE(WC_HW_E);
640+
ExpectIntEQ(wc_LmsKey_Verify(&key, sig, sigSz, msg, sizeof(msg)),
641+
WC_NO_ERR_TRACE(WC_HW_E));
642+
ExpectIntEQ(test_lms_xmss_verify_calls, 3);
643+
#endif
617644
}
618645

619646
XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
@@ -773,8 +800,22 @@ static int test_lms_xmss_keygen_cryptocb(int devIdArg, wc_CryptoInfo* info,
773800

774801
if ((info != NULL) && (info->algo_type == WC_ALGO_TYPE_PK) &&
775802
(info->pk.type == WC_PK_TYPE_PQC_STATEFUL_SIG_KEYGEN)) {
803+
#if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
804+
if (ctx != NULL) {
805+
return ((const int*)ctx)[0];
806+
}
807+
#endif
776808
return 0;
777809
}
810+
#if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
811+
if ((ctx != NULL) && (info != NULL) &&
812+
(info->algo_type == WC_ALGO_TYPE_PK) &&
813+
(info->pk.type == WC_PK_TYPE_PQC_STATEFUL_SIG_SIGS_LEFT)) {
814+
*info->pk.pqc_stateful_sig_sigs_left.sigsLeft =
815+
(word32)((const int*)ctx)[1];
816+
return 0;
817+
}
818+
#endif
778819
return CRYPTOCB_UNAVAILABLE;
779820
}
780821
#endif
@@ -809,6 +850,33 @@ int test_wc_LmsKey_keygen_no_sigsleft(void)
809850
WC_NO_ERR_TRACE(BAD_STATE_E));
810851

811852
wc_LmsKey_Free(&key);
853+
#if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
854+
{
855+
static const struct {
856+
int reply[2]; /* Keygen result and remaining signatures. */
857+
int expected;
858+
} cases[] = {
859+
{{ 0, 1 }, 0},
860+
{{ 0, 0 }, WC_NO_ERR_TRACE(BAD_STATE_E)},
861+
{{ WC_NO_ERR_TRACE(WC_HW_E), 0 }, WC_NO_ERR_TRACE(WC_HW_E)}
862+
};
863+
unsigned int i;
864+
865+
wc_CryptoCb_UnRegisterDevice(TEST_LMS_XMSS_CRYPTOCB_DEVID);
866+
for (i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) {
867+
int reply[2];
868+
XMEMCPY(reply, cases[i].reply, sizeof(reply));
869+
ExpectIntEQ(wc_CryptoCb_RegisterDevice(TEST_LMS_XMSS_CRYPTOCB_DEVID,
870+
test_lms_xmss_keygen_cryptocb, reply), 0);
871+
ExpectIntEQ(wc_LmsKey_Init(&key, NULL,
872+
TEST_LMS_XMSS_CRYPTOCB_DEVID), 0);
873+
ExpectIntEQ(test_lms_set_params(&key), 0);
874+
ExpectIntEQ(wc_LmsKey_MakeKey(&key, &rng), cases[i].expected);
875+
wc_LmsKey_Free(&key);
876+
wc_CryptoCb_UnRegisterDevice(TEST_LMS_XMSS_CRYPTOCB_DEVID);
877+
}
878+
}
879+
#endif
812880
wc_FreeRng(&rng);
813881
wc_CryptoCb_UnRegisterDevice(TEST_LMS_XMSS_CRYPTOCB_DEVID);
814882
#endif
@@ -1178,18 +1246,26 @@ int test_wc_XmssKey_reload_devid_verify(void)
11781246
byte msg[] = "test message for XMSS signing";
11791247
byte* sig = NULL;
11801248
word32 sigSz = 0;
1249+
void* reply = NULL;
1250+
#if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
1251+
int verifyResult = 1;
1252+
reply = &verifyResult;
1253+
#endif
11811254

11821255
/* Zero so cleanup is safe if an early alloc failure skips init. */
11831256
XMEMSET(&key, 0, sizeof(key));
11841257
test_lms_xmss_verify_calls = 0;
11851258

11861259
ExpectIntEQ(wc_CryptoCb_RegisterDevice(TEST_LMS_XMSS_CRYPTOCB_DEVID,
1187-
test_lms_xmss_verify_cryptocb, NULL), 0);
1260+
test_lms_xmss_verify_cryptocb, reply), 0);
11881261

11891262
/* No read callback, so the reload leaves the state with the device. */
11901263
ExpectIntEQ(wc_XmssKey_Init(&key, NULL, TEST_LMS_XMSS_CRYPTOCB_DEVID), 0);
11911264
ExpectIntEQ(wc_XmssKey_SetParamStr(&key, "XMSS-SHA2_10_256"), 0);
11921265
ExpectIntEQ(wc_XmssKey_Reload(&key), 0);
1266+
#if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
1267+
ExpectIntEQ(wc_XmssKey_Reload(&key), WC_NO_ERR_TRACE(BAD_STATE_E));
1268+
#endif
11931269
ExpectNull(key.sk);
11941270

11951271
/* Only the signature length is checked before the device is asked, so the
@@ -1201,6 +1277,15 @@ int test_wc_XmssKey_reload_devid_verify(void)
12011277
XMEMSET(sig, 0, sigSz);
12021278
ExpectIntEQ(wc_XmssKey_Verify(&key, sig, sigSz, msg, sizeof(msg)), 0);
12031279
ExpectIntEQ(test_lms_xmss_verify_calls, 1);
1280+
#if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
1281+
verifyResult = 0;
1282+
ExpectIntEQ(wc_XmssKey_Verify(&key, sig, sigSz, msg, sizeof(msg)),
1283+
WC_NO_ERR_TRACE(SIG_VERIFY_E));
1284+
verifyResult = WC_NO_ERR_TRACE(WC_HW_E);
1285+
ExpectIntEQ(wc_XmssKey_Verify(&key, sig, sigSz, msg, sizeof(msg)),
1286+
WC_NO_ERR_TRACE(WC_HW_E));
1287+
ExpectIntEQ(test_lms_xmss_verify_calls, 3);
1288+
#endif
12041289
}
12051290

12061291
XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
@@ -2627,6 +2712,48 @@ int test_wc_LmsDecisionCoverage(void)
26272712

26282713
ExpectIntEQ(wc_LmsKey_Init(&key, NULL, INVALID_DEVID), 0);
26292714

2715+
#if defined(WOLF_PRIVATE_KEY_ID) && !defined(HAVE_SELFTEST) && \
2716+
!defined(HAVE_FIPS)
2717+
{
2718+
static const byte id[] = {1};
2719+
char label[LMS_MAX_LABEL_LEN + 2];
2720+
LmsKey identified;
2721+
2722+
XMEMSET(&identified, 0, sizeof(identified));
2723+
ExpectIntEQ(wc_LmsKey_InitId(NULL, id, 1, NULL, INVALID_DEVID),
2724+
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
2725+
ExpectIntEQ(wc_LmsKey_InitId(&identified, NULL, 1, NULL,
2726+
INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
2727+
ExpectIntEQ(wc_LmsKey_InitId(&identified, id, -1, NULL,
2728+
INVALID_DEVID), WC_NO_ERR_TRACE(BUFFER_E));
2729+
ExpectIntEQ(wc_LmsKey_InitId(&identified, id, LMS_MAX_ID_LEN + 1,
2730+
NULL, INVALID_DEVID), WC_NO_ERR_TRACE(BUFFER_E));
2731+
ExpectIntEQ(wc_LmsKey_InitId(&identified, NULL, 0, NULL,
2732+
INVALID_DEVID), 0);
2733+
wc_LmsKey_Free(&identified);
2734+
ExpectIntEQ(wc_LmsKey_InitId(&identified, id, 0, NULL,
2735+
INVALID_DEVID), 0);
2736+
wc_LmsKey_Free(&identified);
2737+
ExpectIntEQ(wc_LmsKey_InitId(&identified, id, 1, NULL,
2738+
INVALID_DEVID), 0);
2739+
wc_LmsKey_Free(&identified);
2740+
2741+
XMEMSET(label, 'a', sizeof(label) - 1);
2742+
label[sizeof(label) - 1] = '\0';
2743+
ExpectIntEQ(wc_LmsKey_InitLabel(NULL, "key", NULL, INVALID_DEVID),
2744+
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
2745+
ExpectIntEQ(wc_LmsKey_InitLabel(&identified, NULL, NULL,
2746+
INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
2747+
ExpectIntEQ(wc_LmsKey_InitLabel(&identified, "", NULL,
2748+
INVALID_DEVID), WC_NO_ERR_TRACE(BUFFER_E));
2749+
ExpectIntEQ(wc_LmsKey_InitLabel(&identified, label, NULL,
2750+
INVALID_DEVID), WC_NO_ERR_TRACE(BUFFER_E));
2751+
ExpectIntEQ(wc_LmsKey_InitLabel(&identified, "key", NULL,
2752+
INVALID_DEVID), 0);
2753+
wc_LmsKey_Free(&identified);
2754+
}
2755+
#endif
2756+
26302757
/* wc_LmsKey_SetParameters: unknown (levels,height,winternitz) triple ->
26312758
* table search exhausts and returns BAD_FUNC_ARG. Independence: vary one
26322759
* coordinate at a time away from the known-good L1/H5/W8 set (the others
@@ -2954,6 +3081,48 @@ int test_wc_XmssDecisionCoverage(void)
29543081
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
29553082
ExpectIntEQ(wc_XmssKey_Init(&key, NULL, INVALID_DEVID), 0);
29563083

3084+
#if defined(WOLF_PRIVATE_KEY_ID) && !defined(HAVE_SELFTEST) && \
3085+
!defined(HAVE_FIPS)
3086+
{
3087+
static const byte id[] = {1};
3088+
char label[XMSS_MAX_LABEL_LEN + 2];
3089+
XmssKey identified;
3090+
3091+
XMEMSET(&identified, 0, sizeof(identified));
3092+
ExpectIntEQ(wc_XmssKey_InitId(NULL, id, 1, NULL, INVALID_DEVID),
3093+
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
3094+
ExpectIntEQ(wc_XmssKey_InitId(&identified, NULL, 1, NULL,
3095+
INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
3096+
ExpectIntEQ(wc_XmssKey_InitId(&identified, id, -1, NULL,
3097+
INVALID_DEVID), WC_NO_ERR_TRACE(BUFFER_E));
3098+
ExpectIntEQ(wc_XmssKey_InitId(&identified, id, XMSS_MAX_ID_LEN + 1,
3099+
NULL, INVALID_DEVID), WC_NO_ERR_TRACE(BUFFER_E));
3100+
ExpectIntEQ(wc_XmssKey_InitId(&identified, NULL, 0, NULL,
3101+
INVALID_DEVID), 0);
3102+
wc_XmssKey_Free(&identified);
3103+
ExpectIntEQ(wc_XmssKey_InitId(&identified, id, 0, NULL,
3104+
INVALID_DEVID), 0);
3105+
wc_XmssKey_Free(&identified);
3106+
ExpectIntEQ(wc_XmssKey_InitId(&identified, id, 1, NULL,
3107+
INVALID_DEVID), 0);
3108+
wc_XmssKey_Free(&identified);
3109+
3110+
XMEMSET(label, 'a', sizeof(label) - 1);
3111+
label[sizeof(label) - 1] = '\0';
3112+
ExpectIntEQ(wc_XmssKey_InitLabel(NULL, "key", NULL, INVALID_DEVID),
3113+
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
3114+
ExpectIntEQ(wc_XmssKey_InitLabel(&identified, NULL, NULL,
3115+
INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
3116+
ExpectIntEQ(wc_XmssKey_InitLabel(&identified, "", NULL,
3117+
INVALID_DEVID), WC_NO_ERR_TRACE(BUFFER_E));
3118+
ExpectIntEQ(wc_XmssKey_InitLabel(&identified, label, NULL,
3119+
INVALID_DEVID), WC_NO_ERR_TRACE(BUFFER_E));
3120+
ExpectIntEQ(wc_XmssKey_InitLabel(&identified, "key", NULL,
3121+
INVALID_DEVID), 0);
3122+
wc_XmssKey_Free(&identified);
3123+
}
3124+
#endif
3125+
29573126
/* wc_XmssKey_SetParamStr: NULL key vs NULL str (independence pair), then
29583127
* an unknown parameter string -> BAD_FUNC_ARG from the lookup. */
29593128
ExpectIntEQ(wc_XmssKey_SetParamStr(NULL, "XMSS-SHA2_10_256"),
@@ -3139,6 +3308,16 @@ int test_wc_LmsKey_make_key_id_dev(void)
31393308
wc_LmsKey_Free(&key);
31403309

31413310
wc_CryptoCb_UnRegisterDevice(TEST_LMS_XMSS_CRYPTOCB_DEVID);
3311+
#if !defined(HAVE_SELFTEST) && !defined(WOLF_CRYPTO_CB_ONLY_LMS) && \
3312+
!defined(WOLF_CRYPTO_CB_FIND)
3313+
/* Without the registered device, key generation checks the software
3314+
* key's storage callbacks. The fresh key has no write callback. */
3315+
ExpectIntEQ(wc_LmsKey_InitId(&key, id, (int)sizeof(id), NULL,
3316+
TEST_LMS_XMSS_CRYPTOCB_DEVID), 0);
3317+
ExpectIntEQ(test_lms_set_params(&key), 0);
3318+
ExpectIntEQ(wc_LmsKey_MakeKey(&key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
3319+
wc_LmsKey_Free(&key);
3320+
#endif
31423321
DoExpectIntEQ(wc_FreeRng(&rng), 0);
31433322
#endif
31443323
return EXPECT_RESULT();
@@ -3180,6 +3359,16 @@ int test_wc_XmssKey_make_key_id_dev(void)
31803359
wc_XmssKey_Free(&key);
31813360

31823361
wc_CryptoCb_UnRegisterDevice(TEST_LMS_XMSS_CRYPTOCB_DEVID);
3362+
#if !defined(HAVE_SELFTEST) && !defined(WOLF_CRYPTO_CB_ONLY_XMSS) && \
3363+
!defined(WOLF_CRYPTO_CB_FIND)
3364+
/* Without the registered device, key generation checks the software
3365+
* key's storage callbacks. The fresh key has no write callback. */
3366+
ExpectIntEQ(wc_XmssKey_InitId(&key, id, (int)sizeof(id), NULL,
3367+
TEST_LMS_XMSS_CRYPTOCB_DEVID), 0);
3368+
ExpectIntEQ(wc_XmssKey_SetParamStr(&key, "XMSS-SHA2_10_256"), 0);
3369+
ExpectIntEQ(wc_XmssKey_MakeKey(&key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
3370+
wc_XmssKey_Free(&key);
3371+
#endif
31833372
DoExpectIntEQ(wc_FreeRng(&rng), 0);
31843373
#endif
31853374
return EXPECT_RESULT();

‎tests/api/test_mldsa.c‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32756,6 +32756,23 @@ int test_wc_MldsaDecisionCoverage2(void)
3275632756
}
3275732757
#endif
3275832758

32759+
#if defined(WOLFSSL_MLDSA_PRIVATE_KEY) && \
32760+
!defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
32761+
{
32762+
byte out[1];
32763+
word32 outLen = (word32)sizeof(out);
32764+
32765+
ExpectIntEQ(wc_MlDsaKey_ExportPrivRaw(NULL, out, &outLen),
32766+
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
32767+
ExpectIntEQ(wc_MlDsaKey_ExportPrivRaw(&key, NULL, &outLen),
32768+
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
32769+
ExpectIntEQ(wc_MlDsaKey_ExportPrivRaw(&key, out, NULL),
32770+
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
32771+
ExpectIntEQ(wc_MlDsaKey_ExportPrivRaw(&key, out, &outLen),
32772+
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
32773+
}
32774+
#endif
32775+
3275932776
/* wc_MlDsaKey_SignCtxHash / SignCtxWithSeed / SignCtxHashWithSeed /
3276032777
* SignMuWithSeed: independence of each four/five-way NULL OR and the
3276132778
* ctxLen>0/muLen!=MU_SZ guards. Hold all other operands valid and
@@ -32820,6 +32837,17 @@ int test_wc_MldsaDecisionCoverage2(void)
3282032837
ExpectIntEQ(wc_MlDsaKey_SignCtxWithSeed(&key, NULL, 1, sig, &sigLen,
3282132838
msg, (word32)sizeof(msg), seed), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
3282232839

32840+
#if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
32841+
/* The length checks run before hashing or dispatch. Keep the key
32842+
* without private material so no signature can be attempted. */
32843+
ExpectIntEQ(wc_MlDsaKey_SignCtx(&key, NULL, 0, sig, &sigLen, msg,
32844+
(word32)(WOLFSSL_MAX_32BIT / 2) + 1, &rng),
32845+
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
32846+
ExpectIntEQ(wc_MlDsaKey_SignCtxWithSeed(&key, NULL, 0, sig, &sigLen,
32847+
msg, (word32)(WOLFSSL_MAX_32BIT / 2) + 1, seed),
32848+
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
32849+
#endif
32850+
3282332851
#ifdef WOLFSSL_MLDSA_NO_CTX
3282432852
/* wc_MlDsaKey_SignWithSeed: five-way NULL OR (incl. seed). */
3282532853
sigLen = (word32)sizeof(sig);

‎tests/api/test_mlkem.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5475,6 +5475,32 @@ int test_wc_mlkem_decapsulate_id_key(void)
54755475
ExpectIntEQ(wc_MlKemKey_Decapsulate(key, ss, ct, ctLen), 0);
54765476
ExpectIntEQ(seen.calls, 3);
54775477

5478+
#if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
5479+
{
5480+
WC_RNG rng;
5481+
5482+
XMEMSET(&rng, 0, sizeof(rng));
5483+
ExpectIntEQ(wc_InitRng(&rng), 0);
5484+
if (keyInit) {
5485+
wc_MlKemKey_Free(key);
5486+
keyInit = 0;
5487+
}
5488+
ExpectIntEQ(wc_MlKemKey_Init_Id(key, TEST_MLKEM_CB_PENDING_TYPE, id,
5489+
(int)sizeof(id), NULL, TEST_MLKEM_CB_PENDING_DEVID), 0);
5490+
if (EXPECT_SUCCESS()) {
5491+
keyInit = 1;
5492+
}
5493+
seen.ret = 0;
5494+
ExpectIntEQ(wc_MlKemKey_Encapsulate(key, ct, ss, &rng), 0);
5495+
ExpectIntEQ(seen.calls, 4);
5496+
seen.ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE);
5497+
ExpectIntEQ(wc_MlKemKey_Encapsulate(key, ct, ss, &rng),
5498+
WC_NO_ERR_TRACE(BAD_STATE_E));
5499+
ExpectIntEQ(seen.calls, 5);
5500+
DoExpectIntEQ(wc_FreeRng(&rng), 0);
5501+
}
5502+
#endif
5503+
54785504
if (keyInit) {
54795505
wc_MlKemKey_Free(key);
54805506
}

‎tests/api/test_slhdsa.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,11 @@ int test_wc_slhdsa_verify(void)
889889

890890
ExpectIntEQ(wc_SlhDsaKey_Init(&key, TEST_SLHDSA_DEFAULT_PARAM, NULL,
891891
INVALID_DEVID), 0);
892+
#if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
893+
sigLen = WC_SLHDSA_MAX_SIG_LEN;
894+
ExpectIntEQ(wc_SlhDsaKey_Sign(&key, ctx, sizeof(ctx), msg, sizeof(msg),
895+
sig, &sigLen, &rng), WC_NO_ERR_TRACE(MISSING_KEY));
896+
#endif
892897
ExpectIntEQ(wc_SlhDsaKey_MakeKey(&key, &rng), 0);
893898

894899
/* Generate a signature. */
@@ -933,6 +938,17 @@ int test_wc_slhdsa_verify(void)
933938
ExpectIntEQ(wc_SlhDsaKey_Verify(&key, NULL, 0, msg, sizeof(msg),
934939
sig, sigLen), 0);
935940

941+
#if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
942+
/* A NULL message represents an empty message only when its size is 0. */
943+
sigLen = WC_SLHDSA_MAX_SIG_LEN;
944+
ExpectIntEQ(wc_SlhDsaKey_Sign(&key, ctx, sizeof(ctx), NULL, 1, sig,
945+
&sigLen, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
946+
ExpectIntEQ(wc_SlhDsaKey_Sign(&key, ctx, sizeof(ctx), NULL, 0, sig,
947+
&sigLen, &rng), 0);
948+
ExpectIntEQ(wc_SlhDsaKey_Verify(&key, ctx, sizeof(ctx), NULL, 0, sig,
949+
sigLen), 0);
950+
#endif
951+
936952
wc_SlhDsaKey_Free(&key);
937953

938954
wc_FreeRng(&rng);

0 commit comments

Comments
 (0)