use crypto_bigint::{ modular::{BernsteinYangInverter, ConstMontyParams}, Odd, PrecomputeInverter, Uint, }; use csidh::{CsidhParams, PrivateKey, PublicKey}; use iai_callgrind::{black_box, library_benchmark, library_benchmark_group, main}; use rand::Rng; fn private_key>( params: CsidhParams, ) -> PrivateKey { let mut path = [0; N]; for element in path.iter_mut() { *element = rand::thread_rng().gen_range(0..=10); } PrivateKey::new(params, path) } #[library_benchmark] #[bench::random(private_key(CsidhParams::CSIDH_512))] fn public_key_1< const SAT_LIMBS: usize, const N: usize, MOD: ConstMontyParams, const UNSAT_LIMBS: usize, >( private_key: PrivateKey, ) where Odd>: PrecomputeInverter< Inverter = BernsteinYangInverter, Output = Uint, >, { let _ = PublicKey::from(black_box(private_key), &mut rand::thread_rng()); } #[library_benchmark] #[bench::random(private_key(CsidhParams::CSIDH_512))] fn public_key_2< const SAT_LIMBS: usize, const N: usize, MOD: ConstMontyParams, const UNSAT_LIMBS: usize, >( private_key: PrivateKey, ) where Odd>: PrecomputeInverter< Inverter = BernsteinYangInverter, Output = Uint, >, { let _ = PublicKey::from(black_box(private_key), &mut rand::thread_rng()); } #[library_benchmark] #[bench::random(private_key(CsidhParams::CSIDH_512))] fn public_key_3< const SAT_LIMBS: usize, const N: usize, MOD: ConstMontyParams, const UNSAT_LIMBS: usize, >( private_key: PrivateKey, ) where Odd>: PrecomputeInverter< Inverter = BernsteinYangInverter, Output = Uint, >, { let _ = PublicKey::from(black_box(private_key), &mut rand::thread_rng()); } library_benchmark_group!( name = public_key_group; benchmarks = public_key_1, public_key_2, public_key_3, ); main!(library_benchmark_groups = public_key_group);