Skip to content

Commit 284e405

Browse files
authored
Add LMS/HSS example. (#390)
1 parent f155379 commit 284e405

5 files changed

Lines changed: 514 additions & 2 deletions

File tree

pq/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ safe connection. Authentication will be done via the FALCON signature scheme.
7373
Ephemeral key establishment will be done via kYBER KEM. Both are NIST PQC
7474
competition round 3 finalists. Please see
7575
https://github.com/wolfSSL/osp/tree/master/oqs/README.md for further
76-
instructions about certificate generation.
76+
instructions about certificate generation.
7777

7878
In a terminal, execute the server:
7979

pq/sphincs_sign_verify.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ int main(int argc, char** argv)
108108
}
109109

110110
if (ret == 0) {
111-
ret = wc_KeyPemToDer((const byte*)pem_buf, pem_len,
111+
ret = wc_KeyPemToDer((const byte*)pem_buf, pem_len,
112112
priv_der_buf, priv_der_len, NULL);
113113
if (ret > 0) {
114114
priv_der_len = ret;

pq/stateful_hash_sig/Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# PQ Stateful Hash-Based Signature Examples Makefile
2+
CC = gcc
3+
LIB_PATH = /usr/local
4+
HSS_INC = <path to hss install>
5+
CFLAGS = -Wall -I$(LIB_PATH)/include -I$(HSS_INC)
6+
LIBS = -L$(LIB_PATH)/lib -lm
7+
8+
# option variables
9+
DYN_LIB = -lwolfssl
10+
STATIC_LIB = $(LIB_PATH)/lib/libwolfssl.a
11+
HSS_LIB = <path to hss_lib_thread.a>
12+
DEBUG_FLAGS = -g -DDEBUG
13+
DEBUG_INC_PATHS = -MD
14+
OPTIMIZE = -Os
15+
16+
# Options
17+
#CFLAGS+=$(DEBUG_FLAGS)
18+
#CFLAGS+=$(OPTIMIZE)
19+
LIBS+=$(STATIC_LIB)
20+
#LIBS+=$(DYN_LIB)
21+
LIBS+=$(HSS_LIB)
22+
23+
# build targets
24+
SRC=$(wildcard *.c)
25+
TARGETS=$(patsubst %.c, %, $(SRC))
26+
27+
.PHONY: clean all
28+
29+
all: $(TARGETS)
30+
31+
debug: CFLAGS+=$(DEBUG_FLAGS)
32+
debug: all
33+
34+
# build template
35+
lms_example: lms_example.c
36+
$(CC) -o $@ $< $(CFLAGS) $(LIBS)
37+
38+
clean:
39+
rm -f $(TARGETS)
40+
rm -f lms_example.key

pq/stateful_hash_sig/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# wolfSSL Post-Quantum Cryptography Stateful Hash-based Signatures Example
2+
3+
This directory contains:
4+
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>`.
8+
9+
# Prerequisites
10+
11+
The LMS sign verify example requires that hash-sigs has been built, and
12+
wolfSSL has been built with LMS/HSS support enabled. Please see Item 17
13+
in the wolfSSL repo's INSTALL file.
14+
15+
https://github.com/wolfSSL/wolfssl/blob/master/INSTALL
16+
17+
## Building the Applications
18+
19+
Configure the Makefile to point to your hash-sigs install:
20+
21+
```
22+
HSS_INC = <path to hss install>
23+
```
24+
25+
```
26+
HSS_LIB = <path to hss_lib_thread.a>
27+
```
28+
29+
Then build:
30+
31+
```
32+
$ make
33+
```
34+
35+
## Signing and Verifying a Message with LMS/HSS
36+
37+
This example will generate an LMS/HSS key pair with L=levels, H=height, and
38+
W=Winternitz parameters, then sign and verify a given number of signatures.
39+
It will also print the signature size, the total number of signatures, and
40+
the public and private key lengths.
41+
42+
While LMS/HSS have small public and private keys, and fast signing and
43+
verifying, the initial key generation can be quite slow and intensive,
44+
especially for larger heights and Winternitz parameters.
45+
46+
LMS/HSS signature systems have a finite number of one-time signatures (OTS).
47+
The number of available signatures is
48+
N = 2 ** (levels * height)
49+
50+
The supported parameter values are those in RFC8554:
51+
- levels = {1..8}
52+
- height = {5, 10, 15, 20, 25}
53+
- Winternitz = {1, 2, 4, 8}
54+
55+
To see the help and usage, run the program without options:
56+
```sh
57+
$./lms_example
58+
usage:
59+
./lms_example <levels> <height> <winternitz> [num signatures]
60+
61+
examples:
62+
./lms_example 1 5 1
63+
./lms_example 3 5 4 100
64+
./lms_example 2 10 2 0
65+
66+
description:
67+
...
68+
```

0 commit comments

Comments
 (0)