mirror of
https://github.com/saymrwulf/betrusted-curve25519-dalek-source.git
synced 2026-09-10 21:21:08 +00:00
rustfmt src/backend/vector/scalar_mul (no changes besides formatting)
This commit is contained in:
parent
0db8783be8
commit
219995dbc9
5 changed files with 402 additions and 406 deletions
|
|
@ -15,27 +15,27 @@
|
|||
)]
|
||||
pub mod spec {
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use core::borrow::Borrow;
|
||||
use core::cmp::Ordering;
|
||||
use core::borrow::Borrow;
|
||||
use core::cmp::Ordering;
|
||||
|
||||
#[for_target_feature("avx2")]
|
||||
use crate::backend::vector::avx2::{CachedPoint, ExtendedPoint};
|
||||
#[for_target_feature("avx2")]
|
||||
use crate::backend::vector::avx2::{CachedPoint, ExtendedPoint};
|
||||
|
||||
#[for_target_feature("avx512ifma")]
|
||||
use crate::backend::vector::ifma::{CachedPoint, ExtendedPoint};
|
||||
#[for_target_feature("avx512ifma")]
|
||||
use crate::backend::vector::ifma::{CachedPoint, ExtendedPoint};
|
||||
|
||||
use crate::edwards::EdwardsPoint;
|
||||
use crate::scalar::Scalar;
|
||||
use crate::traits::{Identity, VartimeMultiscalarMul};
|
||||
use crate::edwards::EdwardsPoint;
|
||||
use crate::scalar::Scalar;
|
||||
use crate::traits::{Identity, VartimeMultiscalarMul};
|
||||
|
||||
/// Implements a version of Pippenger's algorithm.
|
||||
///
|
||||
/// See the documentation in the serial `scalar_mul::pippenger` module for details.
|
||||
pub struct Pippenger;
|
||||
/// Implements a version of Pippenger's algorithm.
|
||||
///
|
||||
/// See the documentation in the serial `scalar_mul::pippenger` module for details.
|
||||
pub struct Pippenger;
|
||||
|
||||
impl VartimeMultiscalarMul for Pippenger {
|
||||
impl VartimeMultiscalarMul for Pippenger {
|
||||
type Point = EdwardsPoint;
|
||||
|
||||
fn optional_multiscalar_mul<I, J>(scalars: I, points: J) -> Option<EdwardsPoint>
|
||||
|
|
@ -134,10 +134,10 @@ impl VartimeMultiscalarMul for Pippenger {
|
|||
.into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
#[test]
|
||||
fn test_vartime_pippenger() {
|
||||
use super::*;
|
||||
|
|
@ -173,6 +173,5 @@ mod test {
|
|||
n = n / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,28 +17,28 @@
|
|||
)]
|
||||
pub mod spec {
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use core::borrow::Borrow;
|
||||
use core::cmp::Ordering;
|
||||
use core::borrow::Borrow;
|
||||
use core::cmp::Ordering;
|
||||
|
||||
#[for_target_feature("avx2")]
|
||||
use crate::backend::vector::avx2::{CachedPoint, ExtendedPoint};
|
||||
#[for_target_feature("avx2")]
|
||||
use crate::backend::vector::avx2::{CachedPoint, ExtendedPoint};
|
||||
|
||||
#[for_target_feature("avx512ifma")]
|
||||
use crate::backend::vector::ifma::{CachedPoint, ExtendedPoint};
|
||||
#[for_target_feature("avx512ifma")]
|
||||
use crate::backend::vector::ifma::{CachedPoint, ExtendedPoint};
|
||||
|
||||
use crate::edwards::EdwardsPoint;
|
||||
use crate::scalar::Scalar;
|
||||
use crate::traits::Identity;
|
||||
use crate::traits::VartimePrecomputedMultiscalarMul;
|
||||
use crate::window::{NafLookupTable5, NafLookupTable8};
|
||||
use crate::edwards::EdwardsPoint;
|
||||
use crate::scalar::Scalar;
|
||||
use crate::traits::Identity;
|
||||
use crate::traits::VartimePrecomputedMultiscalarMul;
|
||||
use crate::window::{NafLookupTable5, NafLookupTable8};
|
||||
|
||||
pub struct VartimePrecomputedStraus {
|
||||
pub struct VartimePrecomputedStraus {
|
||||
static_lookup_tables: Vec<NafLookupTable8<CachedPoint>>,
|
||||
}
|
||||
}
|
||||
|
||||
impl VartimePrecomputedMultiscalarMul for VartimePrecomputedStraus {
|
||||
impl VartimePrecomputedMultiscalarMul for VartimePrecomputedStraus {
|
||||
type Point = EdwardsPoint;
|
||||
|
||||
fn new<I>(static_points: I) -> Self
|
||||
|
|
@ -123,6 +123,5 @@ impl VartimePrecomputedMultiscalarMul for VartimePrecomputedStraus {
|
|||
|
||||
Some(R.into())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,35 +17,35 @@
|
|||
)]
|
||||
pub mod spec {
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use core::borrow::Borrow;
|
||||
use core::cmp::Ordering;
|
||||
use core::borrow::Borrow;
|
||||
use core::cmp::Ordering;
|
||||
|
||||
use zeroize::Zeroizing;
|
||||
use zeroize::Zeroizing;
|
||||
|
||||
#[for_target_feature("avx2")]
|
||||
use crate::backend::vector::avx2::{CachedPoint, ExtendedPoint};
|
||||
#[for_target_feature("avx2")]
|
||||
use crate::backend::vector::avx2::{CachedPoint, ExtendedPoint};
|
||||
|
||||
#[for_target_feature("avx512ifma")]
|
||||
use crate::backend::vector::ifma::{CachedPoint, ExtendedPoint};
|
||||
#[for_target_feature("avx512ifma")]
|
||||
use crate::backend::vector::ifma::{CachedPoint, ExtendedPoint};
|
||||
|
||||
use crate::edwards::EdwardsPoint;
|
||||
use crate::scalar::Scalar;
|
||||
use crate::traits::{Identity, MultiscalarMul, VartimeMultiscalarMul};
|
||||
use crate::window::{LookupTable, NafLookupTable5};
|
||||
use crate::edwards::EdwardsPoint;
|
||||
use crate::scalar::Scalar;
|
||||
use crate::traits::{Identity, MultiscalarMul, VartimeMultiscalarMul};
|
||||
use crate::window::{LookupTable, NafLookupTable5};
|
||||
|
||||
/// Multiscalar multiplication using interleaved window / Straus'
|
||||
/// method. See the `Straus` struct in the serial backend for more
|
||||
/// details.
|
||||
///
|
||||
/// This exists as a seperate implementation from that one because the
|
||||
/// AVX2 code uses different curve models (it does not pass between
|
||||
/// multiple models during scalar mul), and it has to convert the
|
||||
/// point representation on the fly.
|
||||
pub struct Straus {}
|
||||
/// Multiscalar multiplication using interleaved window / Straus'
|
||||
/// method. See the `Straus` struct in the serial backend for more
|
||||
/// details.
|
||||
///
|
||||
/// This exists as a seperate implementation from that one because the
|
||||
/// AVX2 code uses different curve models (it does not pass between
|
||||
/// multiple models during scalar mul), and it has to convert the
|
||||
/// point representation on the fly.
|
||||
pub struct Straus {}
|
||||
|
||||
impl MultiscalarMul for Straus {
|
||||
impl MultiscalarMul for Straus {
|
||||
type Point = EdwardsPoint;
|
||||
|
||||
fn multiscalar_mul<I, J>(scalars: I, points: J) -> EdwardsPoint
|
||||
|
|
@ -80,9 +80,9 @@ impl MultiscalarMul for Straus {
|
|||
}
|
||||
Q.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl VartimeMultiscalarMul for Straus {
|
||||
impl VartimeMultiscalarMul for Straus {
|
||||
type Point = EdwardsPoint;
|
||||
|
||||
fn optional_multiscalar_mul<I, J>(scalars: I, points: J) -> Option<EdwardsPoint>
|
||||
|
|
@ -120,6 +120,5 @@ impl VartimeMultiscalarMul for Straus {
|
|||
|
||||
Some(Q.into())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,19 +6,19 @@
|
|||
)]
|
||||
pub mod spec {
|
||||
|
||||
#[for_target_feature("avx2")]
|
||||
use crate::backend::vector::avx2::{CachedPoint, ExtendedPoint};
|
||||
#[for_target_feature("avx2")]
|
||||
use crate::backend::vector::avx2::{CachedPoint, ExtendedPoint};
|
||||
|
||||
#[for_target_feature("avx512ifma")]
|
||||
use crate::backend::vector::ifma::{CachedPoint, ExtendedPoint};
|
||||
#[for_target_feature("avx512ifma")]
|
||||
use crate::backend::vector::ifma::{CachedPoint, ExtendedPoint};
|
||||
|
||||
use crate::edwards::EdwardsPoint;
|
||||
use crate::scalar::Scalar;
|
||||
use crate::traits::Identity;
|
||||
use crate::window::LookupTable;
|
||||
use crate::edwards::EdwardsPoint;
|
||||
use crate::scalar::Scalar;
|
||||
use crate::traits::Identity;
|
||||
use crate::window::LookupTable;
|
||||
|
||||
/// Perform constant-time, variable-base scalar multiplication.
|
||||
pub fn mul(point: &EdwardsPoint, scalar: &Scalar) -> EdwardsPoint {
|
||||
/// Perform constant-time, variable-base scalar multiplication.
|
||||
pub fn mul(point: &EdwardsPoint, scalar: &Scalar) -> EdwardsPoint {
|
||||
// Construct a lookup table of [P,2P,3P,4P,5P,6P,7P,8P]
|
||||
let lookup_table = LookupTable::<CachedPoint>::from(point);
|
||||
// Setting s = scalar, compute
|
||||
|
|
@ -40,6 +40,5 @@ pub fn mul(point: &EdwardsPoint, scalar: &Scalar) -> EdwardsPoint {
|
|||
Q = &Q + &lookup_table.select(scalar_digits[i]);
|
||||
}
|
||||
Q.into()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,29 +17,29 @@
|
|||
)]
|
||||
pub mod spec {
|
||||
|
||||
use core::cmp::Ordering;
|
||||
use core::cmp::Ordering;
|
||||
|
||||
#[for_target_feature("avx2")]
|
||||
use crate::backend::vector::avx2::{CachedPoint, ExtendedPoint};
|
||||
#[for_target_feature("avx2")]
|
||||
use crate::backend::vector::avx2::{CachedPoint, ExtendedPoint};
|
||||
|
||||
#[for_target_feature("avx512ifma")]
|
||||
use crate::backend::vector::ifma::{CachedPoint, ExtendedPoint};
|
||||
#[for_target_feature("avx512ifma")]
|
||||
use crate::backend::vector::ifma::{CachedPoint, ExtendedPoint};
|
||||
|
||||
#[cfg(feature = "precomputed-tables")]
|
||||
#[for_target_feature("avx2")]
|
||||
use crate::backend::vector::avx2::constants::BASEPOINT_ODD_LOOKUP_TABLE;
|
||||
#[cfg(feature = "precomputed-tables")]
|
||||
#[for_target_feature("avx2")]
|
||||
use crate::backend::vector::avx2::constants::BASEPOINT_ODD_LOOKUP_TABLE;
|
||||
|
||||
#[cfg(feature = "precomputed-tables")]
|
||||
#[for_target_feature("avx512ifma")]
|
||||
use crate::backend::vector::ifma::constants::BASEPOINT_ODD_LOOKUP_TABLE;
|
||||
#[cfg(feature = "precomputed-tables")]
|
||||
#[for_target_feature("avx512ifma")]
|
||||
use crate::backend::vector::ifma::constants::BASEPOINT_ODD_LOOKUP_TABLE;
|
||||
|
||||
use crate::edwards::EdwardsPoint;
|
||||
use crate::scalar::Scalar;
|
||||
use crate::traits::Identity;
|
||||
use crate::window::NafLookupTable5;
|
||||
use crate::edwards::EdwardsPoint;
|
||||
use crate::scalar::Scalar;
|
||||
use crate::traits::Identity;
|
||||
use crate::window::NafLookupTable5;
|
||||
|
||||
/// Compute \\(aA + bB\\) in variable time, where \\(B\\) is the Ed25519 basepoint.
|
||||
pub fn mul(a: &Scalar, A: &EdwardsPoint, b: &Scalar) -> EdwardsPoint {
|
||||
/// Compute \\(aA + bB\\) in variable time, where \\(B\\) is the Ed25519 basepoint.
|
||||
pub fn mul(a: &Scalar, A: &EdwardsPoint, b: &Scalar) -> EdwardsPoint {
|
||||
let a_naf = a.non_adjacent_form(5);
|
||||
|
||||
#[cfg(feature = "precomputed-tables")]
|
||||
|
|
@ -62,7 +62,8 @@ pub fn mul(a: &Scalar, A: &EdwardsPoint, b: &Scalar) -> EdwardsPoint {
|
|||
let table_B = &BASEPOINT_ODD_LOOKUP_TABLE;
|
||||
|
||||
#[cfg(not(feature = "precomputed-tables"))]
|
||||
let table_B = &NafLookupTable5::<CachedPoint>::from(&crate::constants::ED25519_BASEPOINT_POINT);
|
||||
let table_B =
|
||||
&NafLookupTable5::<CachedPoint>::from(&crate::constants::ED25519_BASEPOINT_POINT);
|
||||
|
||||
let mut Q = ExtendedPoint::identity();
|
||||
|
||||
|
|
@ -96,6 +97,5 @@ pub fn mul(a: &Scalar, A: &EdwardsPoint, b: &Scalar) -> EdwardsPoint {
|
|||
}
|
||||
|
||||
Q.into()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue