Skip to content

Commit a026d84

Browse files
Merge pull request #6564 from philljj/add_lms_hooks
Add LMS/HSS wolfCrypt hooks.
2 parents 5171388 + a747e77 commit a026d84

12 files changed

Lines changed: 1813 additions & 1 deletion

File tree

INSTALL

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,58 @@
254254
The wolfssl port in vcpkg is kept up to date by wolfSSL.
255255

256256
We also have vcpkg ports for wolftpm, wolfmqtt and curl.
257+
258+
17. Building with hash-sigs lib for LMS/HSS support [EXPERIMENTAL]
259+
260+
Using LMS/HSS requires that the hash-sigs lib has been built on
261+
your system. We support hash-sigs lib at this git commit:
262+
b0631b8891295bf2929e68761205337b7c031726
263+
At the time of writing this, this is the HEAD of the master
264+
branch of the hash-sigs project.
265+
266+
Currently the hash-sigs project only builds static libraries:
267+
- hss_lib.a: a single-threaded static lib.
268+
- hss_lib_thread.a: a multi-threaded static lib.
269+
270+
The multi-threaded version will mainly have speedups for key
271+
generation and signing.
272+
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.
277+
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.
281+
282+
How to get and build the hash-sigs library:
283+
$ mkdir ~/hash_sigs
284+
$ cd ~/hash_sigs
285+
$ git clone https://github.com/cisco/hash-sigs.git src
286+
$ cd src
287+
$ git checkout b0631b8891295bf2929e68761205337b7c031726
288+
289+
In sha256.h, set USE_OPENSSL to 0:
290+
#define USE_OPENSSL 0
291+
292+
To build the single-threaded version:
293+
$ make hss_lib.a
294+
$ ls *.a
295+
hss_lib.a
296+
297+
To build multi-threaded:
298+
$ make hss_lib_thread.a
299+
$ ls *.a
300+
hss_lib_thread.a
301+
302+
Build wolfSSL with
303+
$ ./configure \
304+
--enable-static \
305+
--disable-shared \
306+
--enable-lms=yes \
307+
--with-liblms=<path to dir containing hss_lib_thread.a>
308+
$ make
309+
310+
Run the benchmark against LMS/HSS with:
311+
$ ./wolfcrypt/benchmark/benchmark -lms_hss

configure.ac

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,109 @@ then
11441144
fi
11451145

11461146

