Skip to content

Commit

Permalink
Merge branch 'dev' into jonas/psq
Browse files Browse the repository at this point in the history
  • Loading branch information
jschneider-bensch authored Jun 27, 2024
2 parents 03f9269 + 5611bb3 commit d3bee52
Show file tree
Hide file tree
Showing 58 changed files with 25,086 additions and 305 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions libcrux-ml-dsa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ readme.workspace = true
libcrux-sha3 = { version = "0.0.2-pre.2", path = "../libcrux-sha3" }

[dev-dependencies]
rand = { version = "0.8" }
hex = { version = "0.4.3", features = ["serde"] }
serde_json = { version = "1.0" }
serde = { version = "1.0", features = ["derive"] }
criterion = "0.5"
pqcrypto-dilithium = { version = "0.5.0", default-features = false }

[[bench]]
name = "ml-dsa"
harness = false
94 changes: 94 additions & 0 deletions libcrux-ml-dsa/benches/ml-dsa.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
use std::time::Duration;

use criterion::{criterion_group, criterion_main, Criterion};
use rand::{rngs::OsRng, RngCore};

use libcrux_ml_dsa::ml_dsa_65;

pub fn comparisons_key_generation(c: &mut Criterion) {
let mut rng = OsRng;
let mut group = c.benchmark_group("ML-DSA-65 Key Generation");
group.measurement_time(Duration::from_secs(10));

group.bench_function("libcrux portable (external random)", |b| {
let mut randomness = [0; 32];
rng.fill_bytes(&mut randomness);
b.iter(|| {
let _ = ml_dsa_65::generate_key_pair(randomness);
})
});

group.bench_function("pqclean reference implementation (internal random)", |b| {
b.iter(|| {
let (_, _) = pqcrypto_dilithium::dilithium3::keypair();
})
});
}

pub fn comparisons_signing(c: &mut Criterion) {
let mut rng = OsRng;
let mut group = c.benchmark_group("ML-DSA-65 Signing");
group.measurement_time(Duration::from_secs(10));

let mut message = [0u8; 511];
rng.fill_bytes(&mut message);

group.bench_function("libcrux portable (external random)", |b| {
let mut randomness = [0; 32];
rng.fill_bytes(&mut randomness);
let keypair = ml_dsa_65::generate_key_pair(randomness);

rng.fill_bytes(&mut randomness);
b.iter(|| {
let _ = ml_dsa_65::sign(keypair.signing_key, &message, randomness);
})
});

group.bench_function("pqclean reference implementation (internal random)", |b| {
let (_, sk) = pqcrypto_dilithium::dilithium3::keypair();
b.iter(|| {
let _ = pqcrypto_dilithium::dilithium3::detached_sign(&message, &sk);
})
});
}

pub fn comparisons_verification(c: &mut Criterion) {
let mut rng = OsRng;
let mut group = c.benchmark_group("ML-DSA-65 Verification");
group.measurement_time(Duration::from_secs(10));

let mut message = [0u8; 511];
rng.fill_bytes(&mut message);

group.bench_function("libcrux portable (external random)", |b| {
let mut randomness = [0; 32];
rng.fill_bytes(&mut randomness);
let keypair = ml_dsa_65::generate_key_pair(randomness);

rng.fill_bytes(&mut randomness);
let signature = ml_dsa_65::sign(keypair.signing_key, &message, randomness);
b.iter(|| {
let _ = ml_dsa_65::verify(keypair.verification_key, &message, signature).unwrap();
})
});

group.bench_function("pqclean reference implementation (internal random)", |b| {
let (vk, sk) = pqcrypto_dilithium::dilithium3::keypair();
let signature = pqcrypto_dilithium::dilithium3::detached_sign(&message, &sk);
b.iter(|| {
let _ = pqcrypto_dilithium::dilithium3::verify_detached_signature(
&signature, &message, &vk,
)
.unwrap();
})
});
}

pub fn comparisons(c: &mut Criterion) {
comparisons_key_generation(c);
comparisons_signing(c);
comparisons_verification(c);
}

criterion_group!(benches, comparisons);
criterion_main!(benches);
17 changes: 17 additions & 0 deletions libcrux-ml-dsa/examples/key_pair_65.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use libcrux_ml_dsa::ml_dsa_65;
use rand::{rngs::OsRng, RngCore};

fn random_array<const L: usize>() -> [u8; L] {
let mut rng = OsRng;
let mut seed = [0; L];
rng.try_fill_bytes(&mut seed).unwrap();
seed
}

fn main() {
let key_generation_seed = random_array();

for _i in 0..100_000 {
let _ = ml_dsa_65::generate_key_pair(key_generation_seed);
}
}
21 changes: 21 additions & 0 deletions libcrux-ml-dsa/examples/sign_65.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use libcrux_ml_dsa::ml_dsa_65;
use rand::{rngs::OsRng, RngCore};

fn random_array<const L: usize>() -> [u8; L] {
let mut rng = OsRng;
let mut seed = [0; L];
rng.try_fill_bytes(&mut seed).unwrap();
seed
}

fn main() {
let key_generation_seed = random_array();
let signing_randomness = random_array();
let message = random_array::<1023>();

let keypair = ml_dsa_65::generate_key_pair(key_generation_seed);

for _i in 0..100_000 {
let _ = ml_dsa_65::sign(keypair.signing_key, &message, signing_randomness);
}
}
22 changes: 22 additions & 0 deletions libcrux-ml-dsa/examples/verify_65.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use libcrux_ml_dsa::ml_dsa_65;
use rand::{rngs::OsRng, RngCore};

fn random_array<const L: usize>() -> [u8; L] {
let mut rng = OsRng;
let mut seed = [0; L];
rng.try_fill_bytes(&mut seed).unwrap();
seed
}

fn main() {
let key_generation_seed = random_array();
let signing_randomness = random_array();
let message = random_array::<1023>();

let keypair = ml_dsa_65::generate_key_pair(key_generation_seed);
let signature = ml_dsa_65::sign(keypair.signing_key, &message, signing_randomness);

for _i in 0..100_000 {
ml_dsa_65::verify(keypair.verification_key, &message, signature).unwrap();
}
}
Loading

0 comments on commit d3bee52

Please sign in to comment.