Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pq: ML-DSA example, and reorganize examples. #466

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ pq/stateful_hash_sig/xmss_example.key
pq/stateful_hash_sig/lms_example
pq/stateful_hash_sig/lms_example.key

# PQ ML-DSA
pq/ml_dsa/ml_dsa_test
pq/ml_dsa/*.bin
pq/ml_dsa/*.key

embedded/tls-client-server
embedded/tls-server-size
embedded/tls-sock-client
Expand Down
18 changes: 18 additions & 0 deletions pq/ml_dsa/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CC = gcc

WOLFSSL_INSTALL_DIR = /usr/local

WOLFSSL_CFLAGS = -Wextra -Werror -Wall -I$(WOLFSSL_INSTALL_DIR)/include
WOLFSSL_LIBS = -L$(WOLFSSL_INSTALL_DIR)/lib -lm -lwolfssl

DEBUG_FLAGS = -g -DDEBUG

all: ml_dsa_test

ml_dsa_test: ml_dsa.c
$(CC) -o $@ $^ $(WOLFSSL_CFLAGS) $(WOLFSSL_LIBS) $(DEBUG_FLAGS)

.PHONY: clean all

clean:
rm -f *.o wolfssl_acert ml_dsa_test
65 changes: 65 additions & 0 deletions pq/ml_dsa/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Description

Simple example of wolfCrypt ML-DSA keygen, signing, and verifying.

Requires wolfSSL is built with:

```sh
./configure --enable-dilithium
make
make install
```

Build the ML-DSA example with:

```sh
make ml_dsa_test
```

# Usage

```
./ml_dsa_test -?
usage:
./ml_dsa_test [-pvw] -c <security category> [-m <message>]

parms:
-m <message> the message to sign
-c <security category> set the security category {2,3,5}
-p print FIPS 204 parameters and exit
-v verbose
-w write keys, msg, and sig to file
-? show this help
```

## Keygen, sign, and verify

This will generate a keypair with security category 5, then
sign and verify a test message, and write the keys, message,
and signature to `*.key` and `*.bin` files:
```
./ml_dsa_test -c 5 -m "my test message" -w
info: making key
info: using ML-DSA-87, Security Category 5: priv_len 4896, pub_len 2592, sig_len 4627
info: signed message
info: verify message good
info: done
```

## Print Supported ML-DSA Parameters

To see the supported parameters:

```
./ml_dsa_test -p
ML-DSA parameters and key/sig sizes*

Private Key Public Key Signature Size Security Strength
ML-DSA-44 2560 1312 2420 Category 2
ML-DSA-65 4032 1952 3309 Category 3
ML-DSA-87 4896 2592 4627 Category 5


* from Tables 1 & 2 of FIPS 204:
https://csrc.nist.gov/pubs/fips/204/final
```
Loading