Skip to content

Commit cd02d51

Browse files
Merge pull request #6738 from philljj/wolfcrypt_lms_verify_only
Wolfcrypt LMS verify-only support
2 parents efd08ea + b36c312 commit cd02d51

7 files changed

Lines changed: 622 additions & 156 deletions

File tree

INSTALL

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,20 +264,20 @@ We also have vcpkg ports for wolftpm, wolfmqtt and curl.
264264
branch of the hash-sigs project.
265265

266266
Currently the hash-sigs project only builds static libraries:
267+
- hss_verify.a: a single-threaded verify-only static lib.
267268
- hss_lib.a: a single-threaded static lib.
268269
- hss_lib_thread.a: a multi-threaded static lib.
269270

270271
The multi-threaded version will mainly have speedups for key
271272
generation and signing.
272273

273-
Additionally, the hash-sigs project can be modified to build
274-
and install a shared library in /usr/local with either single
275-
or multi-threaded versions. If the shared version has been
276-
built, libhss.so is the assumed name.
274+
The default LMS build (--enable-lms) will look for
275+
hss_lib.a first, and hss_lib_thread.a second, in a specified
276+
hash-sigs dir.
277277

278-
wolfSSL supports either option, and by default will look for
279-
hss_lib.a first, and hss_lib_thread.a second, and libhss.so
280-
lastly, in a specified hash-sigs dir.
278+
The LMS verify-only build (--enable-lms=verify-only) will look
279+
for hss_verify.a only, which is a slimmer library that includes
280+
only the minimal functions necessary for signature verification.
281281

282282
How to get and build the hash-sigs library:
283283
$ mkdir ~/hash_sigs
@@ -299,12 +299,17 @@ We also have vcpkg ports for wolftpm, wolfmqtt and curl.
299299
$ ls *.a
300300
hss_lib_thread.a
301301

302+
To build verify-only:
303+
$ make hss_verify.a
304+
$ ls *.a
305+
hss_verify.a
306+
302307
Build wolfSSL with
303308
$ ./configure \
304309
--enable-static \
305310
--disable-shared \
306-
--enable-lms=yes \
307-
--with-liblms=<path to dir containing hss_lib_thread.a>
311+
--enable-lms \
312+
--with-liblms=<path to dir containing hss_lib.a or hss_lib_thread.a>
308313
$ make
309314

310315
Run the benchmark against LMS/HSS with:

configure.ac

Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,49 @@ then
11411141
fi
11421142

11431143

