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