#![allow(incomplete_features)] #![feature(generic_const_exprs)] #![feature(const_trait_impl)] use criterion::{black_box, criterion_group, criterion_main, Criterion}; use rand::SeedableRng; use cryptix_blmq::{BLMQ, fr::FrElement}; use sha2::Digest; const SEED: [u8; 32] = [ 1, 0, 52, 0, 0, 0, 0, 0, 1, 0, 10, 0, 22, 32, 0, 0, 2, 0, 55, 49, 0, 11, 0, 0, 3, 0, 0, 0, 0, 0, 2, 92, ]; const ID: &[u8] = b"M4tsuri"; const MSG: &[u8] = b"1145141919810"; fn bench_blmq(c: &mut Criterion) { // c.bench_function("bench ring multiplication", |b| { // let x: Element = bigint!(U256, "551e8e3d059337e403273bb5cfbe18ec3b07f6eea014b7e32829a88101a76648").into(); // let y: Element = bigint!(U256, "0f44148ca6427affe2d16f7402ad1da381fb3002db6aa1c0b414a52e715abe88").into(); // b.iter(|| black_box(x * y)) // }); c.bench_function("bench fpelement rand", |b| { let rng = rand_chacha::ChaCha12Rng::from_seed(SEED); b.iter(|| { let mut rng = rng.clone(); black_box(FrElement::rand(&mut rng)) }) }); c.bench_function("bench hash", |b| { b.iter(|| { black_box(sha2::Sha256::digest(MSG)) }) }); c.bench_function("bench blmq init", |b| { let rng = rand_chacha::ChaCha12Rng::from_seed(SEED); b.iter(|| { let rng = rng.clone(); black_box(BLMQ::new(rng)) }) }); c.bench_function("bench blmq extract", |b| { let rng = rand_chacha::ChaCha12Rng::from_seed(SEED); let blmq = BLMQ::new(rng); b.iter(|| black_box(blmq.extract(ID))) }); c.bench_function("bench blmq sign", |b| { let rng = rand_chacha::ChaCha12Rng::from_seed(SEED); let mut blmq = BLMQ::new(rng); let (_, sk) = blmq.extract(ID); b.iter(|| black_box(blmq.sign(sk, MSG))) }); c.bench_function("bench blmq verify", |b| { let rng = rand_chacha::ChaCha12Rng::from_seed(SEED); let mut blmq = BLMQ::new(rng); let (_pk, sk) = blmq.extract(ID); let sig = blmq.sign(sk, MSG); b.iter(|| black_box(blmq.verify(&sig, ID, MSG))) }); } criterion_group!(benches, bench_blmq); criterion_main!(benches);