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

ML-DSA: update benchmarks pqclean #736

Merged
merged 5 commits into from
Jan 14, 2025
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: 4 additions & 1 deletion libcrux-ml-dsa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ 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

# This doesn't build on intel macos.
[target.'cfg(not(all(target_os = "macos", target_arch = "x86_64")))'.dev-dependencies]
pqcrypto-mldsa = { version = "0.1.0" } #, default-features = false

[features]
default = ["std", "mldsa44", "mldsa65", "mldsa87"]
Expand Down
22 changes: 11 additions & 11 deletions libcrux-ml-dsa/benches/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,43 +129,43 @@ macro_rules! bench_group_libcrux {
}};
}

#[cfg(not(all(target_os = "macos", target_arch = "x86_64")))]
#[macro_export]
macro_rules! bench_group_pqclean {
($variant:literal, $mod:ident) => {{
bench!("(pqclean) KeyGen", $variant, (), |()| {}, |()| {
pqcrypto_dilithium::$mod::keypair()
pqcrypto_mldsa::$mod::keypair()
});
bench!(
"(pqclean) Sign",
$variant,
(),
|()| {
let (_, sk) = pqcrypto_dilithium::$mod::keypair();
let (_, sk) = pqcrypto_mldsa::$mod::keypair();
let message = bench_utils::random_array::<1023>();
(sk, message)
},
|(sk, message): (pqcrypto_dilithium::$mod::SecretKey, [u8; 1023])| {
let _ = pqcrypto_dilithium::$mod::detached_sign(&message, &sk);
|(sk, message): (pqcrypto_mldsa::$mod::SecretKey, [u8; 1023])| {
let _ = pqcrypto_mldsa::$mod::detached_sign(&message, &sk);
}
);
bench!(
"(pqclean) Verify",
$variant,
(),
|()| {
let (vk, sk) = pqcrypto_dilithium::$mod::keypair();
let (vk, sk) = pqcrypto_mldsa::$mod::keypair();
let message = bench_utils::random_array::<1023>();
let signature = pqcrypto_dilithium::$mod::detached_sign(&message, &sk);
let signature = pqcrypto_mldsa::$mod::detached_sign(&message, &sk);
(vk, message, signature)
},
|(vk, message, signature): (
pqcrypto_dilithium::$mod::PublicKey,
pqcrypto_mldsa::$mod::PublicKey,
[u8; 1023],
pqcrypto_dilithium::$mod::DetachedSignature
pqcrypto_mldsa::$mod::DetachedSignature
)| {
let _ =
pqcrypto_dilithium::$mod::verify_detached_signature(&signature, &message, &vk)
.unwrap();
let _ = pqcrypto_mldsa::$mod::verify_detached_signature(&signature, &message, &vk)
.unwrap();
}
);
}};
Expand Down
6 changes: 3 additions & 3 deletions libcrux-ml-dsa/benches/manual44.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use libcrux_ml_dsa::{
KEY_GENERATION_RANDOMNESS_SIZE, SIGNING_RANDOMNESS_SIZE,
};

use pqcrypto_dilithium;

mod bench_utils;

fn main() {
Expand All @@ -28,5 +26,7 @@ fn main() {
MLDSA44KeyPair,
MLDSA44Signature
);
bench_group_pqclean!("44", dilithium2);

#[cfg(not(all(target_os = "macos", target_arch = "x86_64")))]
bench_group_pqclean!("44", mldsa44);
}
6 changes: 3 additions & 3 deletions libcrux-ml-dsa/benches/manual65.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use libcrux_ml_dsa::{
KEY_GENERATION_RANDOMNESS_SIZE, SIGNING_RANDOMNESS_SIZE,
};

use pqcrypto_dilithium;

mod bench_utils;

fn main() {
Expand All @@ -28,5 +26,7 @@ fn main() {
MLDSA65KeyPair,
MLDSA65Signature
);
bench_group_pqclean!("65", dilithium3);

#[cfg(not(all(target_os = "macos", target_arch = "x86_64")))]
bench_group_pqclean!("65", mldsa65);
}
6 changes: 3 additions & 3 deletions libcrux-ml-dsa/benches/manual87.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use libcrux_ml_dsa::{
KEY_GENERATION_RANDOMNESS_SIZE, SIGNING_RANDOMNESS_SIZE,
};

use pqcrypto_dilithium;

mod bench_utils;

fn main() {
Expand All @@ -28,5 +26,7 @@ fn main() {
MLDSA87KeyPair,
MLDSA87Signature
);
bench_group_pqclean!("87", dilithium5);

#[cfg(not(all(target_os = "macos", target_arch = "x86_64")))]
bench_group_pqclean!("87", mldsa87);
}
42 changes: 24 additions & 18 deletions libcrux-ml-dsa/benches/ml-dsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ pub fn comparisons_key_generation(c: &mut Criterion) {
})
});

#[cfg(not(all(target_os = "macos", target_arch = "x86_64")))]
group.bench_function("pqclean (internal random)", move |b| {
b.iter(|| {
let (_, _) = pqcrypto_dilithium::dilithium3::keypair();
let (_, _) = pqcrypto_mldsa::mldsa65::keypair();
})
});
}
Expand All @@ -46,12 +47,15 @@ pub fn comparisons_signing(c: &mut Criterion) {
})
});

let (_, sk) = pqcrypto_dilithium::dilithium3::keypair();
group.bench_function("pqclean (internal random)", move |b| {
b.iter(|| {
let _ = pqcrypto_dilithium::dilithium3::detached_sign(&message, &sk);
})
});
#[cfg(not(all(target_os = "macos", target_arch = "x86_64")))]
{
let (_, sk) = pqcrypto_mldsa::mldsa65::keypair();
group.bench_function("pqclean (internal random)", move |b| {
b.iter(|| {
let _ = pqcrypto_mldsa::mldsa65::detached_sign(&message, &sk);
})
});
}
}

pub fn comparisons_verification(c: &mut Criterion) {
Expand All @@ -76,17 +80,19 @@ pub fn comparisons_verification(c: &mut Criterion) {
})
});

let (vk, sk) = pqcrypto_dilithium::dilithium3::keypair();
let signature = pqcrypto_dilithium::dilithium3::detached_sign(&message, &sk);

group.bench_function("pqclean", move |b| {
b.iter(|| {
let _ = pqcrypto_dilithium::dilithium3::verify_detached_signature(
&signature, &message, &vk,
)
.unwrap();
})
});
#[cfg(not(all(target_os = "macos", target_arch = "x86_64")))]
{
let (vk, sk) = pqcrypto_mldsa::mldsa65::keypair();
let signature = pqcrypto_mldsa::mldsa65::detached_sign(&message, &sk);

group.bench_function("pqclean", move |b| {
b.iter(|| {
let _ =
pqcrypto_mldsa::mldsa65::verify_detached_signature(&signature, &message, &vk)
.unwrap();
})
});
}
}

pub fn comparisons(c: &mut Criterion) {
Expand Down
Loading