Skip to content

Commit e6a7fcb

Browse files
committed
WIP tests
1 parent 17819d1 commit e6a7fcb

File tree

4 files changed

+111
-56
lines changed

4 files changed

+111
-56
lines changed

.github/workflows/lms.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,49 @@ jobs:
144144
package: ${{ github.workflow }}
145145
target: ${{ matrix.target }}
146146
features: ${{ matrix.features }}
147+
148+
# Demo scripts
149+
demo-lms:
150+
needs: set-msrv
151+
strategy:
152+
matrix:
153+
rust:
154+
- stable
155+
features:
156+
- default
157+
158+
runs-on: ubuntu-latest
159+
defaults:
160+
run:
161+
# Cross mounts only current package, i.e. by default it ignores workspace's Cargo.toml
162+
working-directory: .
163+
steps:
164+
- uses: actions/checkout@v4
165+
- uses: RustCrypto/actions/cargo-cache@master
166+
- uses: dtolnay/rust-toolchain@v1
167+
with:
168+
toolchain: ${{ matrix.rust }}
169+
- run: sh scripts/lms-demo.sh
170+
171+
# Demo scripts
172+
demo-sst:
173+
needs: set-msrv
174+
strategy:
175+
matrix:
176+
rust:
177+
- stable
178+
features:
179+
- default
180+
181+
runs-on: ubuntu-latest
182+
defaults:
183+
run:
184+
# Cross mounts only current package, i.e. by default it ignores workspace's Cargo.toml
185+
working-directory: .
186+
steps:
187+
- uses: actions/checkout@v4
188+
- uses: RustCrypto/actions/cargo-cache@master
189+
- uses: dtolnay/rust-toolchain@v1
190+
with:
191+
toolchain: ${{ matrix.rust }}
192+
- run: sh scripts/sst-demo.sh

README.md

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,62 +12,8 @@ This implementation is binary compatible with the reference implementation found
1212
This crate does not require the standard library (i.e. no_std capable) and can be easily used for bare-metal programming.
1313

1414
## Demo
15-
A demo application is located in the `examples` folder to demonstrate the use of the library.
16-
This demo application can be used in the console as follows:
17-
18-
```
19-
# Key generation
20-
# Generates `mykey.prv`, `mykey.pub` with merkle tree height 10 and winternitz parameter 2
21-
cargo run --release --example lms-demo -- genkey mykey 10/2 --seed 0123456701234567012345670123456701234567012345670123456701234567
22-
23-
# Signing
24-
# Generates `message.txt.sig`
25-
cargo run --release --example lms-demo -- sign mykey message.txt
26-
27-
# Signing (fast_verification)
28-
# Generates `message.txt_mut`, `message.txt_mut.sig`
29-
HBS_LMS_MAX_HASH_OPTIMIZATIONS=1000 HBS_LMS_THREADS=2 cargo run --release --example lms-demo \
30-
--features fast_verify -- sign_mut mykey message.txt
31-
32-
# Verification
33-
# Verifies `message.txt` with `message.txt.sig` against `mykey.pub`
34-
cargo run --release --example lms-demo -- verify mykey message.txt
35-
```
36-
37-
The SST extension can be used as follows:
38-
39-
```
40-
# Key generation: prepare
41-
# Generates intermediate node, generates or reads the tree identifier (init_tree_ident 1/0), and uses "mykey" as filename base.
42-
# One dedicated signing entity has to create the common L-0 tree identifier (--init_tree_ident=1) before other signing entities
43-
# can generate their subtrees.
44-
#
45-
# The following example uses two HSS levels, first with tree height = 10 / Winternitz = 8, second with 5 / 2.
46-
# First, a signing entity (here: 1 of 8) creates the tree identifier
47-
cargo run --release --example sst-demo -- prepare_keygen mykey 10/8,5/2 --ssts=1/8 --auxsize=2048 \
48-
--seed=c912a74bc8c5fc1b2a73b96e6ce1eb2317dc9aa49806b30e --init_tree_ident
49-
# The signing instance index is 3 of total 8, and this signing entity will use the tree identifier and use another secret seed.
50-
# This will use "mykey.5.prv" and "mykey.5.aux" for private key and aux data, and "mykey_treeident.bin" to write the tree identifier
51-
seq 2 8 | xargs -i{} cargo run --release --example sst-demo -- prepare_keygen mykey 10/8,5/2 --ssts={}/8 --auxsize=2048 \
52-
--seed=1eb2317dc9aa49806b30e578436d0f659b1f5c912a74bc8c
53-
54-
# Key generation: finalize
55-
# After all signing entities have created their intermediate node values, the public key can be generated.
56-
# This will use mykey.5.pub to write the public key for signing entity index 5.
57-
cargo run --release --example sst-demo -- finalize_keygen mykey 5
58-
59-
# Signing
60-
# Generates `message.txt.sig` using mykey.5.prv
61-
cargo run --release --example sst-demo -- sign mykey.5 message.txt
62-
63-
# Verification
64-
# Verifies `message.txt` with `message.txt.sig` against `mykey.5.pub`
65-
cargo run --release --example sst-demo -- verify mykey.5 message.txt
66-
67-
# Verification can as well performed with lms-demo
68-
# Verifies `message.txt` with `message.txt.sig` against `mykey.5.pub`
69-
cargo run --release --example lms-demo -- verify mykey.5 message.txt
70-
```
15+
Two demo applications are located in the `examples` folder to demonstrate the use of the library.
16+
The examples are the [lms-demo](scripts/lms-demo.sh) and the [sst-demo](scripts/sst-demo.sh).
7117

