diff --git a/.travis.yml b/.travis.yml index a598e32..56cad2f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,8 @@ env: - TEST_COMMAND=test EXTRA_FLAGS='' FEATURES='serde' - TEST_COMMAND=test EXTRA_FLAGS='' FEATURES='nightly' - TEST_COMMAND=test EXTRA_FLAGS='' FEATURES='yolocrypto nightly' - - TEST_COMMAND=bench EXTRA_FLAGS='' FEATURES='nightly bench' - - TEST_COMMAND=bench EXTRA_FLAGS='' FEATURES='yolocrypto nightly bench' + - TEST_COMMAND=bench EXTRA_FLAGS='' FEATURES='nightly' + - TEST_COMMAND=bench EXTRA_FLAGS='' FEATURES='yolocrypto nightly' - TEST_COMMAND=build EXTRA_FLAGS=--no-default-features FEATURES='' matrix: @@ -21,13 +21,13 @@ matrix: # run benchmarks, which causes dalek not to build on stable. See # https://github.com/isislovecruft/curve25519-dalek/pull/38#issuecomment-286027562 - rust: stable - env: TEST_COMMAND=bench EXTRA_FLAGS='' FEATURES='nightly bench' + env: TEST_COMMAND=bench EXTRA_FLAGS='' FEATURES='nightly' - rust: beta - env: TEST_COMMAND=bench EXTRA_FLAGS='' FEATURES='nightly bench' + env: TEST_COMMAND=bench EXTRA_FLAGS='' FEATURES='nightly' - rust: stable - env: TEST_COMMAND=bench EXTRA_FLAGS='' FEATURES='yolocrypto nightly bench' + env: TEST_COMMAND=bench EXTRA_FLAGS='' FEATURES='yolocrypto nightly' - rust: beta - env: TEST_COMMAND=bench EXTRA_FLAGS='' FEATURES='yolocrypto nightly bench' + env: TEST_COMMAND=bench EXTRA_FLAGS='' FEATURES='yolocrypto nightly' # Test nightly features, such as radix_51, only on nightly. - rust: stable env: TEST_COMMAND=test EXTRA_FLAGS='' FEATURES='nightly' diff --git a/Cargo.toml b/Cargo.toml index c9ff5ee..72eda7f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,11 @@ travis-ci = { repository = "dalek-cryptography/curve25519-dalek", branch = "mast [dev-dependencies] sha2 = "0.7" serde_cbor = "0.6" +criterion = "0.2" + +[[bench]] +name = "dalek_benchmarks" +harness = false # Note: we generate precomputed tables by building the crate twice: once as # part of build.rs, and then once "for real". @@ -60,7 +65,6 @@ default = ["std"] std = ["rand", "subtle/std"] alloc = [] yolocrypto = ["avx2_backend"] -bench = [] # Radix-51 arithmetic using u128 radix_51 = [] # Include precomputed basepoint tables. This is off by default so that build.rs can generate the tables, and then re-enabled by build.rs in the main-stage compilation. diff --git a/README.md b/README.md index 1ac09aa..1ac0bfe 100644 --- a/README.md +++ b/README.md @@ -66,13 +66,12 @@ Curve arithmetic is implemented using one of the following backends: * an experimental AVX2 backend, available using the `yolocrypto` feature when compiling for a target with `target_feature=+avx2`. -By default, the benchmarks are not compiled without the `bench` -feature. Benchmarks can be run via: +Benchmarks are run using [`criterion.rs`][criterion]: ```sh -cargo bench --features="bench" # u32 backend -cargo bench --features="bench nightly" # u64 backend -cargo bench --features="bench nightly yolocrypto" # u64 or avx2 if available +cargo bench # u32 backend +cargo bench --features="nightly" # u64 backend +cargo bench --features="nightly yolocrypto" # u64 or avx2 if available ``` The `yolocrypto` feature enables experimental features. The name `yolocrypto` @@ -120,3 +119,4 @@ contributions. [contributing]: https://github.com/dalek-cryptography/curve25519-dalek/blob/master/CONTRIBUTING.md [docs-external]: https://doc.dalek.rs/curve25519_dalek/ [docs-internal]: https://doc-internal.dalek.rs/curve25519_dalek/ +[criterion]: https://github.com/japaric/criterion.rs diff --git a/benches/dalek_benchmarks.rs b/benches/dalek_benchmarks.rs new file mode 100644 index 0000000..81c9056 --- /dev/null +++ b/benches/dalek_benchmarks.rs @@ -0,0 +1,207 @@ +#![allow(non_snake_case)] + +extern crate rand; +use rand::OsRng; + +#[macro_use] +extern crate criterion; + +use criterion::Criterion; + +extern crate curve25519_dalek; + +use curve25519_dalek::constants; +use curve25519_dalek::scalar::Scalar; + +static MULTISCALAR_SIZES: [usize; 13] = [1, 2, 4, 8, 16, 32, 64, 128, 256, 384, 512, 768, 1024]; + +mod edwards_benches { + use super::*; + use curve25519_dalek::edwards::{self, EdwardsPoint}; + + fn compress(c: &mut Criterion) { + let B = &constants::ED25519_BASEPOINT_POINT; + c.bench_function("EdwardsPoint compression", move |b| { + b.iter(|| B.compress()) + }); + } + + fn decompress(c: &mut Criterion) { + let B_comp = &constants::ED25519_BASEPOINT_COMPRESSED; + c.bench_function("EdwardsPoint decompression", move |b| { + b.iter(|| B_comp.decompress().unwrap()) + }); + } + + fn consttime_fixed_base_scalar_mul(c: &mut Criterion) { + let B = &constants::ED25519_BASEPOINT_TABLE; + let s = Scalar::from_u64(897987897).invert(); + c.bench_function("Constant-time fixed-base scalar mul", move |b| { + b.iter(|| B * &s) + }); + } + + fn consttime_variable_base_scalar_mul(c: &mut Criterion) { + let B = &constants::ED25519_BASEPOINT_POINT; + let s = Scalar::from_u64(897987897).invert(); + c.bench_function("Constant-time variable-base scalar mul", move |b| { + b.iter(|| B * &s) + }); + } + + fn vartime_double_base_scalar_mul(c: &mut Criterion) { + c.bench_function("Variable-time aA+bB, A variable, B fixed", |bench| { + let B = &constants::ED25519_BASEPOINT_POINT; + let a = Scalar::from_u64(298374928).invert(); + let b = Scalar::from_u64(897987897).invert(); + let A = B * (b * a); + bench.iter(|| edwards::vartime::double_scalar_mul_basepoint(&a, &A, &b)); + }); + } + + fn consttime_multiscalar_mul(c: &mut Criterion) { + c.bench_function_over_inputs( + "Constant-time variable-base multiscalar multiplication", + |b, &&size| { + let mut rng = OsRng::new().unwrap(); + let scalars: Vec = (0..size).map(|_| Scalar::random(&mut rng)).collect(); + let points: Vec = scalars + .iter() + .map(|s| s * &constants::ED25519_BASEPOINT_TABLE) + .collect(); + b.iter(|| edwards::multiscalar_mul(&scalars, &points)); + }, + &MULTISCALAR_SIZES, + ); + } + + fn vartime_multiscalar_mul(c: &mut Criterion) { + c.bench_function_over_inputs( + "Variable-time variable-base multiscalar multiplication", + |b, &&size| { + let mut rng = OsRng::new().unwrap(); + let scalars: Vec = (0..size).map(|_| Scalar::random(&mut rng)).collect(); + let points: Vec = scalars + .iter() + .map(|s| s * &constants::ED25519_BASEPOINT_TABLE) + .collect(); + b.iter(|| edwards::vartime::multiscalar_mul(&scalars, &points)); + }, + &MULTISCALAR_SIZES, + ); + } + + criterion_group!{ + name = edwards_benches; + config = Criterion::default(); + targets = + compress, + decompress, + consttime_fixed_base_scalar_mul, + consttime_variable_base_scalar_mul, + vartime_double_base_scalar_mul, + consttime_multiscalar_mul, + vartime_multiscalar_mul, + } +} + +mod ristretto_benches { + use super::*; + use curve25519_dalek::ristretto::RistrettoPoint; + + fn compress(c: &mut Criterion) { + c.bench_function("RistrettoPoint compression", |b| { + let B = &constants::RISTRETTO_BASEPOINT_POINT; + b.iter(|| B.compress()) + }); + } + + fn decompress(c: &mut Criterion) { + c.bench_function("RistrettoPoint decompression", |b| { + let B_comp = &constants::RISTRETTO_BASEPOINT_COMPRESSED; + b.iter(|| B_comp.decompress().unwrap()) + }); + } + + fn double_and_compress_batch(c: &mut Criterion) { + c.bench_function_over_inputs( + "Batch Ristretto double-and-encode", + |b, &&size| { + let mut rng = OsRng::new().unwrap(); + let points: Vec = (0..size) + .map(|_| RistrettoPoint::random(&mut rng)) + .collect(); + b.iter(|| RistrettoPoint::double_and_compress_batch(&points)); + }, + &MULTISCALAR_SIZES, + ); + } + + criterion_group!{ + name = ristretto_benches; + config = Criterion::default(); + targets = + compress, + decompress, + double_and_compress_batch, + } +} + +mod montgomery_benches { + use super::*; + + fn montgomery_ladder(c: &mut Criterion) { + c.bench_function("Montgomery pseudomultiplication", |b| { + let B = constants::X25519_BASEPOINT; + let s = Scalar::from_u64(897987897).invert(); + b.iter(|| B * s); + }); + } + + criterion_group!{ + name = montgomery_benches; + config = Criterion::default(); + targets = montgomery_ladder, + } +} + +mod scalar_benches { + use super::*; + + fn scalar_inversion(c: &mut Criterion) { + c.bench_function("Scalar inversion", |b| { + let s = Scalar::from_u64(897987897).invert(); + b.iter(|| s.invert()); + }); + } + + fn batch_scalar_inversion(c: &mut Criterion) { + c.bench_function_over_inputs( + "Batch scalar inversion", + |b, &&size| { + let mut rng = OsRng::new().unwrap(); + let scalars: Vec = (0..size).map(|_| Scalar::random(&mut rng)).collect(); + b.iter(|| { + let mut s = scalars.clone(); + Scalar::batch_invert(&mut s); + }); + }, + &MULTISCALAR_SIZES, + ); + } + + criterion_group!{ + name = scalar_benches; + config = Criterion::default(); + targets = + scalar_inversion, + batch_scalar_inversion, + } +} + +criterion_main!( + scalar_benches::scalar_benches, + montgomery_benches::montgomery_benches, + ristretto_benches::ristretto_benches, + edwards_benches::edwards_benches, +); diff --git a/src/backend/avx2/edwards.rs b/src/backend/avx2/edwards.rs index 575619a..7f564d7 100644 --- a/src/backend/avx2/edwards.rs +++ b/src/backend/avx2/edwards.rs @@ -919,121 +919,3 @@ mod test { } } } - -#[cfg(all(test, feature = "bench"))] -mod bench { - use test::Bencher; - use rand::OsRng; - use super::*; - - use constants; - use scalar::Scalar; - - #[bench] - fn conversion_into__avx2_format(b: &mut Bencher) { - let B = constants::ED25519_BASEPOINT_POINT; - - b.iter(|| ExtendedPoint::from(B)); - } - - #[bench] - fn conversion_outof_avx2_format(b: &mut Bencher) { - let B = constants::ED25519_BASEPOINT_POINT; - let B_avx2 = ExtendedPoint::from(B); - - b.iter(|| edwards::EdwardsPoint::from(B_avx2)); - } - - #[bench] - fn point_readdition(b: &mut Bencher) { - let B = &constants::ED25519_BASEPOINT_TABLE; - let P = ExtendedPoint::from(B * &Scalar::from_u64(83973422)); - let Q = ExtendedPoint::from(B * &Scalar::from_u64(98932328)); - let Q_cached = CachedPoint::from(Q); - - b.iter(|| &P + &Q_cached ); - } - - #[bench] - fn point_addition(b: &mut Bencher) { - let B = &constants::ED25519_BASEPOINT_TABLE; - let P = ExtendedPoint::from(B * &Scalar::from_u64(83973422)); - let Q = ExtendedPoint::from(B * &Scalar::from_u64(98932328)); - - b.iter(|| &P + &Q ); - } - - #[bench] - fn point_doubling(b: &mut Bencher) { - let B = &constants::ED25519_BASEPOINT_TABLE; - let P = ExtendedPoint::from(B * &Scalar::from_u64(83973422)); - - b.iter(|| P.double() ); - } - - #[bench] - fn scalar_mul(b: &mut Bencher) { - let B = &constants::ED25519_BASEPOINT_TABLE; - let P = ExtendedPoint::from(B * &Scalar::from_u64(83973422)); - let s = Scalar::from_bits([233, 1, 233, 147, 113, 78, 244, 120, 40, 45, 103, 51, 224, 199, 189, 218, 96, 140, 211, 112, 39, 194, 73, 216, 173, 33, 102, 93, 76, 200, 84, 12]); - - b.iter(|| &P * &s ); - } - - #[bench] - fn basepoint_table_creation(b: &mut Bencher) { - let B = ExtendedPoint::from(constants::ED25519_BASEPOINT_POINT); - - b.iter(|| EdwardsBasepointTable::create(&B) ); - } - - #[bench] - fn basepoint_mult(b: &mut Bencher) { - let B = ExtendedPoint::from(constants::ED25519_BASEPOINT_POINT); - let table = EdwardsBasepointTable::create(&B); - let s = Scalar::from_bits([233, 1, 233, 147, 113, 78, 244, 120, 40, 45, 103, 51, 224, 199, 189, 218, 96, 140, 211, 112, 39, 194, 73, 216, 173, 33, 102, 93, 76, 200, 84, 12]); - - b.iter(|| &table * &s ); - } - - #[bench] - fn ten_fold_scalar_mul(b: &mut Bencher) { - let mut csprng: OsRng = OsRng::new().unwrap(); - // Create 10 random scalars - let scalars: Vec<_> = (0..10).map(|_| Scalar::random(&mut csprng)).collect(); - // Create 10 points (by doing scalar mults) - let B = &constants::ED25519_BASEPOINT_TABLE; - let points: Vec<_> = scalars.iter().map(|s| B * s).collect(); - - b.iter(|| multiscalar_mul(&scalars, &points)); - } - - mod vartime { - use super::super::*; - use super::{constants, Bencher, OsRng}; - - #[bench] - fn double_scalar_mul(b: &mut Bencher) { - let mut csprng: OsRng = OsRng::new().unwrap(); - // Create 2 random scalars - let s1 = Scalar::random(&mut csprng); - let s2 = Scalar::random(&mut csprng); - let P = &s1 * &constants::ED25519_BASEPOINT_TABLE; - - b.iter(|| vartime::double_scalar_mul_basepoint(&s2, &P, &s1) ); - } - - #[bench] - fn ten_fold_scalar_mul(b: &mut Bencher) { - let mut csprng: OsRng = OsRng::new().unwrap(); - // Create 10 random scalars - let scalars: Vec<_> = (0..10).map(|_| Scalar::random(&mut csprng)).collect(); - // Create 10 points (by doing scalar mults) - let B = &constants::ED25519_BASEPOINT_TABLE; - let points: Vec<_> = scalars.iter().map(|s| B * s).collect(); - - b.iter(|| vartime::multiscalar_mul(&scalars, &points)); - } - } -} - diff --git a/src/backend/avx2/field.rs b/src/backend/avx2/field.rs index d8b7883..125aa55 100644 --- a/src/backend/avx2/field.rs +++ b/src/backend/avx2/field.rs @@ -671,20 +671,4 @@ mod test { assert_eq!(x2, splits[2]); assert_eq!(x3, splits[3]); } - } - -#[cfg(all(test, feature = "bench"))] -mod bench { - use test::Bencher; - use super::*; - - #[bench] - fn multiply(b: &mut Bencher) { - let vec = FieldElement32x4::splat(&FieldElement64::zero()); - let vecprime = vec.clone(); - - b.iter(|| &vec * &vecprime ); - } -} - diff --git a/src/backend/u32/scalar.rs b/src/backend/u32/scalar.rs index af88b79..6c3bb51 100644 --- a/src/backend/u32/scalar.rs +++ b/src/backend/u32/scalar.rs @@ -519,38 +519,3 @@ mod test { } } } - - -#[cfg(all(test, feature = "bench"))] -mod bench { - use test::Bencher; - - use super::*; - use super::test::{X, Y}; - - #[bench] - fn square(b: &mut Bencher) { - b.iter(|| X.square()); - } - - #[bench] - fn mul(b: &mut Bencher) { - b.iter(|| Scalar32::mul(&X, &Y)); - } - - #[bench] - fn montgomery_square(b: &mut Bencher) { - b.iter(|| X.montgomery_square()); - } - - #[bench] - fn montgomery_mul(b: &mut Bencher) { - b.iter(|| Scalar32::montgomery_mul(&X, &Y)); - } - - #[bench] - fn from_bytes_wide(b: &mut Bencher) { - let bignum = [255u8; 64]; // 2^512 - 1 - b.iter(|| Scalar32::from_bytes_wide(&bignum)); - } -} diff --git a/src/backend/u64/scalar.rs b/src/backend/u64/scalar.rs index c5d46d3..e14440b 100644 --- a/src/backend/u64/scalar.rs +++ b/src/backend/u64/scalar.rs @@ -441,38 +441,3 @@ mod test { } } } - - -#[cfg(all(test, feature = "bench"))] -mod bench { - use test::Bencher; - - use super::*; - use super::test::{X, Y}; - - #[bench] - fn square(b: &mut Bencher) { - b.iter(|| X.square()); - } - - #[bench] - fn mul(b: &mut Bencher) { - b.iter(|| Scalar64::mul(&X, &Y)); - } - - #[bench] - fn montgomery_square(b: &mut Bencher) { - b.iter(|| X.montgomery_square()); - } - - #[bench] - fn montgomery_mul(b: &mut Bencher) { - b.iter(|| Scalar64::montgomery_mul(&X, &Y)); - } - - #[bench] - fn from_bytes_wide(b: &mut Bencher) { - let bignum = [255u8; 64]; // 2^512 - 1 - b.iter(|| Scalar64::from_bytes_wide(&bignum)); - } -} diff --git a/src/edwards.rs b/src/edwards.rs index 33d299f..bcc4db6 100644 --- a/src/edwards.rs +++ b/src/edwards.rs @@ -1384,153 +1384,3 @@ mod test { assert!(parsed.is_err()); } } - -// ------------------------------------------------------------------------ -// Benchmarks -// ------------------------------------------------------------------------ - -#[cfg(all(test, feature = "bench"))] -mod bench { - use rand::OsRng; - use test::Bencher; - use constants; - use super::*; - use super::test::A_SCALAR; - - #[bench] - fn edwards_decompress(b: &mut Bencher) { - let B = &constants::ED25519_BASEPOINT_COMPRESSED; - b.iter(|| B.decompress().unwrap()); - } - - #[bench] - fn edwards_compress(b: &mut Bencher) { - let B = &constants::ED25519_BASEPOINT_POINT; - b.iter(|| B.compress()); - } - - #[bench] - #[cfg(feature="precomputed_tables")] - fn basepoint_mult(b: &mut Bencher) { - let B = &constants::ED25519_BASEPOINT_TABLE; - b.iter(|| B * &A_SCALAR); - } - - #[bench] - fn scalar_mul(b: &mut Bencher) { - let B = &constants::ED25519_BASEPOINT_POINT; - b.iter(|| B * &A_SCALAR); - } - - #[bench] - #[cfg(feature="precomputed_tables")] - fn bench_select_precomputed_point(b: &mut Bencher) { - use test::black_box; - let table = &constants::ED25519_BASEPOINT_TABLE.0[0]; - b.iter(|| table.select(black_box(5)) ); - } - - #[bench] - fn add_extended_and_projective_niels_output_completed(b: &mut Bencher) { - let p1 = constants::ED25519_BASEPOINT_POINT; - let p2 = constants::ED25519_BASEPOINT_POINT.to_projective_niels(); - - b.iter(|| &p1 + &p2); - } - - #[bench] - fn add_extended_and_projective_niels_output_extended(b: &mut Bencher) { - let p1 = constants::ED25519_BASEPOINT_POINT; - let p2 = constants::ED25519_BASEPOINT_POINT.to_projective_niels(); - - b.iter(|| (&p1 + &p2).to_extended()); - } - - #[bench] - fn add_extended_and_affine_niels_output_completed(b: &mut Bencher) { - let p1 = constants::ED25519_BASEPOINT_POINT; - let p2 = constants::ED25519_BASEPOINT_POINT.to_affine_niels(); - - b.iter(|| &p1 + &p2); - } - - #[bench] - fn add_extended_and_affine_niels_output_extended(b: &mut Bencher) { - let p1 = constants::ED25519_BASEPOINT_POINT; - let p2 = constants::ED25519_BASEPOINT_POINT.to_affine_niels(); - - b.iter(|| (&p1 + &p2).to_extended()); - } - - #[bench] - fn projective_double_output_completed(b: &mut Bencher) { - let p1 = constants::ED25519_BASEPOINT_POINT.to_projective(); - - b.iter(|| p1.double()); - } - - #[bench] - fn extended_double_output_extended(b: &mut Bencher) { - let p1 = constants::ED25519_BASEPOINT_POINT; - - b.iter(|| p1.double()); - } - - #[bench] - fn mul_by_cofactor(b: &mut Bencher) { - let p1 = constants::ED25519_BASEPOINT_POINT; - - b.iter(|| p1.mul_by_cofactor()); - } - - #[bench] - #[cfg(feature="precomputed_tables")] - fn create_basepoint_table(b: &mut Bencher) { - let aB = &constants::ED25519_BASEPOINT_TABLE * &A_SCALAR; - b.iter(|| EdwardsBasepointTable::create(&aB)); - } - - #[bench] - #[cfg(feature="precomputed_tables")] - fn ten_fold_scalar_mul(b: &mut Bencher) { - let mut csprng: OsRng = OsRng::new().unwrap(); - // Create 10 random scalars - let scalars: Vec<_> = (0..10).map(|_| Scalar::random(&mut csprng)).collect(); - // Create 10 points (by doing scalar mults) - let B = &constants::ED25519_BASEPOINT_TABLE; - let points: Vec<_> = scalars.iter().map(|s| B * &s).collect(); - - b.iter(|| multiscalar_mul(&scalars, &points)); - } - - mod vartime { - use super::super::*; - use super::super::test::{A_SCALAR, B_SCALAR, A_TIMES_BASEPOINT}; - use super::{Bencher, OsRng}; - - #[bench] - fn bench_double_scalar_mul_basepoint(b: &mut Bencher) { - let A = A_TIMES_BASEPOINT.decompress().unwrap(); - b.iter(|| vartime::double_scalar_mul_basepoint(&A_SCALAR, &A, &B_SCALAR)); - } - - #[bench] - #[cfg(feature="precomputed_tables")] - fn ten_fold_scalar_mul(b: &mut Bencher) { - let mut csprng: OsRng = OsRng::new().unwrap(); - // Create 10 random scalars - let scalars: Vec<_> = (0..10).map(|_| Scalar::random(&mut csprng)).collect(); - // Create 10 points (by doing scalar mults) - let B = &constants::ED25519_BASEPOINT_TABLE; - let points: Vec<_> = scalars.iter().map(|s| B * &s).collect(); - - // XXX Currently Rust's benchmarking implementation doesn't - // allow you to specify a sequence of random inputs, but only - // many trials of the same input. - // - // Since this is a variable-time function, this means the - // benchmark is only useful as a ballpark measurement. - b.iter(|| vartime::multiscalar_mul(&scalars, &points)); - } - } -} diff --git a/src/field.rs b/src/field.rs index 6b599f4..81251f9 100644 --- a/src/field.rs +++ b/src/field.rs @@ -497,50 +497,3 @@ mod test { } } } - -#[cfg(all(test, feature = "bench"))] -mod bench { - use test::Bencher; - - use super::*; - use super::test::A_BYTES; - - #[bench] - fn fieldelement_a_mul_a(b: &mut Bencher) { - let a = FieldElement::from_bytes(&A_BYTES); - b.iter(|| &a * &a); - } - - #[bench] - fn fieldelement_a_sq(b: &mut Bencher) { - let a = FieldElement::from_bytes(&A_BYTES); - b.iter(|| a.square()); - } - - #[bench] - fn fieldelement_a_inv(b: &mut Bencher) { - let a = FieldElement::from_bytes(&A_BYTES); - b.iter(|| a.invert()); - } - - #[bench] - fn batch_16_inv(b: &mut Bencher) { - let a = FieldElement::from_bytes(&A_BYTES); - let mut a_vec = vec![a; 16]; - b.iter(|| FieldElement::batch_invert(&mut a_vec)); - } - - #[bench] - fn batch_128_inv(b: &mut Bencher) { - let a = FieldElement::from_bytes(&A_BYTES); - let mut a_vec = vec![a; 128]; - b.iter(|| FieldElement::batch_invert(&mut a_vec)); - } - - #[bench] - fn batch_1024_inv(b: &mut Bencher) { - let a = FieldElement::from_bytes(&A_BYTES); - let mut a_vec = vec![a; 1024]; - b.iter(|| FieldElement::batch_invert(&mut a_vec)); - } -} diff --git a/src/lib.rs b/src/lib.rs index 5e9c854..bb788c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,6 @@ #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(feature = "alloc", feature(alloc))] -#![cfg_attr(feature = "bench", feature(test))] #![cfg_attr(feature = "nightly", feature(i128_type))] #![cfg_attr(feature = "nightly", feature(cfg_target_feature))] @@ -41,9 +40,6 @@ extern crate alloc; extern crate clear_on_drop; -#[cfg(all(test, feature = "bench"))] -extern crate test; - #[cfg(feature = "yolocrypto")] extern crate stdsimd; diff --git a/src/montgomery.rs b/src/montgomery.rs index 81337c5..8be9ec0 100644 --- a/src/montgomery.rs +++ b/src/montgomery.rs @@ -347,22 +347,3 @@ mod test { assert_eq!(result, expected.to_montgomery()) } } - -#[cfg(all(test, feature = "bench"))] -#[cfg(feature="precomputed_tables")] -mod bench { - use rand::OsRng; - use constants::ED25519_BASEPOINT_TABLE; - use constants::X25519_BASEPOINT; - use test::Bencher; - use super::*; - - #[bench] - fn montgomery_ladder(b: &mut Bencher) { - let mut csprng: OsRng = OsRng::new().unwrap(); - let s: Scalar = Scalar::random(&mut csprng); - let P: MontgomeryPoint = (&Scalar::random(&mut csprng) * &ED25519_BASEPOINT_TABLE).to_montgomery(); - - b.iter(|| s * P); - } -} diff --git a/src/ristretto.rs b/src/ristretto.rs index 0426766..f2fcce0 100644 --- a/src/ristretto.rs +++ b/src/ristretto.rs @@ -1499,54 +1499,3 @@ mod test { } } } - -#[cfg(all(test, feature = "bench"))] -mod bench { - use rand::OsRng; - use test::Bencher; - - use super::*; - - #[bench] - #[cfg(feature="precomputed_tables")] - fn decompression(b: &mut Bencher) { - let mut rng = OsRng::new().unwrap(); - let B = &constants::RISTRETTO_BASEPOINT_TABLE; - let P = B * &Scalar::random(&mut rng); - let P_compressed = P.compress(); - b.iter(|| P_compressed.decompress().unwrap()); - } - - #[bench] - #[cfg(feature="precomputed_tables")] - fn compression(b: &mut Bencher) { - let mut rng = OsRng::new().unwrap(); - let B = &constants::RISTRETTO_BASEPOINT_TABLE; - let P = B * &Scalar::random(&mut rng); - b.iter(|| P.compress()); - } - - fn double_and_compress_n_random_points(n: usize, b: &mut Bencher) { - let mut rng = OsRng::new().unwrap(); - - let points: Vec = - (0..n).map(|_| RistrettoPoint::random(&mut rng)).collect(); - - b.iter(|| RistrettoPoint::double_and_compress_batch(&points) ); - } - - #[bench] - fn double_and_compress_16_random_points(b: &mut Bencher) { - double_and_compress_n_random_points(16, b); - } - - #[bench] - fn double_and_compress_128_random_points(b: &mut Bencher) { - double_and_compress_n_random_points(128, b); - } - - #[bench] - fn double_and_compress_1024_random_points(b: &mut Bencher) { - double_and_compress_n_random_points(1024, b); - } -} diff --git a/src/scalar.rs b/src/scalar.rs index db17193..7dae1e1 100644 --- a/src/scalar.rs +++ b/src/scalar.rs @@ -972,32 +972,3 @@ mod test { Scalar::batch_invert(&mut xs); } } - -#[cfg(all(test, feature = "bench"))] -mod bench { - use rand::OsRng; - use test::Bencher; - - use super::*; - use super::test::{X}; - - #[bench] - fn reduce(b: &mut Bencher) { - let unreduced = Scalar::from_bits([0xff; 32]); - - b.iter(|| unreduced.reduce()); - } - - #[bench] - fn scalar_random(b: &mut Bencher) { - let mut csprng: OsRng = OsRng::new().unwrap(); - - b.iter(|| Scalar::random(&mut csprng)); - } - - #[bench] - fn invert(b: &mut Bencher) { - let x = X.unpack(); - b.iter(|| x.invert()); - } -}