1144+
# LMS
1145+
AC_ARG_ENABLE([lms],
1146+
[AS_HELP_STRING([--enable-lms],[Enable stateful LMS/HSS signatures (default: disabled)])],
1147+
[ ENABLED_LMS=$enableval ],
1148+
[ ENABLED_LMS=no ]
1149+
)
1150+
1151+
ENABLED_WC_LMS=no
1152+
for v in `echo $ENABLED_LMS | tr "," " "`
1153+
do
1154+
case $v in
1155+
yes)
1156+
;;
1157+
no)
1158+
;;
1159+
verify-only)
1160+
LMS_VERIFY_ONLY=yes
1161+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_LMS_VERIFY_ONLY"
1162+
;;
1163+
wolfssl)
1164+
ENABLED_WC_LMS=yes
1165+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_WC_LMS"
1166+
;;
1167+
*)
1168+
AC_MSG_ERROR([Invalid choice for LMS []: $ENABLED_LMS.])
1169+
break;;
1170+
esac
1171+
done
1172+
1173+
if test "$ENABLED_LMS" != "no"
1174+
then
1175+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_HAVE_LMS"
1176+
1177+
if test "$ENABLED_WC_LMS" = "no";
1178+
then
1179+
# Default is to use hash-sigs LMS lib. Make sure it's enabled.
1180+
if test "$ENABLED_LIBLMS" = "no"; then
1181+
AC_MSG_ERROR([The default implementation for LMS is the hash-sigs LMS/HSS lib.
1182+
Please use --with-liblms.])
1183+
fi
1184+
fi
1185+
fi
1186+
11441187
# liblms
11451188
# Get the path to the hash-sigs LMS HSS lib.
11461189
ENABLED_LIBLMS="no"
@@ -1160,10 +1203,21 @@ AC_ARG_WITH([liblms],
11601203
tryliblmsdir="/usr/local"
11611204
fi
11621205
1163-
# 1. By default use the hash-sigs single-threaded static library.
1164-
# 2. If 1 not found, then use the multi-threaded static lib.
1165-
# 3. If 2 not found, then use the multi-threaded dynamic lib.
1166-
if test -e $tryliblmsdir/hss_lib.a; then
1206+
# 1. If verify only build, use hss_verify.a
1207+
# 2. If normal build, by default use single-threaded hss_lib.a
1208+
# 3. If 2 not found, then use the multi-threaded hss_lib_thread.a
1209+
if test "$LMS_VERIFY_ONLY" = "yes"; then
1210+
if test -e $tryliblmsdir/hss_verify.a; then
1211+
CPPFLAGS="$AM_CPPFLAGS -DHAVE_LIBLMS -I$tryliblmsdir"
1212+
LIB_STATIC_ADD="$LIB_STATIC_ADD $tryliblmsdir/hss_verify.a"
1213+
enable_shared=no
1214+
enable_static=yes
1215+
liblms_linked=yes
1216+
else
1217+
AC_MSG_ERROR([hss_verify.a isn't found.
1218+
If it's already installed, specify its path using --with-liblms=/dir/])
1219+
fi
1220+
elif test -e $tryliblmsdir/hss_lib.a; then
11671221
CPPFLAGS="$AM_CPPFLAGS -DHAVE_LIBLMS -I$tryliblmsdir"
11681222
LIB_STATIC_ADD="$LIB_STATIC_ADD $tryliblmsdir/hss_lib.a"
11691223
enable_shared=no
@@ -1175,12 +1229,6 @@ AC_ARG_WITH([liblms],
11751229
enable_shared=no
11761230
enable_static=yes
11771231
liblms_linked=yes
1178-
elif test -e $tryliblmsdir/lib/libhss.so; then
1179-
LIBS="$LIBS -lhss"
1180-
CPPFLAGS="$AM_CPPFLAGS -DHAVE_LIBLMS -I$tryliblmsdir/include/hss"
1181-
LDFLAGS="$AM_LDFLAGS $LDFLAGS -L$tryliblmsdir/lib"
1182-
1183-
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <hss.h>]], [[ param_set_t lm_type; param_set_t lm_ots_type; hss_get_public_key_len(4, &lm_type, &lm_ots_type); ]])], [ liblms_linked=yes ],[ liblms_linked=no ])
11841232
else
11851233
AC_MSG_ERROR([liblms isn't found.
11861234
If it's already installed, specify its path using --with-liblms=/dir/])
@@ -1203,47 +1251,6 @@ AC_ARG_WITH([liblms],
12031251
]
12041252
)
12051253

1206-
1207-
# LMS
1208-
AC_ARG_ENABLE([lms],
1209-
[AS_HELP_STRING([--enable-lms],[Enable stateful LMS/HSS signatures (default: disabled)])],
1210-
[ ENABLED_LMS=$enableval ],
1211-
[ ENABLED_LMS=no ]
1212-
)
1213-
1214-
ENABLED_WC_LMS=no
1215-
for v in `echo $ENABLED_LMS | tr "," " "`
1216-
do
1217-
case $v in
1218-
yes)
1219-
;;
1220-
no)
1221-
;;
1222-
wolfssl)
1223-
ENABLED_WC_LMS=yes
1224-
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_WC_LMS"
1225-
;;
1226-
*)
1227-
AC_MSG_ERROR([Invalid choice for LMS []: $ENABLED_LMS.])
1228-
break;;
1229-
esac
1230-
done
1231-
1232-
if test "$ENABLED_LMS" != "no"
1233-
then
1234-
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_HAVE_LMS"
1235-
1236-
if test "$ENABLED_WC_LMS" = "no";
1237-
then
1238-
# Default is to use hash-sigs LMS lib. Make sure it's enabled.
1239-
if test "$ENABLED_LIBLMS" = "no"; then
1240-
AC_MSG_ERROR([The default implementation for LMS is the hash-sigs LMS/HSS lib.
1241-
Please use --with-liblms.])
1242-
fi
1243-
fi
1244-
fi
1245-
1246-
12471254
# SINGLE THREADED
12481255
AC_ARG_ENABLE([singlethreaded],
12491256
[AS_HELP_STRING([--enable-singlethreaded],[Enable wolfSSL single threaded (default: disabled)])],

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-
#ifdef WOLFSSL_HAVE_LMS
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)
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) */
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-
#ifdef WOLFSSL_HAVE_LMS
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
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-
#ifdef WOLFSSL_HAVE_LMS
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 /* ifdef WOLFSSL_HAVE_LMS */
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)
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) */
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)
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) */
10646+
#endif
1064710647
#endif
1064810648
if (!optMatched) {
1064910649
printf("Option not recognized: %s\n", argv[1]);

0 commit comments

Comments
 (0)