-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move benchmarks into a separate crate. (#107)
- Loading branch information
1 parent
fd3b306
commit 97a40c3
Showing
13 changed files
with
282 additions
and
57 deletions.
There are no files selected for viewing
This file contains 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 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 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,62 @@ | ||
[package] | ||
name = "benchmarks" | ||
version.workspace = true | ||
authors.workspace = true | ||
license.workspace = true | ||
homepage.workspace = true | ||
edition.workspace = true | ||
repository.workspace = true | ||
readme.workspace = true | ||
|
||
[dependencies] | ||
|
||
[dev-dependencies] | ||
libcrux = { path = "../", features = ["rand"] } | ||
rand = { version = "0.8" } | ||
rand_core = { version = "0.6" } | ||
# Benchmarking "RustCrypto" | ||
chacha20poly1305 = "0.10" | ||
sha2 = "0.10" | ||
x25519-dalek-ng = "1.1" | ||
sha3 = "0.10" | ||
p256 = { version = "0.13", features = ["ecdh"] } | ||
# Benchmarking "Ring" | ||
ring = "0.17" | ||
|
||
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] | ||
criterion = "0.5" | ||
# libcrux-pqclean = { version = "0.0.2-pre.1", path = "sys/pqclean" } | ||
|
||
# Benchmarking "OpenSSL" | ||
# XXX: We don't do this for Windows or wasm right now. | ||
# x86 is usally a cross compilation where this won't work either. | ||
[target.'cfg(all(not(windows), not(target_arch = "wasm32"), not(target_arch = "x86")))'.dev-dependencies] | ||
openssl = "0.10" | ||
|
||
[[bench]] | ||
name = "sha2" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "sha3" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "x25519" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "p256" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "aead" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "hpke" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "drbg" | ||
harness = false |
File renamed without changes.
This file contains 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 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 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 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,121 @@ | ||
use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; | ||
use libcrux::ecdh; | ||
|
||
mod util; | ||
use rand_core::OsRng; | ||
|
||
fn derive(c: &mut Criterion) { | ||
// Comparing libcrux performance for different payload sizes and other implementations. | ||
let mut group = c.benchmark_group("P256 derive"); | ||
|
||
group.bench_function("libcrux", |b| { | ||
b.iter_batched( | ||
|| { | ||
let (_, pk1) = ecdh::key_gen(ecdh::Algorithm::P256, &mut OsRng).unwrap(); | ||
let (sk2, _) = ecdh::key_gen(ecdh::Algorithm::P256, &mut OsRng).unwrap(); | ||
(pk1, sk2) | ||
}, | ||
|(pk1, sk2)| { | ||
let _zz = ecdh::derive(ecdh::Algorithm::P256, &pk1, &sk2).unwrap(); | ||
}, | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
|
||
group.bench_function("Ring", |b| { | ||
use ring::{agreement, rand::SystemRandom}; | ||
|
||
b.iter_batched( | ||
|| { | ||
let rng = SystemRandom::new(); | ||
let sk1 = | ||
agreement::EphemeralPrivateKey::generate(&agreement::ECDH_P256, &rng).unwrap(); | ||
let pk1 = sk1.compute_public_key().unwrap(); | ||
let sk2 = | ||
agreement::EphemeralPrivateKey::generate(&agreement::ECDH_P256, &rng).unwrap(); | ||
|
||
(pk1, sk2) | ||
}, | ||
|(pk1, sk2)| { | ||
let _zz: Result<Vec<u8>, ring::error::Unspecified> = agreement::agree_ephemeral( | ||
sk2, | ||
&agreement::UnparsedPublicKey::new(&agreement::ECDH_P256, pk1), | ||
|k| Ok(k.to_vec()), | ||
) | ||
.unwrap(); | ||
}, | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
|
||
group.bench_function("RustCrypto", |b| { | ||
use p256::{ecdh::EphemeralSecret, PublicKey}; | ||
|
||
b.iter_batched( | ||
|| { | ||
let sk1 = EphemeralSecret::random(&mut OsRng); | ||
let pk1 = PublicKey::from(&sk1); | ||
let sk2 = EphemeralSecret::random(&mut OsRng); | ||
(pk1, sk2) | ||
}, | ||
|(pk1, sk2)| { | ||
let _zz = sk2.diffie_hellman(&pk1); | ||
}, | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
} | ||
|
||
fn secret_to_public(c: &mut Criterion) { | ||
// Comparing libcrux performance for different payload sizes and other implementations. | ||
let mut group = c.benchmark_group("P256 secret to public"); | ||
|
||
group.bench_function("libcrux", |b| { | ||
b.iter_batched( | ||
|| { | ||
let (sk, _) = ecdh::key_gen(ecdh::Algorithm::P256, &mut OsRng).unwrap(); | ||
sk | ||
}, | ||
|sk| { | ||
let _pk = ecdh::secret_to_public(ecdh::Algorithm::P256, &sk).unwrap(); | ||
}, | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
|
||
group.bench_function("Ring", |b| { | ||
use ring::{agreement, rand::SystemRandom}; | ||
|
||
b.iter_batched( | ||
|| { | ||
let rng = SystemRandom::new(); | ||
let sk = | ||
agreement::EphemeralPrivateKey::generate(&agreement::ECDH_P256, &rng).unwrap(); | ||
|
||
sk | ||
}, | ||
|sk| { | ||
let _pk = sk.compute_public_key().unwrap(); | ||
}, | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
|
||
group.bench_function("RustCrypto", |b| { | ||
use p256::{ecdh::EphemeralSecret, PublicKey}; | ||
|
||
b.iter_batched( | ||
|| { | ||
let sk = EphemeralSecret::random(&mut OsRng); | ||
sk | ||
}, | ||
|sk| { | ||
let _pk = PublicKey::from(&sk); | ||
}, | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, derive, secret_to_public); | ||
criterion_main!(benches); |
This file contains 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 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
File renamed without changes.
Oops, something went wrong.