Skip to content

Commit f32c6a0

Browse files
committed
XMSS/XMSSMT hooks support: fix build.
1 parent 33d4b33 commit f32c6a0

5 files changed

Lines changed: 110 additions & 13 deletions

File tree

INSTALL

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,16 @@ We also have vcpkg ports for wolftpm, wolfmqtt and curl.
401401
The patch may be found in the wolfssl-examples repo here:
402402
pq/stateful_hash_sig/0001-Patch-to-support-xmss-reference-integration.patch
403403

404+
To build patched xmss-reference:
405+
$ make xmss_lib.a
406+
407+
To build verify-only patched xmss-reference:
408+
$ make xmss_verify_lib.a
409+
404410
Note that this patch adds wolfCrypt SHA256 hashing to xmss-reference, and
405411
thus benefits from all the same asm speedups as wolfCrypt SHA hashing.
406412
Depending on architecture you may build with --enable-intelasm, or
407-
and --enable-armasm, and see 30-50% speedups in XMSS/XMSS^MT.
413+
and --enable-armasm, and see 30-40% speedups in XMSS/XMSS^MT.
408414

409415
For full keygen, signing, verifying, and benchmarking support, build
410416
wolfSSL with:

configure.ac

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,10 +1201,32 @@ AC_ARG_WITH([libxmss],
12011201
AC_MSG_ERROR([libxmss isn't found.
12021202
If it's already installed, specify its path using --with-libxmss=/dir/])
12031203
fi
1204+
if test "$XMSS_VERIFY_ONLY" = "yes"; then
1205+
if test -e $trylibxmssdir/xmss_verify_lib.a; then
1206+
CPPFLAGS="$AM_CPPFLAGS -DHAVE_LIBXMSS -I$trylibxmssdir"
1207+
LIB_STATIC_ADD="$LIB_STATIC_ADD $trylibxmssdir/xmss_verify_lib.a"
1208+
enable_shared=no
1209+
enable_static=yes
1210+
libxmss_linked=yes
1211+
else
1212+
AC_MSG_ERROR([xmss_verify_lib.a isn't found.
1213+
If it's already installed, specify its path using --with-libxmss=/dir/])
1214+
fi
1215+
elif test -e $trylibxmssdir/xmss_lib.a; then
1216+
CPPFLAGS="$AM_CPPFLAGS -DHAVE_LIBXMSS -I$trylibxmssdir"
1217+
LIB_STATIC_ADD="$LIB_STATIC_ADD $trylibxmssdir/xmss_lib.a"
1218+
enable_shared=no
1219+
enable_static=yes
1220+
libxmss_linked=yes
1221+
else
1222+
AC_MSG_ERROR([libxmss isn't found.
1223+
If it's already installed, specify its path using --with-libxmss=/dir/])
1224+
fi
12041225
12051226
XMSS_ROOT=$trylibxmssdir
12061227
12071228
AC_MSG_RESULT([yes])
1229+
AM_CPPFLAGS="$CPPFLAGS"
12081230
12091231
AM_CFLAGS="$AM_CFLAGS -DHAVE_LIBXMSS -I$trylibxmssdir"
12101232
ENABLED_LIBXMSS="yes"
@@ -1213,7 +1235,6 @@ AC_ARG_WITH([libxmss],
12131235
[XMSS_ROOT=""]
12141236
)
12151237

1216-
12171238
# LMS
12181239
AC_ARG_ENABLE([lms],
12191240
[AS_HELP_STRING([--enable-lms],[Enable stateful LMS/HSS signatures (default: disabled)])],
@@ -9032,6 +9053,7 @@ AM_CONDITIONAL([BUILD_GE448], [test "x$ENABLED_GE448" = "xyes" || test "x$ENABLE
90329053
AM_CONDITIONAL([BUILD_CURVE448],[test "x$ENABLED_CURVE448" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
90339054
AM_CONDITIONAL([BUILD_CURVE448_SMALL],[test "x$ENABLED_CURVE448_SMALL" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
90349055
AM_CONDITIONAL([BUILD_WC_LMS],[test "x$ENABLED_WC_LMS" != "xno" || test "x$ENABLED_USERSETTINGS" = "xyes"])
9056+
AM_CONDITIONAL([BUILD_WC_XMSS],[test "x$ENABLED_WC_XMSS" != "xno" || test "x$ENABLED_USERSETTINGS" = "xyes"])
90359057
AM_CONDITIONAL([BUILD_WC_KYBER],[test "x$ENABLED_WC_KYBER" != "xno" || test "x$ENABLED_USERSETTINGS" = "xyes"])
90369058
AM_CONDITIONAL([BUILD_ECCSI],[test "x$ENABLED_ECCSI" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
90379059
AM_CONDITIONAL([BUILD_SAKKE],[test "x$ENABLED_SAKKE" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])

src/include.am

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,10 @@ if BUILD_WC_LMS
702702
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/wc_lms.c
703703
endif
704704

705+
if BUILD_WC_XMSS
706+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/wc_xmss.c
707+
endif
708+
705709
if BUILD_CURVE25519
706710
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/curve25519.c
707711
endif
@@ -809,14 +813,6 @@ endif
809813

810814
if BUILD_LIBXMSS
811815
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/ext_xmss.c
812-
src_libwolfssl@LIBSUFFIX@_la_SOURCES += $(XMSS_ROOT)/params.c
813-
src_libwolfssl@LIBSUFFIX@_la_SOURCES += $(XMSS_ROOT)/thash.c
814-
src_libwolfssl@LIBSUFFIX@_la_SOURCES += $(XMSS_ROOT)/hash_address.c
815-
src_libwolfssl@LIBSUFFIX@_la_SOURCES += $(XMSS_ROOT)/wots.c
816-
src_libwolfssl@LIBSUFFIX@_la_SOURCES += $(XMSS_ROOT)/xmss.c
817-
src_libwolfssl@LIBSUFFIX@_la_SOURCES += $(XMSS_ROOT)/xmss_core_fast.c
818-
src_libwolfssl@LIBSUFFIX@_la_SOURCES += $(XMSS_ROOT)/xmss_commons.c
819-
src_libwolfssl@LIBSUFFIX@_la_SOURCES += $(XMSS_ROOT)/utils.c
820816
endif
821817

822818
if BUILD_LIBZ

wolfcrypt/src/ext_xmss.c

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <wolfssl/wolfcrypt/settings.h>
2727
#include <wolfssl/wolfcrypt/error-crypt.h>
2828
#include <wolfssl/wolfcrypt/logging.h>
29+
#include <wolfssl/wolfcrypt/sha256.h>
2930

3031
#ifdef WOLFSSL_HAVE_XMSS
3132
#include <wolfssl/wolfcrypt/ext_xmss.h>
@@ -37,6 +38,63 @@
3738
#include <wolfcrypt/src/misc.c>
3839
#endif
3940

41+
#include <xmss_callbacks.h>
42+
43+
#ifndef WOLFSSL_XMSS_VERIFY_ONLY
44+
static THREAD_LS_T WC_RNG * xmssRng = NULL;
45+
46+
/* RNG callback used by xmss.
47+
* */
48+
static int rng_cb(void * output, size_t length)
49+
{
50+
int ret = 0;
51+
52+
if (output == NULL || xmssRng == NULL) {
53+
return -1;
54+
}
55+
56+
if (length == 0) {
57+
return 0;
58+
}
59+
60+
ret = wc_RNG_GenerateBlock(xmssRng, output, (word32) length);
61+
62+
if (ret) {
63+
WOLFSSL_MSG("error: xmss rng_cb failed");
64+
return -1;
65+
}
66+
67+
return 0;
68+
}
69+
#endif /* ifndef WOLFSSL_XMSS_VERIFY_ONLY */
70+
71+
/* SHA256 callback used by xmss.
72+
* */
73+
static int sha256_cb(const unsigned char *in, unsigned long long inlen,
74+
unsigned char *out)
75+
{
76+
wc_Sha256 sha;
77+
78+
if (wc_InitSha256_ex(&sha, NULL, INVALID_DEVID) != 0) {
79+
WOLFSSL_MSG("SHA256 Init failed");
80+
return -1;
81+
}
82+
83+
if (wc_Sha256Update(&sha, in, (word32) inlen) != 0) {
84+
WOLFSSL_MSG("SHA256 Update failed");
85+
return -1;
86+
}
87+
88+
if (wc_Sha256Final(&sha, out) != 0) {
89+
WOLFSSL_MSG("SHA256 Final failed");
90+
wc_Sha256Free(&sha);
91+
return -1;
92+
}
93+
wc_Sha256Free(&sha);
94+
95+
return 0;
96+
}
97+
4098
/* Init an Xmss key.
4199
*
42100
* Call this before setting the parms of an Xmss key.
@@ -119,6 +177,20 @@ static int wc_XmssKey_SetOid(XmssKey * key, uint32_t oid, int is_xmssmt)
119177
return -1;
120178
}
121179

180+
ret = xmss_set_sha_cb(sha256_cb);
181+
if (ret != 0) {
182+
WOLFSSL_MSG("error: xmss_set_sha_cb failed");
183+
return -1;
184+
}
185+
186+
#ifndef WOLFSSL_XMSS_VERIFY_ONLY
187+
ret = xmss_set_rng_cb(rng_cb);
188+
if (ret != 0) {
189+
WOLFSSL_MSG("error: xmss_set_rng_cb failed");
190+
return -1;
191+
}
192+
#endif
193+
122194
key->oid = oid;
123195
key->is_xmssmt = is_xmssmt;
124196
key->state = WC_XMSS_STATE_PARMSET;
@@ -401,13 +473,15 @@ int wc_XmssKey_MakeKey(XmssKey* key, WC_RNG * rng)
401473
return ret;
402474
}
403475

476+
xmssRng = rng;
477+
404478
/* Finally make the secret public key pair. Immediately write it to NV
405479
* storage and then clear from memory. */
406480
if (key->is_xmssmt) {
407-
ret = xmssmt_keypair(key->pk, key->sk, key->oid, rng);
481+
ret = xmssmt_keypair(key->pk, key->sk, key->oid);
408482
}
409483
else {
410-
ret = xmss_keypair(key->pk, key->sk, key->oid, rng);
484+
ret = xmss_keypair(key->pk, key->sk, key->oid);
411485
}
412486

413487
if (ret == 0) {

wolfssl/wolfcrypt/xmss.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ WOLFSSL_API int wc_XmssKey_ImportPubRaw(XmssKey * key, const byte * in,
144144
word32 inLen);
145145
WOLFSSL_API int wc_XmssKey_Verify(XmssKey * key, const byte * sig, word32 sigSz,
146146
const byte * msg, int msgSz);
147-
WOLFSSL_API const char * wc_XmssKey_RcToStr(enum wc_XmssRc lmsRc);
148147
#ifdef __cplusplus
149148
} /* extern "C" */
150149
#endif

0 commit comments

Comments
 (0)