-
Notifications
You must be signed in to change notification settings - Fork 0
Implementation of ML-DSA #10
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
Open
jnsiemer
wants to merge
5
commits into
dev
Choose a base branch
from
ml_dsa
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| // Copyright 2026 Jan Niklas Siemer | ||
| // | ||
| // This file is part of qFALL-schemes. | ||
| // | ||
| // qfall-schemes is free software: you can redistribute it and/or modify it under | ||
| // the terms of the Mozilla Public License Version 2.0 as published by the | ||
| // Mozilla Foundation. See <https://mozilla.org/en-US/MPL/2.0/>. | ||
|
|
||
| use criterion::*; | ||
| use qfall_schemes::signature::MLDSA; | ||
| use qfall_schemes::signature::SignatureScheme; | ||
|
|
||
| /// Performs a full-cycle of key_gen, sign, vfy with [`MLDSA`]. | ||
|
jnsiemer marked this conversation as resolved.
|
||
| fn mldsa_cycle(ml_dsa: &mut MLDSA) { | ||
| let (pk, sk) = ml_dsa.key_gen(); | ||
| let msg = String::from("benchmark message"); | ||
| let sig = ml_dsa.sign(msg.clone(), &sk, &pk); | ||
| let _ = ml_dsa.vfy(msg, &sig, &pk); | ||
| } | ||
|
|
||
| /// Benchmark [mldsa_cycle] with [MLDSA::ml_dsa_44]. | ||
| /// | ||
| /// This benchmark can be run with for example: | ||
| /// - `cargo criterion ML-DSA\ cycle\ 44` | ||
| /// - `cargo bench --bench benchmarks ML-DSA\ cycle\ 44` | ||
| /// - `cargo flamegraph --bench benchmarks -- --bench ML-DSA\ cycle\ 44` | ||
| fn bench_mldsa_cycle_44(c: &mut Criterion) { | ||
| let mut ml_dsa = MLDSA::ml_dsa_44(); | ||
|
|
||
| c.bench_function("ML-DSA cycle 44", |b| b.iter(|| mldsa_cycle(&mut ml_dsa))); | ||
| } | ||
|
|
||
| /// Benchmark [MLDSA::key_gen] with [MLDSA::ml_dsa_44]. | ||
| fn bench_mldsa_gen_44(c: &mut Criterion) { | ||
| let mut ml_dsa = MLDSA::ml_dsa_44(); | ||
|
|
||
| c.bench_function("ML-DSA key_gen 44", |b| b.iter(|| ml_dsa.key_gen())); | ||
| } | ||
|
|
||
| /// Benchmark [MLDSA::sign] with [MLDSA::ml_dsa_44]. | ||
| fn bench_mldsa_sign_44(c: &mut Criterion) { | ||
| let mut ml_dsa = MLDSA::ml_dsa_44(); | ||
| let (pk, sk) = ml_dsa.key_gen(); | ||
| let msg = String::from("benchmark message"); | ||
|
|
||
| c.bench_function("ML-DSA sign 44", |b| { | ||
| b.iter(|| ml_dsa.sign(msg.clone(), &sk, &pk)) | ||
| }); | ||
| } | ||
|
|
||
| /// Benchmark [MLDSA::vfy] with [MLDSA::ml_dsa_44]. | ||
| fn bench_mldsa_vfy_44(c: &mut Criterion) { | ||
| let mut ml_dsa = MLDSA::ml_dsa_44(); | ||
| let (pk, sk) = ml_dsa.key_gen(); | ||
| let msg = String::from("benchmark message"); | ||
| let sig = ml_dsa.sign(msg.clone(), &sk, &pk); | ||
|
|
||
| c.bench_function("ML-DSA vfy 44", |b| { | ||
| b.iter(|| ml_dsa.vfy(msg.clone(), &sig, &pk)) | ||
| }); | ||
| } | ||
|
|
||
| /// Benchmark [mldsa_cycle] with [MLDSA::ml_dsa_65]. | ||
| /// | ||
| /// This benchmark can be run with for example: | ||
| /// - `cargo criterion ML-DSA\ cycle\ 65` | ||
| /// - `cargo bench --bench benchmarks ML-DSA\ cycle\ 65` | ||
| /// - `cargo flamegraph --bench benchmarks -- --bench ML-DSA\ cycle\ 65` | ||
| fn bench_mldsa_cycle_65(c: &mut Criterion) { | ||
| let mut ml_dsa = MLDSA::ml_dsa_65(); | ||
|
|
||
| c.bench_function("ML-DSA cycle 65", |b| b.iter(|| mldsa_cycle(&mut ml_dsa))); | ||
| } | ||
|
|
||
| /// Benchmark [MLDSA::key_gen] with [MLDSA::ml_dsa_65]. | ||
| fn bench_mldsa_gen_65(c: &mut Criterion) { | ||
| let mut ml_dsa = MLDSA::ml_dsa_65(); | ||
|
|
||
| c.bench_function("ML-DSA key_gen 65", |b| b.iter(|| ml_dsa.key_gen())); | ||
| } | ||
|
|
||
| /// Benchmark [MLDSA::sign] with [MLDSA::ml_dsa_65]. | ||
| fn bench_mldsa_sign_65(c: &mut Criterion) { | ||
| let mut ml_dsa = MLDSA::ml_dsa_65(); | ||
| let (pk, sk) = ml_dsa.key_gen(); | ||
| let msg = String::from("benchmark message"); | ||
|
|
||
| c.bench_function("ML-DSA sign 65", |b| { | ||
| b.iter(|| ml_dsa.sign(msg.clone(), &sk, &pk)) | ||
| }); | ||
| } | ||
|
|
||
| /// Benchmark [MLDSA::vfy] with [MLDSA::ml_dsa_65]. | ||
| fn bench_mldsa_vfy_65(c: &mut Criterion) { | ||
| let mut ml_dsa = MLDSA::ml_dsa_65(); | ||
| let (pk, sk) = ml_dsa.key_gen(); | ||
| let msg = String::from("benchmark message"); | ||
| let sig = ml_dsa.sign(msg.clone(), &sk, &pk); | ||
|
|
||
| c.bench_function("ML-DSA vfy 65", |b| { | ||
| b.iter(|| ml_dsa.vfy(msg.clone(), &sig, &pk)) | ||
| }); | ||
| } | ||
|
|
||
| /// Benchmark [mldsa_cycle] with [MLDSA::ml_dsa_87]. | ||
| /// | ||
| /// This benchmark can be run with for example: | ||
| /// - `cargo criterion ML-DSA\ cycle\ 87` | ||
| /// - `cargo bench --bench benchmarks ML-DSA\ cycle\ 87` | ||
| /// - `cargo flamegraph --bench benchmarks -- --bench ML-DSA\ cycle\ 87` | ||
| fn bench_mldsa_cycle_87(c: &mut Criterion) { | ||
| let mut ml_dsa = MLDSA::ml_dsa_87(); | ||
|
|
||
| c.bench_function("ML-DSA cycle 87", |b| b.iter(|| mldsa_cycle(&mut ml_dsa))); | ||
| } | ||
|
|
||
| /// Benchmark [MLDSA::key_gen] with [MLDSA::ml_dsa_87]. | ||
| fn bench_mldsa_gen_87(c: &mut Criterion) { | ||
| let mut ml_dsa = MLDSA::ml_dsa_87(); | ||
|
|
||
| c.bench_function("ML-DSA key_gen 87", |b| b.iter(|| ml_dsa.key_gen())); | ||
| } | ||
|
|
||
| /// Benchmark [MLDSA::sign] with [MLDSA::ml_dsa_87]. | ||
| fn bench_mldsa_sign_87(c: &mut Criterion) { | ||
| let mut ml_dsa = MLDSA::ml_dsa_87(); | ||
| let (pk, sk) = ml_dsa.key_gen(); | ||
| let msg = String::from("benchmark message"); | ||
|
|
||
| c.bench_function("ML-DSA sign 87", |b| { | ||
| b.iter(|| ml_dsa.sign(msg.clone(), &sk, &pk)) | ||
| }); | ||
| } | ||
|
|
||
| /// Benchmark [MLDSA::vfy] with [MLDSA::ml_dsa_87]. | ||
| fn bench_mldsa_vfy_87(c: &mut Criterion) { | ||
| let mut ml_dsa = MLDSA::ml_dsa_87(); | ||
| let (pk, sk) = ml_dsa.key_gen(); | ||
| let msg = String::from("benchmark message"); | ||
| let sig = ml_dsa.sign(msg.clone(), &sk, &pk); | ||
|
|
||
| c.bench_function("ML-DSA vfy 87", |b| { | ||
| b.iter(|| ml_dsa.vfy(msg.clone(), &sig, &pk)) | ||
| }); | ||
| } | ||
|
|
||
| criterion_group!( | ||
| benches, | ||
| bench_mldsa_cycle_44, | ||
| bench_mldsa_gen_44, | ||
| bench_mldsa_sign_44, | ||
| bench_mldsa_vfy_44, | ||
| bench_mldsa_cycle_65, | ||
| bench_mldsa_gen_65, | ||
| bench_mldsa_sign_65, | ||
| bench_mldsa_vfy_65, | ||
| bench_mldsa_cycle_87, | ||
| bench_mldsa_gen_87, | ||
| bench_mldsa_sign_87, | ||
| bench_mldsa_vfy_87, | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filedescription missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The benchmark files never have a file description. Any (doc-) comments that are part of the benchmarks aren't available in the documentation anyway. So, these comments are really "just" for developers.