diff options
-rw-r--r-- | Cargo.toml | 8 | ||||
-rw-r--r-- | benches/bbg.rs | 41 |
2 files changed, 49 insertions, 0 deletions
@@ -20,3 +20,11 @@ rand = "0.8.5" serde = { version = "1.0.193", features = ["derive"] } sha3 = "0.10.8" thiserror = "1.0.50" + +[dev-dependencies] +criterion = "0.5.1" +rand_chacha = "0.3.1" + +[[bench]] +name = "bbg" +harness = false diff --git a/benches/bbg.rs b/benches/bbg.rs new file mode 100644 index 0000000..dfc1e6c --- /dev/null +++ b/benches/bbg.rs @@ -0,0 +1,41 @@ +use criterion::{criterion_group, criterion_main, Criterion}; +use rand::{Rng, SeedableRng}; +use rand_chacha::ChaChaRng; + +use hohibe::hibe::{Hibe, BonehBoyenGoh}; + +fn rng() -> impl Rng { + ChaChaRng::from_seed([0; 32]) +} + +fn setup(c: &mut Criterion) { + let mut rng = rng(); + let bbg = BonehBoyenGoh::new(32); + c.bench_function("BonehBoyenGoh::setup(32)", |b| { + b.iter(|| bbg.setup(&mut rng)); + }); +} + +fn generate_key(c: &mut Criterion) { + let mut rng = rng(); + let bbg = BonehBoyenGoh::new(32); + let identity = &[0u32.into(), 1u32.into(), 2u32.into()]; + let (public_key, master_key) = bbg.setup(&mut rng).unwrap(); + c.bench_function("BonehBoyenGoh::generate_key(32)", |b| { + b.iter(|| bbg.generate_key(&mut rng, &public_key, &master_key, identity).unwrap()); + }); +} + +fn derive_key(c: &mut Criterion) { + let mut rng = rng(); + let bbg = BonehBoyenGoh::new(32); + let identity = &[0u32.into(), 1u32.into(), 2u32.into()]; + let (public_key, master_key) = bbg.setup(&mut rng).unwrap(); + let key = bbg.generate_key(&mut rng, &public_key, &master_key, identity).unwrap(); + c.bench_function("BonehBoyenGoh::derive_key(32)", |b| { + b.iter(|| bbg.derive_key(&mut rng, &public_key, &key, identity, &3u32.into()).unwrap()); + }); +} + +criterion_group!(benches, setup, generate_key, derive_key); +criterion_main!(benches); |