// SPDX-FileCopyrightText: 2023-2024 eaon // SPDX-License-Identifier: AGPL-3.0-or-later use criterion::{criterion_group, criterion_main, Criterion}; use rand_core::OsRng; use ecdh_omr::*; pub fn x25519_blinding(c: &mut Criterion) { let secret = x25519_dalek::StaticSecret::random_from_rng(&mut OsRng); let public = x25519_dalek::PublicKey::from(&secret); c.bench_function("x25519_blinding", move |b| { b.iter(|| public.blind(&mut OsRng)) }); } pub fn p256_blinding(c: &mut Criterion) { let secret = p256::SecretKey::random(&mut OsRng); let public = secret.public_key(); c.bench_function("p256_blinding", move |b| { b.iter(|| public.blind(&mut OsRng)) }); } pub fn x25519_random_decoy(c: &mut Criterion) { c.bench_function("x25519_random_decoy", move |b| { b.iter(|| x25519_dalek::PublicKey::random_decoy(&mut OsRng)) }); } pub fn p256_random_decoy(c: &mut Criterion) { c.bench_function("p256_random_decoy", move |b| { b.iter(|| p256::PublicKey::random_decoy(&mut OsRng)) }); } pub fn hint_x25519_chacha20poly1305_random_decoy(c: &mut Criterion) { c.bench_function("hint_x25519_chacha20poly1305_random_decoy", move |b| { b.iter(|| Hint::::random_decoy(&mut OsRng)) }); } pub fn hint_p256_aes128_ocb3_random_decoy(c: &mut Criterion) { c.bench_function("hint_p256_aes128_ocb3_random_decoy", move |b| { b.iter(|| { Hint::, ocb3::Ocb3>::random_decoy(&mut OsRng) }) }); } pub fn hint_x25519_chacha20poly1305_new(c: &mut Criterion) { let secret = x25519_dalek::StaticSecret::random_from_rng(&mut OsRng); let public = x25519_dalek::PublicKey::from(&secret); let blinded = public.blind(&mut OsRng); c.bench_function("hint_x25519_chacha20poly1305_new", move |b| { b.iter(|| { Hint::::new( &blinded, &[0u8; 32], &mut OsRng, ) }) }); } pub fn hint_p256_aes128_ocb3_new(c: &mut Criterion) { let secret = p256::SecretKey::random(&mut OsRng); let public = secret.public_key(); let blinded = public.blind(&mut OsRng); c.bench_function("hint_p256_aes128_ocb3_new", move |b| { b.iter(|| { Hint::, ocb3::Ocb3>::new( &blinded, &[0u8; 32], &mut OsRng, ) }) }); } pub fn hint_x25519_aes128_ocb3_new(c: &mut Criterion) { let secret = x25519_dalek::StaticSecret::random_from_rng(&mut OsRng); let public = x25519_dalek::PublicKey::from(&secret); let blinded = public.blind(&mut OsRng); c.bench_function("hint_x25519_aes128_ocb3_new", move |b| { b.iter(|| Hint::>::new(&blinded, &[0u8; 32], &mut OsRng)) }); } criterion_group!( ecdh_omr_benches, x25519_blinding, p256_blinding, x25519_random_decoy, p256_random_decoy, hint_x25519_chacha20poly1305_random_decoy, hint_p256_aes128_ocb3_random_decoy, hint_x25519_chacha20poly1305_new, hint_p256_aes128_ocb3_new, hint_x25519_aes128_ocb3_new, ); criterion_main!(ecdh_omr_benches);