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

Benchmark polynomials of different degrees. #19

Merged
merged 1 commit into from
Aug 30, 2018
Merged
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ env:
- RUST_NEXT=nightly-2018-07-13
script:
- cargo +${RUST_NEXT} clippy -- --deny clippy
- cargo +${RUST_NEXT} clippy --tests --examples -- --deny clippy
- cargo +${RUST_NEXT} clippy --tests --examples --benches -- --deny clippy
- cargo +${RUST_NEXT} clippy --all-features -- --deny clippy
- cargo +${RUST_NEXT} clippy --all-features --tests -- --deny clippy
- cargo +${RUST_NEXT} fmt -- --check
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,18 @@ Disabling memory locking is useful because it removes the possibility of tests f

## Application Details

The basic usage outline is:
The basic usage outline is:
* choose a threshold value `t`
* create a key set
* distribute `N` secret key shares among the participants
* publish the public master key
* publish the public master key

A third party can now encrypt a message to the public master key
and any set of `t + 1` participants *(but no fewer!)* can collaborate to
decrypt it. Also, any set of `t + 1` participants can collaborate to sign a message,
producing a signature that is verifiable with the public master key.

In this system, a signature is unique and independent of
In this system, a signature is unique and independent of
the set of participants that produced it. If `S1` and `S2` are
signatures for the same message, produced by two different sets of `t + 1`
secret key share holders, both signatures will be valid AND
Expand Down
36 changes: 26 additions & 10 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
#[macro_use]
extern crate criterion;
extern crate pairing;
extern crate rand;
extern crate threshold_crypto;

use criterion::Criterion;
use pairing::bls12_381::Fr;
use threshold_crypto::poly::Poly;

mod poly_benches {
use super::*;
use rand::Rng;

// Benchmarks multiplication of two degree 3 polynomials.
// Benchmarks multiplication of two polynomials.
fn multiplication(c: &mut Criterion) {
let mut rng = rand::thread_rng();
let lhs = Poly::random(3, &mut rng).unwrap();
let rhs = Poly::random(3, &mut rng).unwrap();
c.bench_function("Polynomial multiplication", move |b| b.iter(|| &lhs * &rhs));
c.bench_function_over_inputs(
"Polynomial multiplication",
move |b, &&deg| {
let rand_factors = || {
let lhs = Poly::random(deg, &mut rng).unwrap();
let rhs = Poly::random(deg, &mut rng).unwrap();
(lhs, rhs)
};
b.iter_with_setup(rand_factors, |(lhs, rhs)| &lhs * &rhs)
},
&[5, 10, 20, 40],
);
}

// Benchmarks Lagrange interpolation for a degree 3 polynomial.
// Benchmarks Lagrange interpolation for a polynomial.
fn interpolate(c: &mut Criterion) {
// Points from the the polynomial: `y(x) = 5x^3 + 0x^2 + x - 2`.
let sample_points = vec![(-1, -8), (2, 40), (3, 136), (5, 628)];
c.bench_function("Polynomial interpolation", move |b| {
b.iter(|| Poly::interpolate(sample_points.clone()).unwrap())
});
let mut rng = rand::thread_rng();
c.bench_function_over_inputs(
"Polynomial interpolation",
move |b, &&deg| {
let rand_samples = || (0..=deg).map(|i| (i, rng.gen::<Fr>())).collect::<Vec<_>>();
b.iter_with_setup(rand_samples, |samples| Poly::interpolate(samples).unwrap())
},
&[5, 10, 20, 40],
);
}

criterion_group!{
Expand Down