Skip to content

Commit 094ddb6

Browse files
committed
Add wc_LmsKey_ExportPubRaw to wolfcrypt test.
1 parent bc00c95 commit 094ddb6

1 file changed

Lines changed: 46 additions & 17 deletions

File tree

wolfcrypt/test/test.c

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,8 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t scrypt_test(void);
639639
#endif
640640
#if defined(WOLFSSL_HAVE_LMS)
641641
#if !defined(WOLFSSL_SMALL_STACK)
642-
#if defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10)
642+
#if (defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10)) || \
643+
defined(HAVE_LIBLMS)
643644
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test_verify_only(void);
644645
#endif
645646
#endif
@@ -1807,7 +1808,8 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
18071808

18081809
#if defined(WOLFSSL_HAVE_LMS)
18091810
#if !defined(WOLFSSL_SMALL_STACK)
1810-
#if defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10)
1811+
#if (defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10)) || \
1812+
defined(HAVE_LIBLMS)
18111813
if ( (ret = lms_test_verify_only()) != 0)
18121814
TEST_FAIL("LMS Vfy test failed!\n", ret);
18131815
else
@@ -38532,7 +38534,8 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test(void)
3853238534
#endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
3853338535

3853438536
#if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_SMALL_STACK)
38535-
#if defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10)
38537+
#if (defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10)) || \
38538+
defined(HAVE_LIBLMS)
3853638539

3853738540
/* A simple LMS verify only test.
3853838541
*
@@ -38756,18 +38759,23 @@ static byte lms_L1H10W8_sig[LMS_L1H10W8_SIGLEN] =
3875638759

3875738760
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test_verify_only(void)
3875838761
{
38759-
int ret = -1;
38760-
int ret2 = -1;
38761-
int j = 0;
38762-
LmsKey verifyKey;
38763-
word32 sigSz = 0;
38764-
word32 msgSz = sizeof(lms_msg);
38765-
word32 pubLen = 0;
38766-
int levels = 0;
38767-
int height = 0;
38768-
int winternitz = 0;
38762+
LmsKey verifyKey;
38763+
unsigned char pub_raw[HSS_MAX_PUBLIC_KEY_LEN];
38764+
word32 pub_len = sizeof(pub_raw);
38765+
word32 sigSz = 0;
38766+
word32 msgSz = sizeof(lms_msg);
38767+
word32 pubSz = 0;
38768+
int levels = 0;
38769+
int height = 0;
38770+
int winternitz = 0;
38771+
int ret = -1;
38772+
int ret2 = -1;
38773+
int j = 0;
38774+
int n_diff = 0;
3876938775
WOLFSSL_ENTER("lms_test_verify_only");
3877038776

38777+
XMEMSET(pub_raw, 0, sizeof(pub_raw));
38778+
3877138779
ret = wc_LmsKey_Init(&verifyKey, NULL, INVALID_DEVID);
3877238780
if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
3877338781

@@ -38788,12 +38796,12 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test_verify_only(void)
3878838796
return -1;
3878938797
}
3879038798

38791-
ret = wc_LmsKey_GetPubLen(&verifyKey, &pubLen);
38799+
ret = wc_LmsKey_GetPubLen(&verifyKey, &pubSz);
3879238800
if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
3879338801

38794-
if (pubLen != HSS_MAX_PUBLIC_KEY_LEN) {
38795-
printf("error: got %u, expected %d\n", pubLen, HSS_MAX_PUBLIC_KEY_LEN);
38796-
return WC_TEST_RET_ENC_EC(pubLen);
38802+
if (pubSz != HSS_MAX_PUBLIC_KEY_LEN) {
38803+
printf("error: got %u, expected %d\n", pubSz, HSS_MAX_PUBLIC_KEY_LEN);
38804+
return WC_TEST_RET_ENC_EC(pubSz);
3879738805
}
3879838806

3879938807
ret = wc_LmsKey_GetSigLen(&verifyKey, &sigSz);
@@ -38811,6 +38819,27 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test_verify_only(void)
3881138819
return WC_TEST_RET_ENC_EC(ret);
3881238820
}
3881338821

38822+
/* Now test the ExportPubRaw API, verify we recover the original pub. */
38823+
ret = wc_LmsKey_ExportPubRaw(&verifyKey, pub_raw, &pub_len);
38824+
if (ret != 0) {
38825+
printf("error: wc_LmsKey_ExportPubRaw returned %d, expected 0\n", ret);
38826+
return WC_TEST_RET_ENC_EC(ret);
38827+
}
38828+
38829+
if (pub_len != HSS_MAX_PUBLIC_KEY_LEN) {
38830+
printf("error: LMS pub len %d, expected %d\n", pub_len,
38831+
HSS_MAX_PUBLIC_KEY_LEN);
38832+
return WC_TEST_RET_ENC_EC(pub_len);
38833+
}
38834+
38835+
n_diff = XMEMCMP(pub_raw, lms_L1H10W8_pub, sizeof(lms_L1H10W8_pub));
38836+
38837+
if (n_diff != 0) {
38838+
printf("error: exported and imported pub raw do not match: %d\n",
38839+
n_diff);
38840+
return WC_TEST_RET_ENC_EC(n_diff);
38841+
}
38842+
3881438843
/* Flip bits in message. This should fail. */
3881538844
lms_msg[msgSz / 2] ^= 1;
3881638845
ret2 = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,

0 commit comments

Comments
 (0)