Skip to content

Commit 277a2dd

Browse files
committed
Update xmss example.
1 parent 5a7c327 commit 277a2dd

3 files changed

Lines changed: 32 additions & 11 deletions

File tree

pq/stateful_hash_sig/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# PQ Stateful Hash-Based Signature Examples Makefile
2+
#
3+
# XMSS_INC, XMSS_LIB, and WOLF_STATIC_LIB are only required if
4+
# building with --with-libxmss.
5+
#
26
CC = gcc
37
LIB_PATH = /usr/local
48
HSS_INC =
@@ -35,7 +39,10 @@ lms_example: lms_example.c
3539
$(CC) -o $@ $< $(CFLAGS) -I$(HSS_INC) $(LIBS) $(WOLF_STATIC_LIB) $(HSS_LIB)
3640

3741
xmss_example: xmss_example.c
42+
# If building with --enable-xmss=wolfssl:
3843
$(CC) -o $@ $< $(CFLAGS) -I$(XMSS_INC) $(LIBS) $(WOLF_STATIC_LIB) $(XMSS_LIB)
44+
# If building with --enable-xmss --with-libxmss=<path>:
45+
# $(CC) -o $@ $< $(CFLAGS) $(LIBS) $(WOLF_DYN_LIB)
3946

4047
xmss_example_verifyonly: xmss_example.c
4148
$(CC) -o $@ $< $(CFLAGS) -I$(XMSS_INC) -DWOLFSSL_XMSS_VERIFY_ONLY $(LIBS) $(WOLF_STATIC_LIB) $(XMSS_LIB)

pq/stateful_hash_sig/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ This directory contains:
88

99
- An example that uses wolfCrypt XMSS/XMSS^MT hooks to sign and verify a message
1010
with a configurable XMSS/XMSS^MT parameter string. Requires wolfssl with `--enable-xmss=yes`
11-
and `--with-libxmss=<path to patched xmss-reference install>`.
11+
and `--with-libxmss=<path to patched xmss-reference install>`, or wolfssl
12+
with `--enable-xmss=wolfssl`.
1213

1314
# Prerequisites
1415

@@ -18,8 +19,9 @@ in the wolfSSL repo's INSTALL file.
1819

1920
https://github.com/wolfSSL/wolfssl/blob/master/INSTALL
2021

21-
The XMSS/XMSS^MT example requires that the xmss-reference repository has been
22-
cloned, patched, and built. Please see item 20 in the wolfSSL repo's INSTALL file.
22+
If building with `--with-libxmss=<path>`, the XMSS/XMSS^MT example requires
23+
that the xmss-reference repository has been cloned, patched, and built. Please
24+
see item 20 in the wolfSSL repo's INSTALL file.
2325

2426
The patch to use is `0001-Patch-to-support-wolfSSL-xmss-reference-integration.patch` from this XMSS/XMSS^MT example.
2527
This patch includes an addendum readme, `patch_readme.md`, that lists all changes made and explains their rationale.
@@ -79,7 +81,8 @@ description:
7981

8082
# Building the XMSS/XMSS^MT example
8183

82-
Configure the Makefile to point to your xmss install:
84+
If building with `--with-libxmss=<path>`, configure the Makefile to point to
85+
your xmss install:
8386

8487
```
8588
XMSS_INC = <path to patched xmss install>

pq/stateful_hash_sig/xmss_example.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@
2424
#include <wolfssl/options.h>
2525
#include <wolfssl/wolfcrypt/error-crypt.h>
2626

27-
#ifdef HAVE_LIBXMSS
27+
#ifdef WOLFSSL_HAVE_XMSS
2828

2929
#include <wolfssl/wolfcrypt/xmss.h>
30-
#include <wolfssl/wolfcrypt/ext_xmss.h>
30+
#ifdef HAVE_LIBXMSS
31+
#include <wolfssl/wolfcrypt/ext_xmss.h>
32+
#else
33+
#include <wolfssl/wolfcrypt/wc_xmss.h>
34+
#endif
3135

32-
static void dump_hex(const char * what, const uint8_t * buf, size_t len);
36+
static void dump_hex(const char * what, const byte * buf, size_t len);
3337
static void print_usage(void);
3438
#if !defined WOLFSSL_XMSS_VERIFY_ONLY
3539
static int do_xmss_example(const char * params, size_t sigs_to_do);
@@ -304,6 +308,13 @@ do_xmss_example(const char * params,
304308

305309
printf("signing and verifying %zu signatures...\n", sigs_to_do);
306310
for (size_t i = 0; i < sigs_to_do; ++i) {
311+
ret = wc_XmssKey_SigsLeft(&signingKey);
312+
313+
if (ret <= 0) {
314+
fprintf(stderr, "info: %zu: wc_XmssKey_SigsLeft returned %d\n", i, ret);
315+
break;
316+
}
317+
307318
ret = wc_XmssKey_Sign(&signingKey, sig, &sigSz,(byte *) msg,
308319
strlen(msg));
309320
if (ret) {
@@ -524,9 +535,9 @@ read_file(byte * data,
524535
#endif /* if !defined WOLFSSL_XMSS_VERIFY_ONLY */
525536

526537
static void
527-
dump_hex(const char * what,
528-
const uint8_t * buf,
529-
size_t len)
538+
dump_hex(const char * what,
539+
const byte * buf,
540+
size_t len)
530541
{
531542
printf("%s\n", what);
532543
for (size_t i = 0; i < len; ++i) {
@@ -547,7 +558,7 @@ dump_hex(const char * what,
547558
#else
548559

549560
int main(int argc, char** argv) {
550-
printf("This requires the --with-libxmss flag.\n");
561+
printf("This requires --enable-xmss.\n");
551562
return 0;
552563
}
553564
#endif /* WITH_LIBXMSS */

0 commit comments

Comments
 (0)