mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-04 20:24:10 +00:00
Prior to a final stable release of the @RustCrypto dependencies used by the dalek crates, we are going to target `rand_core` v0.10. This updates the `rand` and `rand_core` dependencies as well as the aforementioned @RustCrypto dependencies to be compatible with `rand_core` v0.10, which incurred a few API changes: - `rand_core` no longer includes `OsRng`, so this replaces the `os_rng` features with `getrandom` features (same thing we did for @RustCrypto) which uses the `getrandom` crate directly - For `dev-dependencies` it just migrates straight to `rand`, replacing `rand_chacha` with the `chacha` feature of `rand` (which pulls in `chacha20`), and sourcing `OsRng` from `rand`, its new home (for now) This PR also switches to using the `rustcrypto-ff`/`rustcrypto-group` crates (hopefully temporary) which are forks of `ff` and `group` which have crate releases that have been updated to use `rand_core` v0.10.0 prereleases.
41 lines
1.1 KiB
Rust
41 lines
1.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, criterion_group, criterion_main};
|
|
|
|
use rand::{TryRngCore, rngs::OsRng};
|
|
|
|
use x25519_dalek::EphemeralSecret;
|
|
use x25519_dalek::PublicKey;
|
|
|
|
fn bench_diffie_hellman(c: &mut Criterion) {
|
|
let bob_secret = EphemeralSecret::random_from_rng(&mut OsRng.unwrap_err());
|
|
let bob_public = PublicKey::from(&bob_secret);
|
|
|
|
c.bench_function("diffie_hellman", move |b| {
|
|
b.iter_with_setup(
|
|
|| EphemeralSecret::random_from_rng(&mut OsRng.unwrap_err()),
|
|
|alice_secret| alice_secret.diffie_hellman(&bob_public),
|
|
)
|
|
});
|
|
}
|
|
|
|
criterion_group! {
|
|
name = x25519_benches;
|
|
config = Criterion::default();
|
|
targets =
|
|
bench_diffie_hellman,
|
|
}
|
|
criterion_main! {
|
|
x25519_benches,
|
|
}
|