Skip to content

Commit 946e6f3

Browse files
committed
Update LMS and XMSS examples.
1 parent 2326995 commit 946e6f3

4 files changed

Lines changed: 139 additions & 114 deletions

File tree

pq/stateful_hash_sig/Makefile

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
# PQ Stateful Hash-Based Signature Examples Makefile
22
#
3-
# XMSS_INC, XMSS_LIB, and WOLF_STATIC_LIB are only required if
4-
# building with --with-libxmss.
3+
# HSS_INC, HSS_LIB, XMSS_INC, XMSS_LIB, and WOLF_STATIC_LIB are only
4+
# required if building with --with-libxmss or --with-liblms.
55
#
66
CC = gcc
77
WOLFSSL_INSTALL_DIR = /usr/local
8-
HSS_INC =
9-
XMSS_INC =
108
CFLAGS = -Wall -I$(WOLFSSL_INSTALL_DIR)/include
119
LIBS = -L$(WOLFSSL_INSTALL_DIR)/lib -lm
1210

1311
# option variables
1412
WOLF_DYN_LIB = -lwolfssl
1513
WOLF_STATIC_LIB = $(WOLFSSL_INSTALL_DIR)/lib/libwolfssl.a
16-
HSS_LIB =
17-
XMSS_LIB =
14+
15+
# These are only needed if building with the external
16+
# integration (ext_lms, ext_xmss).
17+
# HSS_INC = path to hash-sigs src dir
18+
# XMSS_INC = path to xmss-reference src dir
19+
# HSS_LIB = path to hash-sigs hss_lib.a
20+
# XMSS_LIB = path to xmss-reference xmss_lib.a
21+
22+
# Options
1823
DEBUG_FLAGS = -g -DDEBUG
1924
DEBUG_INC_PATHS = -MD
2025
OPTIMIZE = -Os
21-
22-
# Options
2326
#CFLAGS+=$(DEBUG_FLAGS)
2427
#CFLAGS+=$(OPTIMIZE)
2528

@@ -36,19 +39,18 @@ debug: all
3639

3740
# build template
3841
lms_example: lms_example.c
39-
$(CC) -o $@ $< $(CFLAGS) -I$(HSS_INC) $(LIBS) $(WOLF_STATIC_LIB) $(HSS_LIB)
42+
# If building with wc_lms (--enable-lms):
43+
$(CC) -o $@ $< $(CFLAGS) -DWOLFSSL_WC_LMS $(LIBS) $(WOLF_DYN_LIB)
44+
# If building with ext_lms (--enable-lms --with-liblms=<path>):
45+
# $(CC) -o $@ $< $(CFLAGS) -I$(HSS_INC) $(LIBS) $(WOLF_STATIC_LIB) $(HSS_LIB)
4046

4147
xmss_example: xmss_example.c
42-
# If building with --enable-xmss=wolfssl:
43-
$(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)
46-
47-
xmss_example_verifyonly: xmss_example.c
48-
$(CC) -o $@ $< $(CFLAGS) -I$(XMSS_INC) -DWOLFSSL_XMSS_VERIFY_ONLY $(LIBS) $(WOLF_STATIC_LIB) $(XMSS_LIB)
48+
# If building with wc_xmss (--enable-xmss):
49+
$(CC) -o $@ $< $(CFLAGS) -DWOLFSSL_WC_XMSS $(LIBS) $(WOLF_DYN_LIB)
50+
# If building with ext_xmss (--enable-xmss --with-libxmss=<path>):
51+
# $(CC) -o $@ $< $(CFLAGS) -I$(XMSS_INC) $(LIBS) $(WOLF_STATIC_LIB) $(XMSS_LIB)
4952

5053
clean:
5154
rm -f $(TARGETS)
52-
rm -f xmss_example_verifyonly
5355
rm -f lms_example.key
5456
rm -f xmss_example.key

pq/stateful_hash_sig/README.md

Lines changed: 103 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,22 @@
22

33
This directory contains:
44

5-
- A simple example that uses wolfCrypt LMS/HSS hooks to sign and verify a message
6-
with configurable LMS/HSS parameters. Requires wolfssl with `--enable-lms=yes`
7-
and `--with-liblms=<path to hash-sigs install>`.
5+
- An example that uses wolfCrypt LMS/HSS to sign and verify a
6+
message with configurable LMS/HSS parameters. Requires wolfssl with
7+
`--enable-lms`.
88

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

