more realistic benchmarks

This commit is contained in:
Neemek 2025-11-07 09:08:30 +01:00
parent d21139d9ff
commit 7debf5e213
Signed by: neemek
GPG key ID: 84FFE4D7D40AB25E

View file

@ -9,7 +9,7 @@ mod benches {
use test::{Bencher, black_box}; use test::{Bencher, black_box};
#[bench] #[bench]
fn diffie_hellman(b: &mut Bencher) { fn dh_shared_key_derivation(b: &mut Bencher) {
let a = Secret::from(U256::from_u32(123456789)); let a = Secret::from(U256::from_u32(123456789));
let p = Public::from(&Secret::from(U256::from_u64(987654321))); let p = Public::from(&Secret::from(U256::from_u64(987654321)));
@ -27,7 +27,7 @@ mod benches {
#[bench] #[bench]
fn montgomery_point_add(b: &mut Bencher) { fn montgomery_point_add(b: &mut Bencher) {
let p = CURVE_25519.point(U256::from_u32(123456789)); let p = CURVE_25519.point(clamp_u256(U256::from_u32(123456789)));
let q = p.double(); let q = p.double();
b.iter(|| black_box(p.add(&q, &p))) b.iter(|| black_box(p.add(&q, &p)))
@ -35,21 +35,22 @@ mod benches {
#[bench] #[bench]
fn montgomery_point_double(b: &mut Bencher) { fn montgomery_point_double(b: &mut Bencher) {
let p = CURVE_25519.point(U256::from_u32(123456789)); let p = CURVE_25519.point(clamp_u256(U256::from_u32(123456789)));
b.iter(|| black_box(p.double())) b.iter(|| black_box(p.double()))
} }
#[bench] #[bench]
fn montgomery_ladder(b: &mut Bencher) { fn montgomery_ladder(b: &mut Bencher) {
let p = CURVE_25519.point(U256::from_u32(123456789)); let p = CURVE_25519.point(clamp_u256(U256::from_u32(123456789)));
let v = clamp_u256(U256::from_u64(987654321));
b.iter(|| black_box(p.ladder(&clamp_u256(U256::from_u64(987654321))))) b.iter(|| black_box(p.ladder(&v)))
} }
#[bench] #[bench]
fn constant_time_montgomery_ladder(b: &mut Bencher) { fn constant_time_montgomery_ladder(b: &mut Bencher) {
let p = CURVE_25519.point(U256::from_u32(123456789)); let p = CURVE_25519.point(clamp_u256(U256::from_u32(123456789)));
b.iter(|| black_box(p.ct_ladder(&clamp_u256(U256::from_u64(987654321))))) b.iter(|| black_box(p.ct_ladder(&clamp_u256(U256::from_u64(987654321)))))
} }