curve25519-dalek-source/benches/x25519.rs

48 lines
1.1 KiB
Rust
Raw Normal View History

// -*- mode: rust; -*-
//
// This file is part of x25519-dalek.
2019-01-12 23:34:49 +00:00
// Copyright (c) 2017-2019 isis agora lovecruft
// Copyright (c) 2019 DebugSteven
// See LICENSE for licensing information.
//
// Authors:
2019-01-12 23:34:49 +00:00
// - isis agora lovecruft <isis@patternsinthevoid.net>
// - DebugSteven <debugsteven@gmail.com>
//! Benchmark the Diffie-Hellman operation.
#[macro_use]
extern crate criterion;
2018-11-10 21:17:19 +00:00
extern crate curve25519_dalek;
extern crate rand_core;
extern crate x25519_dalek;
use criterion::Criterion;
use rand_core::OsRng;
use x25519_dalek::EphemeralSecret;
use x25519_dalek::PublicKey;
fn bench_diffie_hellman(c: &mut Criterion) {
let bob_secret = EphemeralSecret::new(&mut OsRng);
2019-02-16 18:17:15 +00:00
let bob_public = PublicKey::from(&bob_secret);
c.bench_function("diffie_hellman", move |b| {
b.iter_with_setup(
|| EphemeralSecret::new(&mut OsRng),
2018-12-16 18:30:32 +00:00
|alice_secret| alice_secret.diffie_hellman(&bob_public),
)
});
}
criterion_group! {
name = x25519_benches;
config = Criterion::default();
targets =
bench_diffie_hellman,
}
criterion_main! {
x25519_benches,
}