mirror of
https://github.com/saymrwulf/risc0-curve25519-dalek-source.git
synced 2026-09-05 20:10:35 +00:00
Rename OddLookupTable to NafLookupTable5.
An OddLookupTable corresponds to a non-adjacent form of width 5.
This commit is contained in:
parent
7e0ddf6b98
commit
753a0292de
8 changed files with 26 additions and 26 deletions
8
build.rs
8
build.rs
|
|
@ -59,7 +59,7 @@ mod scalar_mul;
|
|||
|
||||
use edwards::EdwardsBasepointTable;
|
||||
use curve_models::AffineNielsPoint;
|
||||
use scalar_mul::window::OddLookupTable;
|
||||
use scalar_mul::window::NafLookupTable5;
|
||||
|
||||
fn main() {
|
||||
// Enable the "precomputed_tables" feature in the main build stage
|
||||
|
|
@ -86,7 +86,7 @@ use edwards::EdwardsBasepointTable;
|
|||
use curve_models::AffineNielsPoint;
|
||||
|
||||
use scalar_mul::window::LookupTable;
|
||||
use scalar_mul::window::OddLookupTable;
|
||||
use scalar_mul::window::NafLookupTable5;
|
||||
|
||||
/// Table containing precomputed multiples of the Ed25519 basepoint \\\\(B = (x, 4/5)\\\\).
|
||||
pub const ED25519_BASEPOINT_TABLE: EdwardsBasepointTable = ED25519_BASEPOINT_TABLE_INNER_DOC_HIDDEN;
|
||||
|
|
@ -101,13 +101,13 @@ pub const ED25519_BASEPOINT_TABLE_INNER_DOC_HIDDEN: EdwardsBasepointTable = {:?}
|
|||
|
||||
// Now generate AFFINE_ODD_MULTIPLES_OF_BASEPOINT
|
||||
let B = &constants::ED25519_BASEPOINT_POINT;
|
||||
let odd_multiples = OddLookupTable::<AffineNielsPoint>::from(B);
|
||||
let odd_multiples = NafLookupTable5::<AffineNielsPoint>::from(B);
|
||||
|
||||
f.write_all(
|
||||
format!(
|
||||
"\n
|
||||
/// Odd multiples of the basepoint `[B, 3B, 5B, 7B, 9B, 11B, 13B, 15B]`.
|
||||
pub(crate) const AFFINE_ODD_MULTIPLES_OF_BASEPOINT: OddLookupTable<AffineNielsPoint> = {:?};
|
||||
pub(crate) const AFFINE_ODD_MULTIPLES_OF_BASEPOINT: NafLookupTable5<AffineNielsPoint> = {:?};
|
||||
\n\n",
|
||||
&odd_multiples
|
||||
).as_bytes(),
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
use core::simd::u32x8;
|
||||
|
||||
use scalar_mul::window::OddLookupTable;
|
||||
use scalar_mul::window::NafLookupTable5;
|
||||
use backend::avx2::field::FieldElement32x4;
|
||||
use backend::avx2::edwards::{ExtendedPoint, CachedPoint};
|
||||
|
||||
|
|
@ -53,8 +53,8 @@ pub(crate) static P_TIMES_2_MASKED: FieldElement32x4 = FieldElement32x4([
|
|||
]);
|
||||
|
||||
/// Odd multiples of the Ed25519 basepoint:
|
||||
pub(crate) static BASEPOINT_ODD_LOOKUP_TABLE: OddLookupTable<CachedPoint> =
|
||||
OddLookupTable([
|
||||
pub(crate) static BASEPOINT_ODD_LOOKUP_TABLE: NafLookupTable5<CachedPoint> =
|
||||
NafLookupTable5([
|
||||
CachedPoint(FieldElement32x4([
|
||||
u32x8::new(3571425, 10045002, 19036563, 1096096, 243332, 65897020, 0, 28963681),
|
||||
u32x8::new(30896895, 63055514, 1614915, 5095970, 0, 53791688, 0, 31258312),
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ use subtle::ConditionallyAssignable;
|
|||
use subtle::Choice;
|
||||
|
||||
use edwards;
|
||||
use scalar_mul::window::{LookupTable, OddLookupTable};
|
||||
use scalar_mul::window::{LookupTable, NafLookupTable5};
|
||||
|
||||
use traits::Identity;
|
||||
|
||||
|
|
@ -294,7 +294,7 @@ impl<'a> From<&'a edwards::EdwardsPoint> for LookupTable<CachedPoint> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a edwards::EdwardsPoint> for OddLookupTable<CachedPoint> {
|
||||
impl<'a> From<&'a edwards::EdwardsPoint> for NafLookupTable5<CachedPoint> {
|
||||
fn from(point: &'a edwards::EdwardsPoint) -> Self {
|
||||
let A = ExtendedPoint::from(*point);
|
||||
let mut Ai = [CachedPoint::from(A); 8];
|
||||
|
|
@ -303,7 +303,7 @@ impl<'a> From<&'a edwards::EdwardsPoint> for OddLookupTable<CachedPoint> {
|
|||
Ai[i + 1] = (&A2 + &Ai[i]).into();
|
||||
}
|
||||
// Now Ai = [A, 3A, 5A, 7A, 9A, 11A, 13A, 15A]
|
||||
OddLookupTable(Ai)
|
||||
NafLookupTable5(Ai)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
use traits::Identity;
|
||||
use scalar::Scalar;
|
||||
use edwards::EdwardsPoint;
|
||||
use scalar_mul::window::OddLookupTable;
|
||||
use scalar_mul::window::NafLookupTable5;
|
||||
use backend::avx2::edwards::{CachedPoint, ExtendedPoint};
|
||||
use backend::avx2::constants::BASEPOINT_ODD_LOOKUP_TABLE;
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ pub fn mul(a: &Scalar, A: &EdwardsPoint, b: &Scalar) -> EdwardsPoint {
|
|||
}
|
||||
}
|
||||
|
||||
let table_A = OddLookupTable::<CachedPoint>::from(A);
|
||||
let table_A = NafLookupTable5::<CachedPoint>::from(A);
|
||||
let table_B = &BASEPOINT_ODD_LOOKUP_TABLE;
|
||||
|
||||
let mut Q = ExtendedPoint::identity();
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use core::borrow::Borrow;
|
|||
use traits::Identity;
|
||||
use scalar::Scalar;
|
||||
use edwards::EdwardsPoint;
|
||||
use scalar_mul::window::OddLookupTable;
|
||||
use scalar_mul::window::NafLookupTable5;
|
||||
use backend::avx2::edwards::{CachedPoint, ExtendedPoint};
|
||||
|
||||
/// Perform variable-time, variable-base scalar multiplication.
|
||||
|
|
@ -31,7 +31,7 @@ where
|
|||
.collect();
|
||||
let lookup_tables: Vec<_> = points
|
||||
.into_iter()
|
||||
.map(|point| OddLookupTable::<CachedPoint>::from(point.borrow()))
|
||||
.map(|point| NafLookupTable5::<CachedPoint>::from(point.borrow()))
|
||||
.collect();
|
||||
|
||||
let mut Q = ExtendedPoint::identity();
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use traits::Identity;
|
|||
use scalar::Scalar;
|
||||
use edwards::EdwardsPoint;
|
||||
use curve_models::{ProjectiveNielsPoint, ProjectivePoint};
|
||||
use scalar_mul::window::OddLookupTable;
|
||||
use scalar_mul::window::NafLookupTable5;
|
||||
|
||||
/// Compute \\(aA + bB\\) in variable time, where \\(B\\) is the Ed25519 basepoint.
|
||||
pub fn mul(a: &Scalar, A: &EdwardsPoint, b: &Scalar) -> EdwardsPoint {
|
||||
|
|
@ -30,7 +30,7 @@ pub fn mul(a: &Scalar, A: &EdwardsPoint, b: &Scalar) -> EdwardsPoint {
|
|||
}
|
||||
}
|
||||
|
||||
let table_A = OddLookupTable::<ProjectiveNielsPoint>::from(A);
|
||||
let table_A = NafLookupTable5::<ProjectiveNielsPoint>::from(A);
|
||||
let table_B = &constants::AFFINE_ODD_MULTIPLES_OF_BASEPOINT;
|
||||
|
||||
let mut r = ProjectivePoint::identity();
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use traits::Identity;
|
|||
use scalar::Scalar;
|
||||
use edwards::EdwardsPoint;
|
||||
use curve_models::{CompletedPoint, ProjectivePoint, ProjectiveNielsPoint};
|
||||
use scalar_mul::window::OddLookupTable;
|
||||
use scalar_mul::window::NafLookupTable5;
|
||||
|
||||
/// Perform variable-time, variable-base scalar multiplication.
|
||||
pub(crate) fn multiscalar_mul<I, J>(scalars: I, points: J) -> EdwardsPoint
|
||||
|
|
@ -31,7 +31,7 @@ where
|
|||
.collect();
|
||||
let lookup_tables: Vec<_> = points
|
||||
.into_iter()
|
||||
.map(|P| OddLookupTable::<ProjectiveNielsPoint>::from(P.borrow()))
|
||||
.map(|P| NafLookupTable5::<ProjectiveNielsPoint>::from(P.borrow()))
|
||||
.collect();
|
||||
|
||||
let mut r = ProjectivePoint::identity();
|
||||
|
|
|
|||
|
|
@ -122,9 +122,9 @@ impl<'a> From<&'a EdwardsPoint> for LookupTable<AffineNielsPoint> {
|
|||
|
||||
/// Holds odd multiples 1A, 3A, ..., 15A of a point A.
|
||||
#[derive(Copy, Clone)]
|
||||
pub(crate) struct OddLookupTable<T>(pub(crate) [T; 8]);
|
||||
pub(crate) struct NafLookupTable5<T>(pub(crate) [T; 8]);
|
||||
|
||||
impl<T: Copy> OddLookupTable<T> {
|
||||
impl<T: Copy> NafLookupTable5<T> {
|
||||
/// Given public, odd \\( x \\) with \\( 0 < x < 2^4 \\), return \\(xA\\).
|
||||
pub fn select(&self, x: usize) -> T {
|
||||
debug_assert_eq!(x & 1, 1);
|
||||
|
|
@ -134,13 +134,13 @@ impl<T: Copy> OddLookupTable<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Debug> Debug for OddLookupTable<T> {
|
||||
impl<T: Debug> Debug for NafLookupTable5<T> {
|
||||
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
||||
write!(f, "OddLookupTable({:?})", self.0)
|
||||
write!(f, "NafLookupTable5({:?})", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a EdwardsPoint> for OddLookupTable<ProjectiveNielsPoint> {
|
||||
impl<'a> From<&'a EdwardsPoint> for NafLookupTable5<ProjectiveNielsPoint> {
|
||||
fn from(A: &'a EdwardsPoint) -> Self {
|
||||
let mut Ai = [A.to_projective_niels(); 8];
|
||||
let A2 = A.double();
|
||||
|
|
@ -148,11 +148,11 @@ impl<'a> From<&'a EdwardsPoint> for OddLookupTable<ProjectiveNielsPoint> {
|
|||
Ai[i + 1] = (&A2 + &Ai[i]).to_extended().to_projective_niels();
|
||||
}
|
||||
// Now Ai = [A, 3A, 5A, 7A, 9A, 11A, 13A, 15A]
|
||||
OddLookupTable(Ai)
|
||||
NafLookupTable5(Ai)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a EdwardsPoint> for OddLookupTable<AffineNielsPoint> {
|
||||
impl<'a> From<&'a EdwardsPoint> for NafLookupTable5<AffineNielsPoint> {
|
||||
fn from(A: &'a EdwardsPoint) -> Self {
|
||||
let mut Ai = [A.to_affine_niels(); 8];
|
||||
let A2 = A.double();
|
||||
|
|
@ -160,6 +160,6 @@ impl<'a> From<&'a EdwardsPoint> for OddLookupTable<AffineNielsPoint> {
|
|||
Ai[i + 1] = (&A2 + &Ai[i]).to_extended().to_affine_niels();
|
||||
}
|
||||
// Now Ai = [A, 3A, 5A, 7A, 9A, 11A, 13A, 15A]
|
||||
OddLookupTable(Ai)
|
||||
NafLookupTable5(Ai)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue