Skip to content
Open
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
11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "qfall-schemes"
version = "0.1.1"
version = "0.1.2"
edition = "2024"
rust-version = "1.87" # due to wit_bindgen dependency
description = "Collection of prototype implementations of lattice-based cryptography"
Expand All @@ -15,13 +15,14 @@ autobenches = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
qfall-tools = "0"
qfall-math = "0"
sha2 = "0.11.0"
qfall-tools = "0.1"
qfall-math = "0.1"
sha2 = "0.11"
serde = {version="1", features=["derive"]}
serde_json = "1"
typetag = "0"
typetag = "0.2"
criterion = { version = "0.8", features = ["html_reports"] }
rand = "0.10"

[profile.bench]
debug = true
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ List of prototypes
- [Full-Domain Hash (FDH)](https://docs.rs/qfall-schemes/latest/qfall_schemes/signature/fdh/struct.FDHGPV.html)
- [Probabilistic FDH (PFDH)](https://docs.rs/qfall-schemes/latest/qfall_schemes/signature/pfdh/struct.PFDHGPV.html)
- [Ring-based FDH](https://docs.rs/qfall-schemes/latest/qfall_schemes/signature/fdh/struct.FDHGPVRing.html)
- [ML-DSA](https://docs.rs/qfall-schemes/latest/qfall_schemes/signature/struct.MLDSA.html)
- [Identity Based Encryption](https://docs.rs/qfall-schemes/latest/qfall_schemes/identity_based_encryption/index.html)
- [From Dual LWE Encryption](https://docs.rs/qfall-schemes/latest/qfall_schemes/identity_based_encryption/struct.DualRegevIBE.html)
- [Hash Functions](https://docs.rs/qfall-schemes/latest/qfall_schemes/hash/index.html)
Expand Down
3 changes: 2 additions & 1 deletion benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
use criterion::criterion_main;

pub mod k_pke;
pub mod ml_dsa;
pub mod pfdh;
pub mod regev;

criterion_main! {regev::benches, pfdh::benches, k_pke::benches}
criterion_main! {regev::benches, pfdh::benches, k_pke::benches, ml_dsa::benches}
161 changes: 161 additions & 0 deletions benches/ml_dsa.rs
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/>.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filedescription missing

Copy link
Copy Markdown
Member Author

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.

use criterion::*;
use qfall_schemes::signature::MLDSA;
use qfall_schemes::signature::SignatureScheme;

/// Performs a full-cycle of key_gen, sign, vfy with [`MLDSA`].
Comment thread
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,
);
2 changes: 1 addition & 1 deletion src/hash/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl HashInto<MatZq> for HashMatZq {
/// };
/// let hash_val = hasher.hash("Hello");
/// ```
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct HashMatPolynomialRingZq {
pub modulus: ModulusPolynomialRingZq,
pub rows: i64,
Expand Down
7 changes: 7 additions & 0 deletions src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@
//! "Trapdoors for hard lattices and new cryptographic constructions."
//! Proceedings of the fortieth annual ACM symposium on Theory of computing. 2008.
//! <https://doi.org/10.1145/1374376.1374407>
//! - \[2\] National Institute of Standards and Technology (2024).
//! Module-Lattice-Based Digital Signature Standard.
//! Federal Information Processing Standards Publication (FIPS 204).
//! <https://doi.org/10.6028/NIST.FIPS.204>

pub mod fdh;
mod ml_dsa;
pub mod pfdh;

pub use ml_dsa::MLDSA;

/// This trait should be implemented by every signature scheme.
/// It captures the essential functionalities each signature scheme has to support.
///
Expand Down
Loading
Loading