curve25519-dalek-source/benches/x25519.rs
pinkforest(she/her) 02a5ce20ca
Add getrandom (#118)
* Add getrandom to bring convenience random init functions

* Fix doc name

* Rename new to random_from_rng

* Deprecate new() in favor of random_from_rng()

* Simplify constructors documentation

Co-authored-by: Ciprian Dorin Craciun <ciprian@volution.ro>
2023-03-21 01:40:51 -04:00

41 lines
1 KiB
Rust

// -*- mode: rust; -*-
//
// This file is part of x25519-dalek.
// Copyright (c) 2017-2019 isis agora lovecruft
// Copyright (c) 2019 DebugSteven
// See LICENSE for licensing information.
//
// Authors:
// - isis agora lovecruft <isis@patternsinthevoid.net>
// - DebugSteven <debugsteven@gmail.com>
//! Benchmark the Diffie-Hellman operation.
use criterion::{criterion_group, criterion_main, Criterion};
use rand_core::OsRng;
use x25519_dalek::EphemeralSecret;
use x25519_dalek::PublicKey;
fn bench_diffie_hellman(c: &mut Criterion) {
let bob_secret = EphemeralSecret::random_from_rng(OsRng);
let bob_public = PublicKey::from(&bob_secret);
c.bench_function("diffie_hellman", move |b| {
b.iter_with_setup(
|| EphemeralSecret::random_from_rng(OsRng),
|alice_secret| alice_secret.diffie_hellman(&bob_public),
)
});
}
criterion_group! {
name = x25519_benches;
config = Criterion::default();
targets =
bench_diffie_hellman,
}
criterion_main! {
x25519_benches,
}