Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microbenchmarks suite #134

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,39 @@ jobs:
- uses: hecrj/setup-rust-action@v2
- run: rustup target add ${{ matrix.target }}
- run: cargo build --verbose --target=${{ matrix.target }} --no-default-features ${{ matrix.frontend_feature }} ${{ matrix.backend_feature }}

benches:
name: cargo bench compilation
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
backend_feature:
- --features ristretto255-ciphersuite
-
frontend_feature:
-
- --features danger
- --features serde
toolchain:
- stable
- 1.65.0
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install ${{ matrix.toolchain }} toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.toolchain }}
override: true

- name: Run cargo bench --no-run
uses: actions-rs/cargo@v1
with:
command: bench
args: --no-default-features ${{ matrix.backend_feature }} --no-run

clippy:
name: cargo clippy
Expand Down
14 changes: 14 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ subtle = { version = "2.3", default-features = false }
zeroize = { version = "1.5", default-features = false }

[dev-dependencies]
criterion = "0.3"
paste = "1.0"
generic-array = { version = "0.14", features = ["more_lengths"] }
hex = "0.4"
p256 = { version = "0.13", default-features = false, features = [
Expand All @@ -63,6 +65,18 @@ regex = "1"
serde_json = "1"
sha2 = "0.10"

[[bench]]
name = "oprf"
harness = false

[[bench]]
name = "voprf"
harness = false

[[bench]]
name = "poprf"
harness = false

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ voprf = "0.5"

Rust **1.65** or higher.

Microbenchmarks
---------------

The library also comes with a suite of microbenchmarks for each mode `oprf`, `voprf`, `poprf` that can be run via:
```
cargo bench --bench <name_of_mode>
```


Contributors
------------

Expand Down
91 changes: 91 additions & 0 deletions benches/oprf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use paste::paste;

use p256::NistP256 as P256;
use p384::NistP384 as P384;
use p521::NistP521 as P521;
use rand::{rngs::StdRng, SeedableRng};
use voprf::{OprfClient, OprfServer, Ristretto255};

Check failure on line 8 in benches/oprf.rs

View workflow job for this annotation

GitHub Actions / cargo bench compilation (--features serde, stable)

unresolved import `voprf::Ristretto255`

Check failure on line 8 in benches/oprf.rs

View workflow job for this annotation

GitHub Actions / cargo bench compilation (stable)

unresolved import `voprf::Ristretto255`

Check failure on line 8 in benches/oprf.rs

View workflow job for this annotation

GitHub Actions / cargo bench compilation (--features danger, stable)

unresolved import `voprf::Ristretto255`

Check failure on line 8 in benches/oprf.rs

View workflow job for this annotation

GitHub Actions / cargo bench compilation (--features serde, 1.65.0)

unresolved import `voprf::Ristretto255`

Check failure on line 8 in benches/oprf.rs

View workflow job for this annotation

GitHub Actions / cargo bench compilation (--features danger, 1.65.0)

unresolved import `voprf::Ristretto255`

Check failure on line 8 in benches/oprf.rs

View workflow job for this annotation

GitHub Actions / cargo bench compilation (1.65.0)

unresolved import `voprf::Ristretto255`

macro_rules! make_oprf_benches {
($cipher_suite:ident) => {

paste! {
fn [<bench_oprf_client_blind_ $cipher_suite:lower>](c: &mut Criterion) {
let rng = StdRng::seed_from_u64(0_u64);
c.bench_function(&format!("{}_{}", "oprf_client_blind", stringify!($cipher_suite).to_lowercase()), move |b| {
b.iter_batched_ref(
|| rng.clone(),
|mut rng| {
OprfClient::<$cipher_suite>::blind(b"input", &mut rng)
.expect("Unable to construct client")
},
BatchSize::SmallInput,
)
});
}
}

paste! {
fn [<bench_oprf_server_evaluate_ $cipher_suite:lower>](c: &mut Criterion) {
let mut rng = StdRng::seed_from_u64(0_u64);
let server = OprfServer::<$cipher_suite>::new(&mut rng).unwrap();
let client_blind_result =
OprfClient::<$cipher_suite>::blind(b"input", &mut rng).expect("Unable to construct client");
c.bench_function(&format!("{}_{}", "oprf_server_eval", stringify!($cipher_suite).to_lowercase()), move |b| {
b.iter(
|| {
server
.blind_evaluate(&client_blind_result.message);
}
)
});
}
}

paste! {
fn [<bench_oprf_client_finalize_ $cipher_suite:lower>](c: &mut Criterion) {
let mut rng = StdRng::seed_from_u64(0_u64);
let server = OprfServer::<$cipher_suite>::new(&mut rng).unwrap();
let client_blind_result =
OprfClient::<$cipher_suite>::blind(b"input", &mut rng).expect("Unable to construct client");
let server_evaluate_result = server
.blind_evaluate(&client_blind_result.message);
c.bench_function(&format!("{}_{}", "oprf_client_final", stringify!($cipher_suite).to_lowercase()), move |b| {
b.iter(|| {
client_blind_result
.state
.finalize(
b"input",
&server_evaluate_result,
)
.expect("Unable to perform client finalization")
})
});
}
}

};
}

make_oprf_benches!(Ristretto255);
make_oprf_benches!(P256);
make_oprf_benches!(P384);
make_oprf_benches!(P521);

criterion_group!(
oprf,
bench_oprf_client_blind_ristretto255,
bench_oprf_server_evaluate_ristretto255,
bench_oprf_client_finalize_ristretto255,
bench_oprf_client_blind_p256,
bench_oprf_server_evaluate_p256,
bench_oprf_client_finalize_p256,
bench_oprf_client_blind_p384,
bench_oprf_server_evaluate_p384,
bench_oprf_client_finalize_p384,
bench_oprf_client_blind_p521,
bench_oprf_server_evaluate_p521,
bench_oprf_client_finalize_p521
);
criterion_main!(oprf);
98 changes: 98 additions & 0 deletions benches/poprf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use paste::paste;

use p256::NistP256 as P256;
use p384::NistP384 as P384;
use p521::NistP521 as P521;
use rand::{rngs::StdRng, SeedableRng};
use voprf::{PoprfClient, PoprfServer, Ristretto255};

Check failure on line 8 in benches/poprf.rs

View workflow job for this annotation

GitHub Actions / cargo bench compilation (--features serde, stable)

unresolved import `voprf::Ristretto255`

Check failure on line 8 in benches/poprf.rs

View workflow job for this annotation

GitHub Actions / cargo bench compilation (stable)

unresolved import `voprf::Ristretto255`

Check failure on line 8 in benches/poprf.rs

View workflow job for this annotation

GitHub Actions / cargo bench compilation (--features danger, stable)

unresolved import `voprf::Ristretto255`

Check failure on line 8 in benches/poprf.rs

View workflow job for this annotation

GitHub Actions / cargo bench compilation (--features serde, 1.65.0)

unresolved import `voprf::Ristretto255`

Check failure on line 8 in benches/poprf.rs

View workflow job for this annotation

GitHub Actions / cargo bench compilation (--features danger, 1.65.0)

unresolved import `voprf::Ristretto255`

Check failure on line 8 in benches/poprf.rs

View workflow job for this annotation

GitHub Actions / cargo bench compilation (1.65.0)

unresolved import `voprf::Ristretto255`

macro_rules! make_poprf_benches {
($cipher_suite:ident) => {

paste! {
fn [<bench_poprf_client_blind_ $cipher_suite:lower>](c: &mut Criterion) {
let rng = StdRng::seed_from_u64(0_u64);
c.bench_function(&format!("{}_{}", "poprf_client_blind", stringify!($cipher_suite).to_lowercase()), move |b| {
b.iter_batched_ref(
|| rng.clone(),
|mut rng| {
PoprfClient::<$cipher_suite>::blind(b"input", &mut rng)
.expect("Unable to construct client")
},
BatchSize::SmallInput,
)
});
}
}

paste! {
fn [<bench_poprf_server_evaluate_ $cipher_suite:lower>](c: &mut Criterion) {
let mut rng = StdRng::seed_from_u64(0_u64);
let server = PoprfServer::<$cipher_suite>::new(&mut rng).unwrap();
let client_blind_result =
PoprfClient::<$cipher_suite>::blind(b"input", &mut rng).expect("Unable to construct client");
c.bench_function(&format!("{}_{}", "poprf_server_eval", stringify!($cipher_suite).to_lowercase()), move |b| {
b.iter_batched_ref(
|| rng.clone(),
|mut rng| {
server
.blind_evaluate(&mut rng, &client_blind_result.message, Some(b"tag"))
.expect("Unable to perform server evaluation")
},
BatchSize::SmallInput,
)
});
}
}

paste! {
fn [<bench_poprf_client_finalize_ $cipher_suite:lower>](c: &mut Criterion) {
let mut rng = StdRng::seed_from_u64(0_u64);
let server = PoprfServer::<$cipher_suite>::new(&mut rng).unwrap();
let client_blind_result =
PoprfClient::<$cipher_suite>::blind(b"input", &mut rng).expect("Unable to construct client");
let server_evaluate_result = server
.blind_evaluate(&mut rng, &client_blind_result.message, Some(b"tag"))
.expect("Unable to perform server evaluation");
c.bench_function(&format!("{}_{}", "poprf_client_final", stringify!($cipher_suite).to_lowercase()), move |b| {
b.iter(|| {
client_blind_result
.state
.finalize(
b"input",
&server_evaluate_result.message,
&server_evaluate_result.proof,
server.get_public_key(),
Some(b"tag"),
)
.expect("Unable to perform client finalization")
})
});
}
}

};
}

make_poprf_benches!(Ristretto255);
make_poprf_benches!(P256);
make_poprf_benches!(P384);
make_poprf_benches!(P521);

criterion_group!(
poprf,
bench_poprf_client_blind_ristretto255,
bench_poprf_server_evaluate_ristretto255,
bench_poprf_client_finalize_ristretto255,
bench_poprf_client_blind_p256,
bench_poprf_server_evaluate_p256,
bench_poprf_client_finalize_p256,
bench_poprf_client_blind_p384,
bench_poprf_server_evaluate_p384,
bench_poprf_client_finalize_p384,
bench_poprf_client_blind_p521,
bench_poprf_server_evaluate_p521,
bench_poprf_client_finalize_p521
);
criterion_main!(poprf);
95 changes: 95 additions & 0 deletions benches/voprf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use paste::paste;

use p256::NistP256 as P256;
use p384::NistP384 as P384;
use p521::NistP521 as P521;
use rand::{rngs::StdRng, SeedableRng};
use voprf::{Ristretto255, VoprfClient, VoprfServer};

Check failure on line 8 in benches/voprf.rs

View workflow job for this annotation

GitHub Actions / cargo bench compilation (--features serde, stable)

unresolved import `voprf::Ristretto255`

Check failure on line 8 in benches/voprf.rs

View workflow job for this annotation

GitHub Actions / cargo bench compilation (stable)

unresolved import `voprf::Ristretto255`

Check failure on line 8 in benches/voprf.rs

View workflow job for this annotation

GitHub Actions / cargo bench compilation (--features danger, stable)

unresolved import `voprf::Ristretto255`

Check failure on line 8 in benches/voprf.rs

View workflow job for this annotation

GitHub Actions / cargo bench compilation (--features serde, 1.65.0)

unresolved import `voprf::Ristretto255`

Check failure on line 8 in benches/voprf.rs

View workflow job for this annotation

GitHub Actions / cargo bench compilation (--features danger, 1.65.0)

unresolved import `voprf::Ristretto255`

Check failure on line 8 in benches/voprf.rs

View workflow job for this annotation

GitHub Actions / cargo bench compilation (1.65.0)

unresolved import `voprf::Ristretto255`

macro_rules! make_voprf_benches {
($cipher_suite:ident) => {

paste! {
fn [<bench_voprf_client_blind_ $cipher_suite:lower>](c: &mut Criterion) {
let rng = StdRng::seed_from_u64(0_u64);
c.bench_function(&format!("{}_{}", "voprf_client_blind", stringify!($cipher_suite).to_lowercase()), move |b| {
b.iter_batched_ref(
|| rng.clone(),
|mut rng| {
VoprfClient::<$cipher_suite>::blind(b"input", &mut rng)
.expect("Unable to construct client")
},
BatchSize::SmallInput,
)
});
}
}

paste! {
fn [<bench_voprf_server_evaluate_ $cipher_suite:lower>](c: &mut Criterion) {
let mut rng = StdRng::seed_from_u64(0_u64);
let server = VoprfServer::<$cipher_suite>::new(&mut rng).unwrap();
let client_blind_result =
VoprfClient::<$cipher_suite>::blind(b"input", &mut rng).expect("Unable to construct client");
c.bench_function(&format!("{}_{}", "voprf_server_eval", stringify!($cipher_suite).to_lowercase()), move |b| {
b.iter_batched_ref(
|| rng.clone(),
|mut rng| {
server
.blind_evaluate(&mut rng, &client_blind_result.message);
},
BatchSize::SmallInput,
)
});
}
}

paste! {
fn [<bench_voprf_client_finalize_ $cipher_suite:lower>](c: &mut Criterion) {
let mut rng = StdRng::seed_from_u64(0_u64);
let server = VoprfServer::<$cipher_suite>::new(&mut rng).unwrap();
let client_blind_result =
VoprfClient::<$cipher_suite>::blind(b"input", &mut rng).expect("Unable to construct client");
let server_evaluate_result = server
.blind_evaluate(&mut rng, &client_blind_result.message);
c.bench_function(&format!("{}_{}", "voprf_client_final", stringify!($cipher_suite).to_lowercase()), move |b| {
b.iter(|| {
client_blind_result
.state
.finalize(
b"input",
&server_evaluate_result.message,
&server_evaluate_result.proof,
server.get_public_key(),
)
.expect("Unable to perform client finalization")
})
});
}
}

};
}

make_voprf_benches!(Ristretto255);
make_voprf_benches!(P256);
make_voprf_benches!(P384);
make_voprf_benches!(P521);

criterion_group!(
voprf,
bench_voprf_client_blind_ristretto255,
bench_voprf_server_evaluate_ristretto255,
bench_voprf_client_finalize_ristretto255,
bench_voprf_client_blind_p256,
bench_voprf_server_evaluate_p256,
bench_voprf_client_finalize_p256,
bench_voprf_client_blind_p384,
bench_voprf_server_evaluate_p384,
bench_voprf_client_finalize_p384,
bench_voprf_client_blind_p521,
bench_voprf_server_evaluate_p521,
bench_voprf_client_finalize_p521
);
criterion_main!(voprf);
Loading