ptrcports/alpine/wireguard-vanity-address/0003-update-benchmarks-to-new-scheme.patch

114 lines
4.1 KiB
Diff
Raw Normal View History

From d6473b2d99351fd5ec773dde7037e7fdd0cce18a Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@lothar.com>
Date: Tue, 3 Mar 2020 21:12:01 -0800
Subject: [PATCH 3/5] update benchmarks to new scheme
---
benches/keygen.rs | 59 ++++++++++++++++++++++++++---------------------
1 file changed, 33 insertions(+), 26 deletions(-)
diff --git a/benches/keygen.rs b/benches/keygen.rs
index a50062e..00dcc55 100644
--- a/benches/keygen.rs
+++ b/benches/keygen.rs
@@ -1,63 +1,70 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
-use base64;
+use curve25519_dalek::{
+ constants::ED25519_BASEPOINT_POINT, edwards::EdwardsPoint, montgomery::MontgomeryPoint,
+ scalar::Scalar,
+};
use rand_core::OsRng;
-use x25519_dalek::{PublicKey, StaticSecret};
-use wireguard_vanity_lib::trial;
+use wireguard_vanity_lib::{make_check_predicate, Seed};
fn b1_point_generation(c: &mut Criterion) {
- c.bench_function("b1_point_generation", |b| {
- b.iter(|| StaticSecret::new(&mut OsRng))
- });
+ let seed = Seed::generate();
+ let mut scan = seed.scan();
+ c.bench_function("b1_point_generation", |b| b.iter(|| scan.next()));
}
fn b2a_point_conversion(c: &mut Criterion) {
- let private = StaticSecret::new(&mut OsRng);
+ let ed_point: EdwardsPoint = Scalar::random(&mut OsRng) * ED25519_BASEPOINT_POINT;
c.bench_function("b2a_point_conversion", |b| {
- b.iter(|| PublicKey::from(&private))
+ b.iter(|| ed_point.to_montgomery())
});
}
fn b2b_point_to_bytes(c: &mut Criterion) {
- let private = StaticSecret::new(&mut OsRng);
- let public = PublicKey::from(&private);
- c.bench_function("b2b_point_to_bytes", |b| b.iter(|| public.as_bytes()));
+ let ed_point: EdwardsPoint = Scalar::random(&mut OsRng) * ED25519_BASEPOINT_POINT;
+ let mt_point: MontgomeryPoint = ed_point.to_montgomery();
+ c.bench_function("b2b_point_to_bytes", |b| b.iter(|| mt_point.as_bytes()));
}
fn b2c_bytes_to_base64(c: &mut Criterion) {
- let private = StaticSecret::new(&mut OsRng);
- let public = PublicKey::from(&private);
- let public_bytes = public.as_bytes();
+ let ed_point: EdwardsPoint = Scalar::random(&mut OsRng) * ED25519_BASEPOINT_POINT;
+ let mt_point: MontgomeryPoint = ed_point.to_montgomery();
+ let bytes = mt_point.as_bytes();
c.bench_function("b2c_bytes_to_base64", |b| {
- b.iter(|| base64::encode(black_box(&public_bytes)))
+ b.iter(|| base64::encode(black_box(&bytes)))
});
}
fn b2d_base64_contains(c: &mut Criterion) {
- let private = StaticSecret::new(&mut OsRng);
- let public = PublicKey::from(&private);
- let public_b64 = base64::encode(public.as_bytes());
+ let ed_point: EdwardsPoint = Scalar::random(&mut OsRng) * ED25519_BASEPOINT_POINT;
+ let mt_point: MontgomeryPoint = ed_point.to_montgomery();
+ let bytes = mt_point.as_bytes();
+ let public_b64 = base64::encode(bytes);
c.bench_function("b2d_base64_contains", |b| {
b.iter(|| public_b64[0..10].to_ascii_lowercase().contains("****"))
});
}
fn b2e_total_point_checking(c: &mut Criterion) {
+ let check = make_check_predicate("****", 0, 10);
+ let seed = Seed::generate();
+ let mut scan = seed.scan();
+ let (_count, point) = scan.next().unwrap();
c.bench_function("b2e_total_point_checking", |b| {
- b.iter(|| {
- let private = StaticSecret::new(&mut OsRng);
- let public = PublicKey::from(&private);
- let public_b64 = base64::encode(public.as_bytes());
- public_b64[0..10].to_ascii_lowercase().contains("****")
- })
+ b.iter(|| check(black_box(&point)))
});
}
fn b3_point_generation_and_checking(c: &mut Criterion) {
- let prefix: &str = "****";
+ let check = make_check_predicate("****", 0, 10);
+ let seed = Seed::generate();
+ let mut scan = seed.scan();
c.bench_function("b3_point_generation_and_checking", |b| {
- b.iter(|| trial(&prefix, 0, 10))
+ b.iter(|| {
+ let (_count, point) = scan.next().unwrap();
+ check(&point)
+ })
});
}
--
2.36.0