1147+
# liblms
1148+
# Get the path to the hash-sigs LMS HSS lib.
1149+
ENABLED_LIBLMS="no"
1150+
tryliblmsdir=""
1151+
AC_ARG_WITH([liblms],
1152+
[AS_HELP_STRING([--with-liblms=PATH],[PATH to hash-sigs LMS/HSS install (default /usr/local) EXPERIMENTAL!])],
1153+
[
1154+
AC_MSG_CHECKING([for liblms])
1155+
1156+
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 ])
1157+
1158+
if test "x$liblms_linked" = "xno" ; then
1159+
if test "x$withval" != "xno" ; then
1160+
tryliblmsdir=$withval
1161+
fi
1162+
if test "x$withval" = "xyes" ; then
1163+
tryliblmsdir="/usr/local"
1164+
fi
1165+
1166+
# 1. By default use the hash-sigs single-threaded static library.
1167+
# 2. If 1 not found, then use the multi-threaded static lib.
1168+
# 3. If 2 not found, then use the multi-threaded dynamic lib.
1169+
if test -e $tryliblmsdir/hss_lib.a; then
1170+
CPPFLAGS="$AM_CPPFLAGS -DHAVE_LIBLMS -I$tryliblmsdir"
1171+
LIB_STATIC_ADD="$LIB_STATIC_ADD $tryliblmsdir/hss_lib.a"
1172+
enable_shared=no
1173+
enable_static=yes
1174+
liblms_linked=yes
1175+
elif test -e $tryliblmsdir/hss_lib_thread.a; then
1176+
CPPFLAGS="$AM_CPPFLAGS -DHAVE_LIBLMS -I$tryliblmsdir"
1177+
LIB_STATIC_ADD="$LIB_STATIC_ADD $tryliblmsdir/hss_lib_thread.a"
1178+
enable_shared=no
1179+
enable_static=yes
1180+
liblms_linked=yes
1181+
elif test -e $tryliblmsdir/lib/libhss.so; then
1182+
LIBS="$LIBS -lhss"
1183+
CPPFLAGS="$AM_CPPFLAGS -DHAVE_LIBLMS -I$tryliblmsdir/include/hss"
1184+
LDFLAGS="$AM_LDFLAGS $LDFLAGS -L$tryliblmsdir/lib"
1185+
1186+
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 ])
1187+
else
1188+
AC_MSG_ERROR([liblms isn't found.
1189+
If it's already installed, specify its path using --with-liblms=/dir/])
1190+
fi
1191+
1192+
if test "x$liblms_linked" = "xno" ; then
1193+
AC_MSG_ERROR([liblms isn't found.
1194+
If it's already installed, specify its path using --with-liblms=/dir/])
1195+
fi
1196+
1197+
AC_MSG_RESULT([yes])
1198+
AM_CPPFLAGS="$CPPFLAGS"
1199+
AM_LDFLAGS="$LDFLAGS"
1200+
else
1201+
AC_MSG_RESULT([yes])
1202+
fi
1203+
1204+
AM_CFLAGS="$AM_CFLAGS -DHAVE_LIBLMS"
1205+
ENABLED_LIBLMS="yes"
1206+
]
1207+
)
1208+
1209+
1210+
# LMS
1211+
AC_ARG_ENABLE([lms],
1212+
[AS_HELP_STRING([--enable-lms],[Enable stateful LMS/HSS signatures (default: disabled)])],
1213+
[ ENABLED_LMS=$enableval ],
1214+
[ ENABLED_LMS=no ]
1215+
)
1216+
1217+
ENABLED_WC_LMS=no
1218+
for v in `echo $ENABLED_LMS | tr "," " "`
1219+
do
1220+
case $v in
1221+
yes)
1222+
;;
1223+
no)
1224+
;;
1225+
wolfssl)
1226+
ENABLED_WC_LMS=yes
1227+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_WC_LMS"
1228+
;;
1229+
*)
1230+
AC_MSG_ERROR([Invalid choice for LMS []: $ENABLED_LMS.])
1231+
break;;
1232+
esac
1233+
done
1234+
1235+
if test "$ENABLED_LMS" != "no"
1236+
then
1237+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_HAVE_LMS"
1238+
1239+
if test "$ENABLED_WC_LMS" = "no";
1240+
then
1241+
# Default is to use hash-sigs LMS lib. Make sure it's enabled.
1242+
if test "$ENABLED_LIBLMS" = "no"; then
1243+
AC_MSG_ERROR([The default implementation for LMS is the hash-sigs LMS/HSS lib.
1244+
Please use --with-liblms.])
1245+
fi
1246+
fi
1247+
fi
1248+
1249+
11471250
# SINGLE THREADED
11481251
AC_ARG_ENABLE([singlethreaded],
11491252
[AS_HELP_STRING([--enable-singlethreaded],[Enable wolfSSL single threaded (default: disabled)])],
@@ -8753,6 +8856,7 @@ AM_CONDITIONAL([BUILD_FE448], [test "x$ENABLED_FE448" = "xyes" || test "x$ENABLE
87538856
AM_CONDITIONAL([BUILD_GE448], [test "x$ENABLED_GE448" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
87548857
AM_CONDITIONAL([BUILD_CURVE448],[test "x$ENABLED_CURVE448" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
87558858
AM_CONDITIONAL([BUILD_CURVE448_SMALL],[test "x$ENABLED_CURVE448_SMALL" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
8859+
AM_CONDITIONAL([BUILD_WC_LMS],[test "x$ENABLED_WC_LMS" != "xno" || test "x$ENABLED_USERSETTINGS" = "xyes"])
87568860
AM_CONDITIONAL([BUILD_WC_KYBER],[test "x$ENABLED_WC_KYBER" != "xno" || test "x$ENABLED_USERSETTINGS" = "xyes"])
87578861
AM_CONDITIONAL([BUILD_ECCSI],[test "x$ENABLED_ECCSI" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
87588862
AM_CONDITIONAL([BUILD_SAKKE],[test "x$ENABLED_SAKKE" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
@@ -8792,6 +8896,7 @@ AM_CONDITIONAL([BUILD_CRL],[test "x$ENABLED_CRL" != "xno" || test "x$ENABLED_USE
87928896
AM_CONDITIONAL([BUILD_CRL_MONITOR],[test "x$ENABLED_CRL_MONITOR" = "xyes"])
87938897
AM_CONDITIONAL([BUILD_USER_RSA],[test "x$ENABLED_USER_RSA" = "xyes"] )
87948898
AM_CONDITIONAL([BUILD_USER_CRYPTO],[test "x$ENABLED_USER_CRYPTO" = "xyes"])
8899+
AM_CONDITIONAL([BUILD_LIBLMS],[test "x$ENABLED_LIBLMS" = "xyes"])
87958900
AM_CONDITIONAL([BUILD_LIBOQS],[test "x$ENABLED_LIBOQS" = "xyes"])
87968901
AM_CONDITIONAL([BUILD_WNR],[test "x$ENABLED_WNR" = "xyes"])
87978902
AM_CONDITIONAL([BUILD_SRP],[test "x$ENABLED_SRP" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
@@ -9242,6 +9347,8 @@ echo " * ED25519 streaming: $ENABLED_ED25519_STREAM"
92429347
echo " * CURVE448: $ENABLED_CURVE448"
92439348
echo " * ED448: $ENABLED_ED448"
92449349
echo " * ED448 streaming: $ENABLED_ED448_STREAM"
9350+
echo " * LMS: $ENABLED_LMS"
9351+
echo " * LMS wolfSSL impl: $ENABLED_WC_LMS"
92459352
echo " * KYBER: $ENABLED_KYBER"
92469353
echo " * KYBER wolfSSL impl: $ENABLED_WC_KYBER"
92479354
echo " * ECCSI $ENABLED_ECCSI"
@@ -9297,6 +9404,7 @@ echo " * Persistent session cache: $ENABLED_SAVESESSION"
92979404
echo " * Persistent cert cache: $ENABLED_SAVECERT"
92989405
echo " * Atomic User Record Layer: $ENABLED_ATOMICUSER"
92999406
echo " * Public Key Callbacks: $ENABLED_PKCALLBACKS"
9407+
echo " * liblms: $ENABLED_LIBLMS"
93009408
echo " * liboqs: $ENABLED_LIBOQS"
93019409
echo " * Whitewood netRandom: $ENABLED_WNR"
93029410
echo " * Server Name Indication: $ENABLED_SNI"

src/include.am

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,10 @@ endif
655655
endif
656656
endif
657657

658+
if BUILD_WC_LMS
659+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/wc_lms.c
660+
endif
661+
658662
if BUILD_CURVE25519
659663
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/curve25519.c
660664
endif
@@ -734,6 +738,10 @@ src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/sphincs.c
734738
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/ext_kyber.c
735739
endif
736740

741+
if BUILD_LIBLMS
742+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/ext_lms.c
743+
endif
744+
737745
if BUILD_LIBZ
738746
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/compress.c
739747
endif

0 commit comments

Comments
 (0)