diff --git a/Cargo.toml b/Cargo.toml index e317204..ac1b8d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,6 +59,7 @@ rand = "0.3" generic-array = "^0.8" digest = "0.6" arrayref = "0.3.4" +stdsimd = { git = "https://github.com/hdevalence/stdsimd", branch="feature/more-avx2" } [build-dependencies.serde] version = "1.0" diff --git a/build.rs b/build.rs index 13d9715..4fba073 100644 --- a/build.rs +++ b/build.rs @@ -21,6 +21,8 @@ use std::path::Path; // For instance, this shouldn't exist here at all, but it does. #[cfg(feature = "serde")] extern crate serde; +#[cfg(feature = "yolocrypto")] +extern crate stdsimd; // Public modules diff --git a/src/avx2/edwards.rs b/src/backend/avx2/edwards.rs similarity index 99% rename from src/avx2/edwards.rs rename to src/backend/avx2/edwards.rs index c283e08..4db18f9 100644 --- a/src/avx2/edwards.rs +++ b/src/backend/avx2/edwards.rs @@ -25,8 +25,8 @@ use scalar::Scalar; use traits::Identity; -use avx2::field::FieldElement32x4; -use avx2::field::P_TIMES_2; +use backend::avx2::field::FieldElement32x4; +use backend::avx2::field::P_TIMES_2; /// A point on Curve25519, represented in an AVX2-friendly format. #[derive(Copy, Clone, Debug)] @@ -324,17 +324,18 @@ impl<'a, 'b> Mul<&'b Scalar> for &'a EdwardsBasepointTable { /// takes `-8 ≤ x < 8` and `[16^2i * B, ..., 8 * 16^2i * B]`, /// and returns `x * 16^2i * B` in constant time. fn mul(self, scalar: &'b Scalar) -> ExtendedPoint { + use traits::select_precomputed_point; let e = scalar.to_radix_16(); let mut h = ExtendedPoint::identity(); for i in (0..64).filter(|x| x % 2 == 1) { - h = &h + &edwards::select_precomputed_point(e[i], &self.0[i/2]); + h = &h + &select_precomputed_point(e[i], &self.0[i/2]); } h = h.mult_by_pow_2(4); for i in (0..64).filter(|x| x % 2 == 0) { - h = &h + &edwards::select_precomputed_point(e[i], &self.0[i/2]); + h = &h + &select_precomputed_point(e[i], &self.0[i/2]); } h @@ -395,7 +396,7 @@ pub fn multiscalar_mult<'a, 'b, I, J>(scalars: I, points: J) -> ExtendedPoint where I: IntoIterator, J: IntoIterator { - use edwards::select_precomputed_point; + use traits::select_precomputed_point; //assert_eq!(scalars.len(), points.len()); let lookup_tables: Vec<_> = points.into_iter() diff --git a/src/avx2/field.rs b/src/backend/avx2/field.rs similarity index 100% rename from src/avx2/field.rs rename to src/backend/avx2/field.rs diff --git a/src/avx2/mod.rs b/src/backend/avx2/mod.rs similarity index 100% rename from src/avx2/mod.rs rename to src/backend/avx2/mod.rs diff --git a/src/backend/mod.rs b/src/backend/mod.rs index be3a347..b6845da 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -28,3 +28,7 @@ pub mod u32; #[cfg(feature="radix_51")] pub mod u64; +/// Code using AVX2. +#[cfg(all(feature="yolocrypto", not(feature="radix_51")))] +pub mod avx2; + diff --git a/src/lib.rs b/src/lib.rs index c3a4255..2106e88 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -94,9 +94,5 @@ pub(crate) mod field; // Arithmetic backends (using u32, u64, etc) live here pub(crate) mod backend; -// XXX this should be in backend -#[cfg(all(feature="yolocrypto", not(feature="radix_51")))] -pub(crate) mod avx2; - // Internal curve models which are not part of the public API. pub(crate) mod curve_models;