14-
# Prerequisites
13+
By default these examples use the wolfCrypt LMS and XMSS implementations
14+
(`wc_lms.c`, `wc_lms_impl.c`, `wc_xmss.c`, `wc_xmss_impl.c`), which are more
15+
performant and configurable. Also, these implementations benefit significantly
16+
from `--enable-intelasm` and `--enable-armasm`.
1517

16-
The LMS/HSS sign verify example requires that hash-sigs has been built, and
17-
wolfSSL has been built with LMS/HSS support enabled. Please see Item 17
18-
in the wolfSSL repo's INSTALL file.
19-
20-
https://github.com/wolfSSL/wolfssl/blob/master/INSTALL
21-
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.
25-
26-
The patch to use is `0001-Patch-to-support-wolfSSL-xmss-reference-integration.patch` from this XMSS/XMSS^MT example.
27-
This patch includes an addendum readme, `patch_readme.md`, that lists all changes made and explains their rationale.
28-
29-
# Building the LMS/HSS example
30-
31-
Configure the Makefile to point to your hash-sigs install:
32-
33-
```
34-
HSS_INC = <path to hss install>
35-
```
36-
37-
```
38-
HSS_LIB = <path to hss_lib_thread.a>
39-
```
40-
41-
Then build:
42-
43-
```
44-
$ make lms_example
45-
```
18+
If you want to use the old external integrations LMS/XMSS implementations
19+
(`ext_lms.c`, `ext_xmss.c`), see the section "Building the External Integration
20+
examples".
4621

4722
## Signing and Verifying a Message with LMS/HSS
4823

