* Remove unnecessary constraints on hash * Remove unnecessary `Result` on `KeyPair::generate_random` * Fix de-serialization issue on `Ke1State` * Fix rustfmt * Remove allocations in `envelope` * Run Clippy for tests and rustdoc lints too * Fix `Debug` implementation * Fix missing constraints on `ClientRegistration` * Fix de-serialization * Pin temporary dependency * Update dependencies * Replace macro with derive-where * Remove unnecessary installation of Rust components * Improve macro naming * Implement `Copy`, `Debug`, `Ord` and `PartialOrd` for high-level items * Add `rust-version` field to `Cargo.toml` * Remove unnecessary allocations * Fix MSRV * Fix no_std * Remove unnecessary allocations * Remove unnecessary allocations * Not importing items from voprf helps readability * Fix rustdoc * Remove unnecessary allocations * Remove unnecessary allocations * Replace `Vec` from `diffie_hellman` with `GenericArray` * Remove unnecessary allocations * Remove unnecessary allocations * Remove `cfg(feature = bench)` guard for `missing_docs` * Fix documentation * Remove all remaining allocations from `KeyExchange` * Improve type-safety * Remove all remaining allocations in `keypair` * Remove last remaining allocations except `NonVerifiableClient` input * Remove base64 encoding in Serde implementation * Remove unnecessary Serde `alloc` feature * Make curve25519-dalek optional * Rename `serialize` crate feature to `serde` * Switch `KeGroup` implementations to higher-level libraries - Fixes missing clamping in X25519 - X25519 is now a separate crate feature * Fix typo
347 lines
11 KiB
Rust
347 lines
11 KiB
Rust
// Copyright (c) Facebook, Inc. and its affiliates.
|
|
//
|
|
// This source code is licensed under both the MIT license found in the
|
|
// LICENSE-MIT file in the root directory of this source tree and the Apache
|
|
// License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
|
// of this source tree.
|
|
|
|
#[macro_use]
|
|
extern crate criterion;
|
|
|
|
use criterion::Criterion;
|
|
use opaque_ke::*;
|
|
use rand::rngs::OsRng;
|
|
|
|
#[cfg(feature = "ristretto255_u64")]
|
|
static SUFFIX: &str = "ristretto255_u64";
|
|
#[cfg(feature = "ristretto255_u32")]
|
|
static SUFFIX: &str = "ristretto255_u32";
|
|
#[cfg(feature = "ristretto255_fiat_u64")]
|
|
static SUFFIX: &str = "ristretto255_fiat_u64";
|
|
#[cfg(feature = "ristretto255_fiat_u32")]
|
|
static SUFFIX: &str = "ristretto255_fiat_u32";
|
|
#[cfg(all(not(feature = "ristretto255"), feature = "p256"))]
|
|
static SUFFIX: &str = "p256";
|
|
|
|
struct Default;
|
|
|
|
#[cfg(feature = "ristretto255")]
|
|
impl CipherSuite for Default {
|
|
type OprfGroup = curve25519_dalek::ristretto::RistrettoPoint;
|
|
type KeGroup = curve25519_dalek::ristretto::RistrettoPoint;
|
|
type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
|
|
type Hash = sha2::Sha512;
|
|
type SlowHash = opaque_ke::slow_hash::NoOpHash;
|
|
}
|
|
|
|
#[cfg(not(feature = "ristretto255"))]
|
|
impl CipherSuite for Default {
|
|
type OprfGroup = p256_::ProjectivePoint;
|
|
type KeGroup = p256_::PublicKey;
|
|
type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH;
|
|
type Hash = sha2::Sha256;
|
|
type SlowHash = opaque_ke::slow_hash::NoOpHash;
|
|
}
|
|
|
|
fn server_setup(c: &mut Criterion) {
|
|
let mut rng = OsRng;
|
|
|
|
c.bench_function(&format!("server setup ({})", SUFFIX), move |b| {
|
|
b.iter(|| {
|
|
ServerSetup::<Default>::new(&mut rng);
|
|
})
|
|
});
|
|
}
|
|
|
|
fn client_registration_start(c: &mut Criterion) {
|
|
let mut rng = OsRng;
|
|
let password = b"password";
|
|
|
|
c.bench_function(
|
|
&format!("client registration start ({})", SUFFIX),
|
|
move |b| {
|
|
b.iter(|| {
|
|
ClientRegistration::<Default>::start(&mut rng, password).unwrap();
|
|
})
|
|
},
|
|
);
|
|
}
|
|
|
|
fn server_registration_start(c: &mut Criterion) {
|
|
let mut rng = OsRng;
|
|
let username = b"username";
|
|
let password = b"password";
|
|
let server_setup = ServerSetup::<Default>::new(&mut rng);
|
|
let client_registration_start_result =
|
|
ClientRegistration::<Default>::start(&mut rng, password).unwrap();
|
|
|
|
c.bench_function(
|
|
&format!("server registration start ({})", SUFFIX),
|
|
move |b| {
|
|
b.iter(|| {
|
|
ServerRegistration::<Default>::start(
|
|
&server_setup,
|
|
client_registration_start_result.message.clone(),
|
|
username,
|
|
)
|
|
.unwrap();
|
|
})
|
|
},
|
|
);
|
|
}
|
|
|
|
fn client_registration_finish(c: &mut Criterion) {
|
|
let mut rng = OsRng;
|
|
let username = b"username";
|
|
let password = b"password";
|
|
let server_setup = ServerSetup::<Default>::new(&mut rng);
|
|
let client_registration_start_result =
|
|
ClientRegistration::<Default>::start(&mut rng, password).unwrap();
|
|
let server_registration_start_result = ServerRegistration::<Default>::start(
|
|
&server_setup,
|
|
client_registration_start_result.message.clone(),
|
|
username,
|
|
)
|
|
.unwrap();
|
|
|
|
c.bench_function(
|
|
&format!("client registration finish ({})", SUFFIX),
|
|
move |b| {
|
|
b.iter(|| {
|
|
client_registration_start_result
|
|
.clone()
|
|
.state
|
|
.finish(
|
|
&mut rng,
|
|
server_registration_start_result.message.clone(),
|
|
ClientRegistrationFinishParameters::default(),
|
|
)
|
|
.unwrap();
|
|
})
|
|
},
|
|
);
|
|
}
|
|
|
|
fn server_registration_finish(c: &mut Criterion) {
|
|
let mut rng = OsRng;
|
|
let username = b"username";
|
|
let password = b"password";
|
|
let server_setup = ServerSetup::<Default>::new(&mut rng);
|
|
let client_registration_start_result =
|
|
ClientRegistration::<Default>::start(&mut rng, password).unwrap();
|
|
let server_registration_start_result = ServerRegistration::<Default>::start(
|
|
&server_setup,
|
|
client_registration_start_result.message.clone(),
|
|
username,
|
|
)
|
|
.unwrap();
|
|
let client_registration_finish_result = client_registration_start_result
|
|
.state
|
|
.finish(
|
|
&mut rng,
|
|
server_registration_start_result.message,
|
|
ClientRegistrationFinishParameters::default(),
|
|
)
|
|
.unwrap();
|
|
|
|
c.bench_function(
|
|
&format!("server registration finish ({})", SUFFIX),
|
|
move |b| {
|
|
b.iter(|| {
|
|
ServerRegistration::finish(client_registration_finish_result.clone().message);
|
|
})
|
|
},
|
|
);
|
|
}
|
|
|
|
fn client_login_start(c: &mut Criterion) {
|
|
let mut rng = OsRng;
|
|
let password = b"password";
|
|
|
|
c.bench_function(&format!("client login start ({})", SUFFIX), move |b| {
|
|
b.iter(|| {
|
|
ClientLogin::<Default>::start(&mut rng, password).unwrap();
|
|
})
|
|
});
|
|
}
|
|
|
|
fn server_login_start_real(c: &mut Criterion) {
|
|
let mut rng = OsRng;
|
|
let username = b"username";
|
|
let password = b"password";
|
|
let server_setup = ServerSetup::<Default>::new(&mut rng);
|
|
let client_registration_start_result =
|
|
ClientRegistration::<Default>::start(&mut rng, password).unwrap();
|
|
let server_registration_start_result = ServerRegistration::<Default>::start(
|
|
&server_setup,
|
|
client_registration_start_result.message.clone(),
|
|
username,
|
|
)
|
|
.unwrap();
|
|
let client_registration_finish_result = client_registration_start_result
|
|
.state
|
|
.finish(
|
|
&mut rng,
|
|
server_registration_start_result.message,
|
|
ClientRegistrationFinishParameters::default(),
|
|
)
|
|
.unwrap();
|
|
let password_file = ServerRegistration::finish(client_registration_finish_result.message);
|
|
let client_login_start_result = ClientLogin::<Default>::start(&mut rng, password).unwrap();
|
|
|
|
c.bench_function(
|
|
&format!("server login start (real) ({})", SUFFIX),
|
|
move |b| {
|
|
b.iter(|| {
|
|
ServerLogin::start(
|
|
&mut rng,
|
|
&server_setup,
|
|
Some(password_file.clone()),
|
|
client_login_start_result.clone().message,
|
|
username,
|
|
ServerLoginStartParameters::default(),
|
|
)
|
|
.unwrap();
|
|
})
|
|
},
|
|
);
|
|
}
|
|
|
|
fn server_login_start_fake(c: &mut Criterion) {
|
|
let mut rng = OsRng;
|
|
let username = b"username";
|
|
let password = b"password";
|
|
let server_setup = ServerSetup::<Default>::new(&mut rng);
|
|
let client_login_start_result = ClientLogin::<Default>::start(&mut rng, password).unwrap();
|
|
|
|
c.bench_function(
|
|
&format!("server login start (fake) ({})", SUFFIX),
|
|
move |b| {
|
|
b.iter(|| {
|
|
ServerLogin::start(
|
|
&mut rng,
|
|
&server_setup,
|
|
None,
|
|
client_login_start_result.clone().message,
|
|
username,
|
|
ServerLoginStartParameters::default(),
|
|
)
|
|
.unwrap();
|
|
})
|
|
},
|
|
);
|
|
}
|
|
|
|
fn client_login_finish(c: &mut Criterion) {
|
|
let mut rng = OsRng;
|
|
let username = b"username";
|
|
let password = b"password";
|
|
let server_setup = ServerSetup::<Default>::new(&mut rng);
|
|
let client_registration_start_result =
|
|
ClientRegistration::<Default>::start(&mut rng, password).unwrap();
|
|
let server_registration_start_result = ServerRegistration::<Default>::start(
|
|
&server_setup,
|
|
client_registration_start_result.message.clone(),
|
|
username,
|
|
)
|
|
.unwrap();
|
|
let client_registration_finish_result = client_registration_start_result
|
|
.state
|
|
.finish(
|
|
&mut rng,
|
|
server_registration_start_result.message,
|
|
ClientRegistrationFinishParameters::default(),
|
|
)
|
|
.unwrap();
|
|
let password_file = ServerRegistration::finish(client_registration_finish_result.message);
|
|
let client_login_start_result = ClientLogin::<Default>::start(&mut rng, password).unwrap();
|
|
let server_login_start = ServerLogin::start(
|
|
&mut rng,
|
|
&server_setup,
|
|
Some(password_file),
|
|
client_login_start_result.clone().message,
|
|
username,
|
|
ServerLoginStartParameters::default(),
|
|
)
|
|
.unwrap();
|
|
|
|
c.bench_function(&format!("client login finish ({})", SUFFIX), move |b| {
|
|
b.iter(|| {
|
|
client_login_start_result
|
|
.clone()
|
|
.state
|
|
.finish(
|
|
server_login_start.clone().message,
|
|
ClientLoginFinishParameters::default(),
|
|
)
|
|
.unwrap();
|
|
})
|
|
});
|
|
}
|
|
|
|
fn server_login_finish(c: &mut Criterion) {
|
|
let mut rng = OsRng;
|
|
let username = b"username";
|
|
let password = b"password";
|
|
let server_setup = ServerSetup::<Default>::new(&mut rng);
|
|
let client_registration_start_result =
|
|
ClientRegistration::<Default>::start(&mut rng, password).unwrap();
|
|
let server_registration_start_result = ServerRegistration::<Default>::start(
|
|
&server_setup,
|
|
client_registration_start_result.message.clone(),
|
|
username,
|
|
)
|
|
.unwrap();
|
|
let client_registration_finish_result = client_registration_start_result
|
|
.state
|
|
.finish(
|
|
&mut rng,
|
|
server_registration_start_result.message,
|
|
ClientRegistrationFinishParameters::default(),
|
|
)
|
|
.unwrap();
|
|
let password_file = ServerRegistration::finish(client_registration_finish_result.message);
|
|
let client_login_start_result = ClientLogin::<Default>::start(&mut rng, password).unwrap();
|
|
let server_login_start_result = ServerLogin::start(
|
|
&mut rng,
|
|
&server_setup,
|
|
Some(password_file),
|
|
client_login_start_result.clone().message,
|
|
username,
|
|
ServerLoginStartParameters::default(),
|
|
)
|
|
.unwrap();
|
|
let client_login_finish_result = client_login_start_result
|
|
.state
|
|
.finish(
|
|
server_login_start_result.clone().message,
|
|
ClientLoginFinishParameters::default(),
|
|
)
|
|
.unwrap();
|
|
|
|
c.bench_function(&format!("server login finish ({})", SUFFIX), move |b| {
|
|
b.iter(|| {
|
|
server_login_start_result
|
|
.clone()
|
|
.state
|
|
.finish(client_login_finish_result.clone().message)
|
|
.unwrap();
|
|
})
|
|
});
|
|
}
|
|
|
|
criterion_group!(
|
|
opaque_benches,
|
|
server_setup,
|
|
client_registration_start,
|
|
server_registration_start,
|
|
client_registration_finish,
|
|
server_registration_finish,
|
|
client_login_start,
|
|
server_login_start_real,
|
|
server_login_start_fake,
|
|
client_login_finish,
|
|
server_login_finish,
|
|
);
|
|
criterion_main!(opaque_benches);
|