Benchmark polynomials of different degrees.
This commit is contained in:
parent
d783f2756e
commit
02109b586e
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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, &°| {
|
||||
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, &°| {
|
||||
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!{
|
||||
|
|
Loading…
Reference in New Issue