Skip to content

Commit b36c312

Browse files
committed
LMS verify-only support: fix clang warning, rename define.
1 parent 03088b2 commit b36c312

6 files changed

Lines changed: 37 additions & 35 deletions

File tree

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ do
11581158
;;
11591159
verify-only)
11601160
LMS_VERIFY_ONLY=yes
1161-
AM_CFLAGS="$AM_CFLAGS -DLMS_VERIFY_ONLY"
1161+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_LMS_VERIFY_ONLY"
11621162
;;
11631163
wolfssl)
11641164
ENABLED_WC_LMS=yes

wolfcrypt/benchmark/benchmark.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
#include <wolfssl/wolfcrypt/ext_kyber.h>
158158
#endif
159159
#endif
160-
#if defined(WOLFSSL_HAVE_LMS) && !defined(LMS_VERIFY_ONLY)
160+
#if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
161161
#include <wolfssl/wolfcrypt/lms.h>
162162
#ifdef HAVE_LIBLMS
163163
#include <wolfssl/wolfcrypt/ext_lms.h>
@@ -870,7 +870,7 @@ static const bench_alg bench_other_opt[] = {
870870

871871
#endif /* !WOLFSSL_BENCHMARK_ALL && !NO_MAIN_DRIVER */
872872

873-
#if defined(WOLFSSL_HAVE_LMS) && !defined(LMS_VERIFY_ONLY)
873+
#if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
874874
typedef struct bench_pq_hash_sig_alg {
875875
/* Command line option string. */
876876
const char* str;
@@ -883,7 +883,7 @@ static const bench_pq_hash_sig_alg bench_pq_hash_sig_opt[] = {
883883
{ "-lms_hss", BENCH_LMS_HSS},
884884
{ NULL, 0}
885885
};
886-
#endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(LMS_VERIFY_ONLY) */
886+
#endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
887887

888888
#if defined(HAVE_PQC) && defined(HAVE_LIBOQS)
889889
/* The post-quantum-specific mapping of command line option to bit values and
@@ -2832,11 +2832,11 @@ static void* benchmarks_do(void* args)
28322832
}
28332833
#endif
28342834

2835-
#if defined(WOLFSSL_HAVE_LMS) && !defined(LMS_VERIFY_ONLY)
2835+
#if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
28362836
if (bench_all || (bench_pq_hash_sig_algs & BENCH_LMS_HSS)) {
28372837
bench_lms();
28382838
}
2839-
#endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(LMS_VERIFY_ONLY) */
2839+
#endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
28402840

28412841
#ifdef HAVE_ECC
28422842
if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY) ||
@@ -7664,7 +7664,7 @@ void bench_kyber(int type)
76647664
}
76657665
#endif
76667666

7667-
#if defined(WOLFSSL_HAVE_LMS) && !defined(LMS_VERIFY_ONLY)
7667+
#if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
76687668
/* WC_LMS_PARM_L2_H10_W2
76697669
* signature length: 9300 */
76707670
static const byte lms_priv_L2_H10_W2[64] =
@@ -8031,7 +8031,7 @@ void bench_lms(void)
80318031
return;
80328032
}
80338033

8034-
#endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(LMS_VERIFY_ONLY) */
8034+
#endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
80358035

80368036
#ifdef HAVE_ECC
80378037

@@ -10368,10 +10368,10 @@ static void Usage(void)
1036810368
print_alg(bench_pq_asym_opt2[i].str, &line);
1036910369
#endif /* HAVE_LIBOQS && HAVE_SPHINCS */
1037010370
#endif /* HAVE_PQC */
10371-
#if defined(WOLFSSL_HAVE_LMS) && !defined(LMS_VERIFY_ONLY)
10371+
#if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
1037210372
for (i=0; bench_pq_hash_sig_opt[i].str != NULL; i++)
1037310373
print_alg(bench_pq_hash_sig_opt[i].str, &line);
10374-
#endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(LMS_VERIFY_ONLY) */
10374+
#endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
1037510375
printf("\n");
1037610376
#endif /* !WOLFSSL_BENCHMARK_ALL */
1037710377
e++;
@@ -10634,7 +10634,7 @@ int wolfcrypt_benchmark_main(int argc, char** argv)
1063410634
}
1063510635
}
1063610636

