mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-06 20:41:14 +00:00
Move AVX2 code into a backend
This commit is contained in:
parent
2b37a65d66
commit
ed24d1c5fa
7 changed files with 13 additions and 9 deletions
|
|
@ -59,6 +59,7 @@ rand = "0.3"
|
||||||
generic-array = "^0.8"
|
generic-array = "^0.8"
|
||||||
digest = "0.6"
|
digest = "0.6"
|
||||||
arrayref = "0.3.4"
|
arrayref = "0.3.4"
|
||||||
|
stdsimd = { git = "https://github.com/hdevalence/stdsimd", branch="feature/more-avx2" }
|
||||||
|
|
||||||
[build-dependencies.serde]
|
[build-dependencies.serde]
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
|
|
|
||||||
2
build.rs
2
build.rs
|
|
@ -21,6 +21,8 @@ use std::path::Path;
|
||||||
// For instance, this shouldn't exist here at all, but it does.
|
// For instance, this shouldn't exist here at all, but it does.
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
#[cfg(feature = "yolocrypto")]
|
||||||
|
extern crate stdsimd;
|
||||||
|
|
||||||
// Public modules
|
// Public modules
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ use scalar::Scalar;
|
||||||
|
|
||||||
use traits::Identity;
|
use traits::Identity;
|
||||||
|
|
||||||
use avx2::field::FieldElement32x4;
|
use backend::avx2::field::FieldElement32x4;
|
||||||
use avx2::field::P_TIMES_2;
|
use backend::avx2::field::P_TIMES_2;
|
||||||
|
|
||||||
/// A point on Curve25519, represented in an AVX2-friendly format.
|
/// A point on Curve25519, represented in an AVX2-friendly format.
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[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]`,
|
/// takes `-8 ≤ x < 8` and `[16^2i * B, ..., 8 * 16^2i * B]`,
|
||||||
/// and returns `x * 16^2i * B` in constant time.
|
/// and returns `x * 16^2i * B` in constant time.
|
||||||
fn mul(self, scalar: &'b Scalar) -> ExtendedPoint {
|
fn mul(self, scalar: &'b Scalar) -> ExtendedPoint {
|
||||||
|
use traits::select_precomputed_point;
|
||||||
let e = scalar.to_radix_16();
|
let e = scalar.to_radix_16();
|
||||||
let mut h = ExtendedPoint::identity();
|
let mut h = ExtendedPoint::identity();
|
||||||
|
|
||||||
for i in (0..64).filter(|x| x % 2 == 1) {
|
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);
|
h = h.mult_by_pow_2(4);
|
||||||
|
|
||||||
for i in (0..64).filter(|x| x % 2 == 0) {
|
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
|
h
|
||||||
|
|
@ -395,7 +396,7 @@ pub fn multiscalar_mult<'a, 'b, I, J>(scalars: I, points: J) -> ExtendedPoint
|
||||||
where I: IntoIterator<Item = &'a Scalar>,
|
where I: IntoIterator<Item = &'a Scalar>,
|
||||||
J: IntoIterator<Item = &'b ExtendedPoint>
|
J: IntoIterator<Item = &'b ExtendedPoint>
|
||||||
{
|
{
|
||||||
use edwards::select_precomputed_point;
|
use traits::select_precomputed_point;
|
||||||
//assert_eq!(scalars.len(), points.len());
|
//assert_eq!(scalars.len(), points.len());
|
||||||
|
|
||||||
let lookup_tables: Vec<_> = points.into_iter()
|
let lookup_tables: Vec<_> = points.into_iter()
|
||||||
|
|
@ -28,3 +28,7 @@ pub mod u32;
|
||||||
#[cfg(feature="radix_51")]
|
#[cfg(feature="radix_51")]
|
||||||
pub mod u64;
|
pub mod u64;
|
||||||
|
|
||||||
|
/// Code using AVX2.
|
||||||
|
#[cfg(all(feature="yolocrypto", not(feature="radix_51")))]
|
||||||
|
pub mod avx2;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,9 +94,5 @@ pub(crate) mod field;
|
||||||
// Arithmetic backends (using u32, u64, etc) live here
|
// Arithmetic backends (using u32, u64, etc) live here
|
||||||
pub(crate) mod backend;
|
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.
|
// Internal curve models which are not part of the public API.
|
||||||
pub(crate) mod curve_models;
|
pub(crate) mod curve_models;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue