export more, benchmarks

This commit is contained in:
Neemek 2025-10-09 21:28:56 +02:00
parent 2c7a005d7c
commit 321635a80a
4 changed files with 71 additions and 3 deletions

64
bench/src/lib.rs Normal file
View file

@ -0,0 +1,64 @@
#![feature(test)]
extern crate test;
mod benches {
use test::{black_box, Bencher};
use diffie_hellman::{clamp_u256, Public, Secret, CURVE_25519, U256};
#[bench]
fn diffie_hellman(b: &mut Bencher) {
let a = Secret::from(U256::from_u32(123456789));
let p = Public::from(&Secret::from(U256::from_u64(987654321)));
b.iter(|| {
black_box(a.diffie_hellman(&p));
})
}
#[bench]
fn public_key_derivation(b: &mut Bencher) {
let a = Secret::from(U256::from_u32(123456789));
b.iter(|| {
black_box(Public::from(&a))
})
}
#[bench]
fn montgomery_point_add(b: &mut Bencher) {
let p = CURVE_25519.point(U256::from_u32(123456789));
let q = p.double();
b.iter(|| {
black_box(p.add(q, p))
})
}
#[bench]
fn montgomery_point_double(b: &mut Bencher) {
let p = CURVE_25519.point(U256::from_u32(123456789));
b.iter(|| {
black_box(p.double())
})
}
#[bench]
fn montgomery_ladder(b: &mut Bencher) {
let p = CURVE_25519.point(U256::from_u32(123456789));
b.iter(|| {
black_box(p.ladder(clamp_u256(U256::from_u64(987654321))))
})
}
#[bench]
fn constant_time_montgomery_ladder(b: &mut Bencher) {
let p = CURVE_25519.point(U256::from_u32(123456789));
b.iter(|| {
black_box(p.ct_ladder(clamp_u256(U256::from_u64(987654321))))
})
}
}