Move AVX2 code into a backend

This commit is contained in:
Henry de Valence 2017-11-17 13:25:38 -08:00
parent 2b37a65d66
commit ed24d1c5fa
7 changed files with 13 additions and 9 deletions

View file

@ -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"

View file

@ -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

View file

@ -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<Item = &'a Scalar>,
J: IntoIterator<Item = &'b ExtendedPoint>
{
use edwards::select_precomputed_point;
use traits::select_precomputed_point;
//assert_eq!(scalars.len(), points.len());
let lookup_tables: Vec<_> = points.into_iter()

View file

@ -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;

View file

@ -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;