7218
## Naming conventions wrt to the IETF RFC
7319
The naming in the RFC is done by using a single character.

scripts/lms-demo.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
touch message.txt
2+
3+
random="$(dd if=/dev/urandom bs=24 count=1 status=none | hexdump -v -e '/1 "%02X"'; echo)"
4+
5+
# Key generation
6+
# Generates `mykey.prv`, `mykey.pub` with merkle tree height 10 and winternitz parameter 2
7+
cargo run --release --example lms-demo -- genkey mykey 5/4,5/4 --seed $random &&
8+
9+
# Signing
10+
# Generates `message.txt.sig`
11+
cargo run --release --example lms-demo -- sign mykey message.txt &&
12+
13+
# Verification
14+
# Verifies `message.txt` with `message.txt.sig` against `mykey.pub`
15+
cargo run --release --example lms-demo -- verify mykey message.txt &&
16+
17+
# # Signing (fast_verification)
18+
# # Generates `message.txt_mut`, `message.txt_mut.sig`
19+
# HBS_LMS_MAX_HASH_OPTIMIZATIONS=1000 HBS_LMS_THREADS=1 cargo run --release --example lms-demo \
20+
# --features fast_verify -- sign_mut mykey message.txt &&
21+
22+
# Verification
23+
# Verifies `message.txt` with `message.txt.sig` against `mykey.pub`
24+
cargo run --release --example lms-demo -- verify mykey message.txt

scripts/sst-demo.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
MAX_SE_IDX=8
2+
3+
touch message.txt
4+
5+
random="$(dd if=/dev/urandom bs=24 count=1 status=none | hexdump -v -e '/1 "%02X"'; echo)"
6+
7+
# Key generation: prepare
8+
# Generates intermediate node, generates or reads the tree identifier (init_tree_ident 1/0), and uses "mykey" as filename base.
9+
# One dedicated signing entity has to create the common L-0 tree identifier (--init_tree_ident=1) before other signing entities
10+
# can generate their subtrees.
11+
#
12+
# The following example uses two HSS levels, first with tree height = 10 / Winternitz = 8, second with 5 / 2.
13+
# First, a signing entity (here: 1 of 8) creates the tree identifier
14+
cargo run --release --example sst-demo -- prepare_keygen mykey 10/4 --ssts=1/$MAX_SE_IDX \
15+
--auxsize=2048 --seed $random --init_tree_ident
16+
17+
for se_idx in $(seq 2 $MAX_SE_IDX);
18+
do
19+
random="$(dd if=/dev/urandom bs=24 count=1 status=none | hexdump -v -e '/1 "%02X"'; echo)"
20+
21+
# Create signing entities with index 2 to 8, will use same tree identifier but another secret seed.
22+
# This will use "mykey.X.prv" and "mykey.X.aux" for private key and aux data, and "mykey.X_treeident.bin" to write the tree identifier
23+
cargo run --release --example sst-demo -- prepare_keygen mykey 10/4 --ssts=$se_idx/$MAX_SE_IDX \
24+
--auxsize=2048 --seed $random
25+
done
26+
27+
# Key generation: finalize
28+
# After all signing entities have created their intermediate node values, the public key can be generated.
29+
# This will use mykey.5.pub to write the public key for signing entity index 5.
30+
cargo run --release --example sst-demo -- finalize_keygen mykey 5 &&
31+
32+
# Signing
33+
# Generates `message.txt.sig` using mykey.5.prv
34+
cargo run --release --example sst-demo -- sign mykey.5 message.txt &&
35+
36+
# Verification
37+
# Verifies `message.txt` with `message.txt.sig` against `mykey.5.pub`
38+
cargo run --release --example sst-demo -- verify mykey.5 message.txt &&
39+
cargo run --release --example lms-demo -- verify mykey.5 message.txt

0 commit comments

Comments
 (0)