10637-
#if defined(WOLFSSL_HAVE_LMS) && !defined(LMS_VERIFY_ONLY)
10637+
#if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
1063810638
/* post-quantum stateful hash-based signatures */
1063910639
for (i=0; !optMatched && bench_pq_hash_sig_opt[i].str != NULL; i++) {
1064010640
if (string_matches(argv[1], bench_pq_hash_sig_opt[i].str)) {
@@ -10643,7 +10643,7 @@ int wolfcrypt_benchmark_main(int argc, char** argv)
1064310643
optMatched = 1;
1064410644
}
1064510645
}
10646-
#endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(LMS_VERIFY_ONLY) */
10646+
#endif
1064710647
#endif
1064810648
if (!optMatched) {
1064910649
printf("Option not recognized: %s\n", argv[1]);

wolfcrypt/src/ext_lms.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#include <wolfcrypt/src/misc.c>
3838
#endif
3939

40-
#ifndef LMS_VERIFY_ONLY
40+
#ifndef WOLFSSL_LMS_VERIFY_ONLY
4141
/* If built against hss_lib_thread.a, the hash-sigs lib will spawn
4242
* worker threads to parallelize cpu intensive tasks. This will mainly
4343
* speedup key generation and signing, and to a lesser extent
@@ -102,7 +102,8 @@ static bool LmsWritePrivKey(unsigned char *private_key,
102102
}
103103

104104
/* Use write callback that saves private key to non-volatile storage. */
105-
ret = key->write_private_key(private_key, len_private_key, key->context);
105+
ret = key->write_private_key(private_key, (word32)len_private_key,
106+
key->context);
106107

107108
if (ret != WC_LMS_RC_SAVED_TO_NV_MEMORY) {
108109
WOLFSSL_MSG("error: LmsKey write_private_key failed");
@@ -141,7 +142,8 @@ static bool LmsReadPrivKey(unsigned char *private_key,
141142
}
142143

143144
/* Use read callback that reads private key from non-volatile storage. */
144-
ret = key->read_private_key(private_key, len_private_key, key->context);
145+
ret = key->read_private_key(private_key, (word32)len_private_key,
146+
key->context);
145147

146148
if (ret != WC_LMS_RC_READ_TO_MEMORY) {
147149
WOLFSSL_MSG("error: LmsKey read_private_key failed");
@@ -152,7 +154,7 @@ static bool LmsReadPrivKey(unsigned char *private_key,
152154

153155
return true;
154156
}
155-
#endif /* ifndef LMS_VERIFY_ONLY */
157+
#endif /* ifndef WOLFSSL_LMS_VERIFY_ONLY */
156158

157159
const char * wc_LmsKey_ParmToStr(enum wc_LmsParm lmsParm)
158160
{
@@ -244,7 +246,7 @@ int wc_LmsKey_Init(LmsKey * key, void * heap, int devId)
244246

245247
ForceZero(key, sizeof(LmsKey));
246248

247-
#ifndef LMS_VERIFY_ONLY
249+
#ifndef WOLFSSL_LMS_VERIFY_ONLY
248250
hss_init_extra_info(&key->info);
249251
/* Set the max number of worker threads that hash-sigs can spawn. */
250252
hss_extra_info_set_threads(&key->info, EXT_LMS_MAX_THREADS);
@@ -253,7 +255,7 @@ int wc_LmsKey_Init(LmsKey * key, void * heap, int devId)
253255
key->write_private_key = NULL;
254256
key->read_private_key = NULL;
255257
key->context = NULL;
256-
#endif /* ifndef LMS_VERIFY_ONLY */
258+
#endif /* ifndef WOLFSSL_LMS_VERIFY_ONLY */
257259
key->state = WC_LMS_STATE_INITED;
258260

259261
return 0;
@@ -483,12 +485,12 @@ void wc_LmsKey_Free(LmsKey* key)
483485
return;
484486
}
485487

486-
#ifndef LMS_VERIFY_ONLY
488+
#ifndef WOLFSSL_LMS_VERIFY_ONLY
487489
if (key->working_key != NULL) {
488490
hss_free_working_key(key->working_key);
489491
key->working_key = NULL;
490492
}
491-
#endif /* ifndef LMS_VERIFY_ONLY */
493+
#endif /* ifndef WOLFSSL_LMS_VERIFY_ONLY */
492494

493495
ForceZero(key, sizeof(LmsKey));
494496

@@ -497,7 +499,7 @@ void wc_LmsKey_Free(LmsKey* key)
497499
return;
498500
}
499501

500-
#ifndef LMS_VERIFY_ONLY
502+
#ifndef WOLFSSL_LMS_VERIFY_ONLY
501503
/* Set the write private key callback to the LMS key structure.
502504
*
503505
* The callback must be able to write/update the private key to
@@ -807,7 +809,7 @@ int wc_LmsKey_SigsLeft(LmsKey * key)
807809
return 1;
808810
}
809811

810-
#endif /* ifndef LMS_VERIFY_ONLY*/
812+
#endif /* ifndef WOLFSSL_LMS_VERIFY_ONLY*/
811813

812814
/* Given a levels, height, winternitz parameter set, determine
813815
* the public key length */
@@ -950,7 +952,7 @@ int wc_LmsKey_Verify(LmsKey * key, const byte * sig, word32 sigSz,
950952
return BAD_FUNC_ARG;
951953
}
952954

953-
#ifdef LMS_VERIFY_ONLY
955+
#ifdef WOLFSSL_LMS_VERIFY_ONLY
954956
result = hss_validate_signature(key->pub, (const void *) msg, msgSz, sig,
955957
sigSz, NULL);
956958
#else

wolfcrypt/test/test.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -575,10 +575,10 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t scrypt_test(void);
575575
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t kyber_test(void);
576576
#endif
577577
#if defined(WOLFSSL_HAVE_LMS)
578-
#if !defined(LMS_VERIFY_ONLY)
578+
#if !defined(WOLFSSL_LMS_VERIFY_ONLY)
579579
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test(void);
580580
#endif
581-
#if defined(LMS_VERIFY_ONLY) && !defined(WOLFSSL_SMALL_STACK)
581+
#if defined(WOLFSSL_LMS_VERIFY_ONLY) && !defined(WOLFSSL_SMALL_STACK)
582582
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test_verify_only(void);
583583
#endif
584584
#endif
@@ -1612,14 +1612,14 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
16121612
#endif
16131613

16141614
#if defined(WOLFSSL_HAVE_LMS)
1615-
#if !defined(LMS_VERIFY_ONLY)
1615+
#if !defined(WOLFSSL_LMS_VERIFY_ONLY)
16161616
if ( (ret = lms_test()) != 0)
16171617
TEST_FAIL("LMS test failed!\n", ret);
16181618
else
16191619
TEST_PASS("LMS test passed!\n");
16201620
#endif
16211621

1622-
#if defined(LMS_VERIFY_ONLY) && !defined(WOLFSSL_SMALL_STACK)
1622+
#if defined(WOLFSSL_LMS_VERIFY_ONLY) && !defined(WOLFSSL_SMALL_STACK)
16231623
if ( (ret = lms_test_verify_only()) != 0)
16241624
TEST_FAIL("LMS test failed!\n", ret);
16251625
else
@@ -34955,7 +34955,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t kyber_test(void)
3495534955
#endif /* WOLFSSL_HAVE_KYBER */
3495634956

3495734957

34958-
#if defined(WOLFSSL_HAVE_LMS) && !defined(LMS_VERIFY_ONLY)
34958+
#if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
3495934959
static int lms_write_key_mem(const byte * priv, word32 privSz, void *context)
3496034960
{
3496134961
/* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
@@ -35090,9 +35090,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test(void)
3509035090
return ret;
3509135091
}
3509235092

35093-
#endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(LMS_VERIFY_ONLY) */
35093+
#endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
3509435094

35095-
#if defined(WOLFSSL_HAVE_LMS) && defined(LMS_VERIFY_ONLY) && \
35095+
#if defined(WOLFSSL_HAVE_LMS) && defined(WOLFSSL_LMS_VERIFY_ONLY) && \
3509635096
!defined(WOLFSSL_SMALL_STACK)
3509735097

3509835098
/* A simple LMS verify only test.
@@ -35365,7 +35365,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test_verify_only(void)
3536535365
return ret;
3536635366
}
3536735367

35368-
#endif /* if defined(WOLFSSL_HAVE_LMS) && defined(LMS_VERIFY_ONLY) &&
35368+
#endif /* if defined(WOLFSSL_HAVE_LMS) && defined(WOLFSSL_LMS_VERIFY_ONLY) &&
3536935369
* !defined(WOLFSSL_SMALL_STACK) */
3537035370

3537135371
static const int fiducial3 = WC_TEST_RET_LN; /* source code reference point --

wolfssl/wolfcrypt/ext_lms.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ struct LmsKey {
5151
param_set_t lm_type[MAX_HSS_LEVELS]; /* Height parm per level. */
5252
param_set_t lm_ots_type[MAX_HSS_LEVELS]; /* Winternitz parm per level. */
5353
unsigned char pub[HSS_MAX_PUBLIC_KEY_LEN];
54-
#ifndef LMS_VERIFY_ONLY
54+
#ifndef WOLFSSL_LMS_VERIFY_ONLY
5555
hss_working_key * working_key;
5656
write_private_key_cb write_private_key; /* Callback to write/update key. */
5757
read_private_key_cb read_private_key; /* Callback to read key. */
5858
void * context; /* Context arg passed to callbacks. */
5959
hss_extra_info info;
60-
#endif /* ifndef LMS_VERIFY_ONLY */
60+
#endif /* ifndef WOLFSSL_LMS_VERIFY_ONLY */
6161
enum wc_LmsState state;
6262
};
6363

wolfssl/wolfcrypt/lms.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ WOLFSSL_API int wc_LmsKey_SetParameters(LmsKey * key, int levels,
111111
int height, int winternitz);
112112
WOLFSSL_API int wc_LmsKey_GetParameters(const LmsKey * key, int * levels,
113113
int * height, int * winternitz);
114-
#ifndef LMS_VERIFY_ONLY
114+
#ifndef WOLFSSL_LMS_VERIFY_ONLY
115115
WOLFSSL_API int wc_LmsKey_SetWriteCb(LmsKey * key,
116116
write_private_key_cb write_cb);
117117
WOLFSSL_API int wc_LmsKey_SetReadCb(LmsKey * key,
@@ -123,7 +123,7 @@ WOLFSSL_API int wc_LmsKey_GetPrivLen(const LmsKey * key, word32 * len);
123123
WOLFSSL_API int wc_LmsKey_Sign(LmsKey * key, byte * sig, word32 * sigSz,
124124
const byte * msg, int msgSz);
125125
WOLFSSL_API int wc_LmsKey_SigsLeft(LmsKey * key);
126-
#endif /* ifndef LMS_VERIFY_ONLY */
126+
#endif /* ifndef WOLFSSL_LMS_VERIFY_ONLY */
127127
WOLFSSL_API void wc_LmsKey_Free(LmsKey * key);
128128
WOLFSSL_API int wc_LmsKey_GetSigLen(const LmsKey * key, word32 * len);
129129
WOLFSSL_API int wc_LmsKey_GetPubLen(const LmsKey * key, word32 * len);

0 commit comments

Comments
 (0)