From e3189454dd22ccd724b8caba6e49f3fae963292e Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Wed, 6 Dec 2023 14:06:55 +0100 Subject: add first benchmarks for bbg --- benches/bbg.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 benches/bbg.rs (limited to 'benches') 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); -- cgit v1.2.3