Skip to content

Commit 00fbf9c

Browse files
authored
Merge pull request #466 from philljj/ml_dsa_example
pq: ML-DSA example, and reorganize examples.
2 parents 14dfeeb + e5fdf2e commit 00fbf9c

22 files changed

Lines changed: 518 additions & 0 deletions

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ pq/stateful_hash_sig/xmss_example.key
265265
pq/stateful_hash_sig/lms_example
266266
pq/stateful_hash_sig/lms_example.key
267267

268+
# PQ ML-DSA
269+
pq/ml_dsa/ml_dsa_test
270+
pq/ml_dsa/*.bin
271+
pq/ml_dsa/*.key
272+
268273
embedded/tls-client-server
269274
embedded/tls-server-size
270275
embedded/tls-sock-client

pq/ml_dsa/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
CC = gcc
2+
3+
WOLFSSL_INSTALL_DIR = /usr/local
4+
5+
WOLFSSL_CFLAGS = -Wextra -Werror -Wall -I$(WOLFSSL_INSTALL_DIR)/include
6+
WOLFSSL_LIBS = -L$(WOLFSSL_INSTALL_DIR)/lib -lm -lwolfssl
7+
8+
DEBUG_FLAGS = -g -DDEBUG
9+
10+
all: ml_dsa_test
11+
12+
ml_dsa_test: ml_dsa.c
13+
$(CC) -o $@ $^ $(WOLFSSL_CFLAGS) $(WOLFSSL_LIBS) $(DEBUG_FLAGS)
14+
15+
.PHONY: clean all
16+
17+
clean:
18+
rm -f *.o wolfssl_acert ml_dsa_test

pq/ml_dsa/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Description
2+
3+
Simple example of wolfCrypt ML-DSA keygen, signing, and verifying.
4+
5+
Requires wolfSSL is built with:
6+
7+
```sh
8+
./configure --enable-dilithium
9+
make
10+
make install
11+
```
12+
13+
Build the ML-DSA example with:
14+
15+
```sh
16+
make ml_dsa_test
17+
```
18+
19+
# Usage
20+
21+
```
22+
./ml_dsa_test -?
23+
usage:
24+
./ml_dsa_test [-pvw] -c <security category> [-m <message>]
25+
26+
parms:
27+
-m <message> the message to sign
28+
-c <security category> set the security category {2,3,5}
29+
-p print FIPS 204 parameters and exit
30+
-v verbose
31+
-w write keys, msg, and sig to file
32+
-? show this help
33+
```
34+
35+
## Keygen, sign, and verify
36+
37+
This will generate a keypair with security category 5, then
38+
sign and verify a test message, and write the keys, message,
39+
and signature to `*.key` and `*.bin` files:
40+
```
41+
./ml_dsa_test -c 5 -m "my test message" -w
42+
info: making key
43+
info: using ML-DSA-87, Security Category 5: priv_len 4896, pub_len 2592, sig_len 4627
44+
info: signed message
45+
info: verify message good
46+
info: done
47+
```
48+
49+
## Print Supported ML-DSA Parameters
50+
51+
To see the supported parameters:
52+
53+
```
54+
./ml_dsa_test -p
55+
ML-DSA parameters and key/sig sizes*
56+
57+
Private Key Public Key Signature Size Security Strength
58+
ML-DSA-44 2560 1312 2420 Category 2
59+
ML-DSA-65 4032 1952 3309 Category 3
60+
ML-DSA-87 4896 2592 4627 Category 5
61+
62+
63+
* from Tables 1 & 2 of FIPS 204:
64+
https://csrc.nist.gov/pubs/fips/204/final
65+
```

0 commit comments

Comments
 (0)