@@ -78,31 +53,6 @@ examples:
7853
description:
7954
...
8055
```
81-
82-
# Building the XMSS/XMSS^MT example
83-
84-
If building with `--with-libxmss=<path>`, configure the Makefile to point to
85-
your xmss install:
86-
87-
```
88-
XMSS_INC = <path to patched xmss install>
89-
```
90-
91-
```
92-
XMSS_LIB = <path to xmss_lib.a or xmss_verify_lib.a>
93-
```
94-
95-
Then build:
96-
97-
```
98-
$ make xmss_example
99-
```
100-
101-
Build the verify-only example with
102-
```
103-
$ make xmss_example_verifyonly
104-
```
105-
10656
## Signing and Verifying a Message with XMSS/XMSS^MT
10757

10858
To see the help and usage, run the program without options:
@@ -144,64 +94,76 @@ number of levels in the hyper-tree. The number of signatures available
14494
is `N = 2 ** (h)`.
14595

14696
The main contributor to key generation time is the ratio `h/d`.
147-
Not surprisingly, be aware that `XMSS-SHA2_20_256`, and `XMSSMT-SHA2_60/3_256`, are particularly
148-
CPU intensive because of the large number of hash operations involved, and
149-
may take a long time. E.g. on an Intel i7 linux system these examples took
150-
approximately 24 min, and 1 hour, respectively.
97+
Not surprisingly, be aware that `XMSS-SHA2_20_256`, and `XMSSMT-SHA2_60/3_256`,
98+
are particularly CPU intensive because of the large number of hash operations
99+
involved, and may take a long time.
151100

152101
The other examples will be much faster.
153102

154103
An interesting facet of XMSS/XMSS^MT is that the private key format
155-
and size is implementation specific. The wolfSSL XMSS/XMSS^MT hooks
156-
feature uses the "fast" implementation from xmss-reference, which
157-
has larger private key sizes.
104+
and size is implementation specific. The wolfSSL XMSS/XMSS^MT default
105+
implementation has larger private key sizes for greater signing
106+
performance.
158107

159-
For example:
108+
For example this is obtained with the default `-enable-xmss` with
109+
`--enable-intelasm` (on an Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz):
160110

161111
```
162-
$ ./xmss_example "XMSSMT-SHA2_20/2_256" 200
112+
$time ./xmss_example "XMSSMT-SHA2_20/2_256" 200
163113
using parameters: XMSSMT-SHA2_20/2_256
164114
signature length: 4963
165-
priv key length: 6002
115+
priv key length: 5780
166116
pub key length: 68
117+
making key with XMSSMT-SHA2_20/2_256 parameters...
167118
...done!
168119
signing and verifying 200 signatures...
169120
...done!
170121
finished
171122
123+
real 0m2.115s
124+
user 0m2.104s
125+
sys 0m0.007s
172126
```
173127

128+
Versus the same with `--enable-xmss=small` instead:
129+
174130
```
175-
$ ./xmss_example "XMSSMT-SHA2_40/4_256" 200
176-
using parameters: XMSSMT-SHA2_40/4_256
177-
signature length: 9893
178-
priv key length: 15256
131+
$time ./xmss_example "XMSSMT-SHA2_20/2_256" 200
132+
using parameters: XMSSMT-SHA2_20/2_256
133+
signature length: 4963
134+
priv key length: 135
179135
pub key length: 68
136+
making key with XMSSMT-SHA2_20/2_256 parameters...
180137
...done!
181138
signing and verifying 200 signatures...
182139
...done!
183140
finished
141+
142+
real 6m57.413s
143+
user 6m56.337s
144+
sys 0m0.058s
184145
```
185146

186147
## Using the verify-only XMSS/XMSS^MT example
187148

188-
The usage for the verify-only example is:
149+
The verify-only XMSS example requires that wolfSSL has been built with
150+
`--enable-xmss=verify-only`. The usage for the verify-only example is:
189151
```
190-
$ ./xmss_example_verifyonly
152+
$ ./xmss_example
191153
usage:
192-
./xmss_example_verifyonly <param string> <pub file> <sig file> <msg file>
154+
./xmss_example <param string> <pub file> <sig file> <msg file>
193155
194156
For simplicity message is assumed to be 32 bytes in size.
195157
196158
examples:
197-
./xmss_example_verifyonly XMSSMT-SHA2_20/4_256 xmss_pub.key xmss_sig.bin msg.bin
198-
./xmss_example_verifyonly XMSSMT-SHA2_60/6_256 xmss_pub.key xmss_sig.bin msg.bin
199-
./xmss_example_verifyonly XMSS-SHA2_10_256 xmss_pub.key xmss_sig.bin msg.bin
159+
./xmss_example XMSSMT-SHA2_20/4_256 xmss_pub.key xmss_sig.bin msg.bin
160+
./xmss_example XMSSMT-SHA2_60/6_256 xmss_pub.key xmss_sig.bin msg.bin
161+
./xmss_example XMSS-SHA2_10_256 xmss_pub.key xmss_sig.bin msg.bin
200162
```
201163

202164
An example:
203165
```
204-
$./xmss_example_verifyonly XMSSMT-SHA2_20/2_256 pk.bin sig.bin msg.bin
166+
$./xmss_example XMSSMT-SHA2_20/2_256 pk.bin sig.bin msg.bin
205167
using parameters: XMSSMT-SHA2_20/2_256
206168
pub:
207169
0x00 0x00 0x00 0x01 0x2B 0xC1 0xA4 0x8D
@@ -223,3 +185,60 @@ pub key length: 68
223185
Verify good!
224186
finished
225187
```
188+
189+
190+
# Building the External Integration examples
191+
192+
By default wolfssl uses the wolfCrypt LMS/XMSS implementations. However
193+
the previous external integrations are still supported.
194+
195+
If building with `--with-liblms=<path>`, the LMS/HSS example requires
196+
that hash-sigs has been built. Please see Item 17 in the wolfSSL repo's INSTALL file.
197+
198+
https://github.com/wolfSSL/wolfssl/blob/master/INSTALL
199+
200+
If building with `--with-libxmss=<path>`, the XMSS/XMSS^MT example requires
201+
that the xmss-reference repository has been cloned, patched, and built. Please
202+
see item 20 in the wolfSSL repo's INSTALL file.
203+
204+
The patch to use is `0001-Patch-to-support-wolfSSL-xmss-reference-integration.patch`
205+
from this XMSS/XMSS^MT example. This patch includes an addendum readme,
206+
`patch_readme.md`, that lists all changes made and explains their rationale.
207+
208+
## Building the external LMS/HSS example
209+
210+
If building with `--with-liblms=<path>`, configure the Makefile to point
211+
to your hash-sigs install:
212+
213+
```
214+
HSS_INC = <path to hss install>
215+
```
216+
217+
```
218+
HSS_LIB = <path to hss_lib_thread.a>
219+
```
220+
221+
Then build:
222+
223+
```
224+
$ make lms_example
225+
```
226+
227+
# Building the external XMSS/XMSS^MT example
228+
229+
If building with `--with-libxmss=<path>`, configure the Makefile to point to
230+
your xmss install:
231+
232+
```
233+
XMSS_INC = <path to patched xmss install>
234+
```
235+
236+
```
237+
XMSS_LIB = <path to xmss_lib.a or xmss_verify_lib.a>
238+
```
239+
240+
Then build:
241+
242+
```
243+
$ make xmss_example
244+
```

pq/stateful_hash_sig/lms_example.c

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

27-
#ifdef HAVE_LIBLMS
27+
#ifdef WOLFSSL_HAVE_LMS
2828

2929
#include <wolfssl/wolfcrypt/lms.h>
30-
#include <wolfssl/wolfcrypt/ext_lms.h>
30+
#ifdef HAVE_LIBLMS
31+
#include <wolfssl/wolfcrypt/ext_lms.h>
32+
#else
33+
#include <wolfssl/wolfcrypt/wc_lms.h>
34+
#endif
3135

3236
static void print_usage(void);
3337
static int write_key_file(const byte * priv, word32 privSz, void * context);
3438
static int read_key_file(byte * priv, word32 privSz, void * context);
3539
static int do_lms_example(int levels, int height, int winternitz,
3640
size_t sigs_to_do);
37-
static void dump_hex(const char * what, const uint8_t * buf, size_t len);
41+
static void dump_hex(const char * what, const byte * buf, size_t len);
3842

3943
static WC_RNG rng;
4044

@@ -374,9 +378,9 @@ do_lms_example(int levels,
374378
}
375379

376380
static void
377-
dump_hex(const char * what,
378-
const uint8_t * buf,
379-
size_t len)
381+
dump_hex(const char * what,
382+
const byte * buf,
383+
size_t len)
380384
{
381385
printf("%s\n", what);
382386
for (size_t i = 0; i < len; ++i) {
@@ -400,5 +404,5 @@ int main(int argc, char** argv) {
400404
printf("This requires the --with-liblms flag.\n");
401405
return 0;
402406
}
403-
#endif /* WITH_LILMS */
407+
#endif /* WOLFSSL_HAVE_LMS */
404408

pq/stateful_hash_sig/xmss_example.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static void print_usage(void);
3838
#if !defined WOLFSSL_XMSS_VERIFY_ONLY
3939
static int do_xmss_example(const char * params, size_t sigs_to_do);
4040
static enum wc_XmssRc write_key_file(const byte * priv, word32 privSz,
41-
void * context);
41+
void * context);
4242
static enum wc_XmssRc read_key_file(byte * priv, word32 privSz, void * context);
4343

4444

@@ -385,14 +385,14 @@ static void
385385
print_usage(void)
386386
{
387387
fprintf(stderr, "usage:\n");
388-
fprintf(stderr, " ./xmss_example_verifyonly <param string> <pub file> <sig file> <msg file>\n");
388+
fprintf(stderr, " ./xmss_example <param string> <pub file> <sig file> <msg file>\n");
389389
fprintf(stderr, "\n");
390390
fprintf(stderr, "For simplicity message is assumed to be 32 bytes in size.\n");
391391
fprintf(stderr, "\n");
392392
fprintf(stderr, "examples:\n");
393-
fprintf(stderr, " ./xmss_example_verifyonly XMSSMT-SHA2_20/4_256 xmss_pub.key xmss_sig.bin msg.bin\n");
394-
fprintf(stderr, " ./xmss_example_verifyonly XMSSMT-SHA2_60/6_256 xmss_pub.key xmss_sig.bin msg.bin\n");
395-
fprintf(stderr, " ./xmss_example_verifyonly XMSS-SHA2_10_256 xmss_pub.key xmss_sig.bin msg.bin\n");
393+
fprintf(stderr, " ./xmss_example XMSSMT-SHA2_20/4_256 xmss_pub.key xmss_sig.bin msg.bin\n");
394+
fprintf(stderr, " ./xmss_example XMSSMT-SHA2_60/6_256 xmss_pub.key xmss_sig.bin msg.bin\n");
395+
fprintf(stderr, " ./xmss_example XMSS-SHA2_10_256 xmss_pub.key xmss_sig.bin msg.bin\n");
396396

397397
exit(EXIT_FAILURE);
398398
}
@@ -561,5 +561,5 @@ int main(int argc, char** argv) {
561561
printf("This requires --enable-xmss.\n");
562562
return 0;
563563
}
564-
#endif /* WITH_LIBXMSS */
564+
#endif /* WOLFSSL_HAVE_XMSS */
565565

0 commit comments

Comments
 (0)