From c873f725a5601e425042d9c6ddd2f9a42caae965 Mon Sep 17 00:00:00 2001 From: Henry & Isis Date: Fri, 10 Mar 2017 22:21:17 -0800 Subject: [PATCH] Rename `BasepointTable` as `EdwardsBasepointTable`. --- src/constants.rs | 4 ++-- src/curve.rs | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index 6072293..bfc103d 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -23,7 +23,7 @@ use field::FieldElement; use curve::ExtendedPoint; use curve::AffineNielsPoint; use curve::CompressedEdwardsY; -use curve::BasepointTable; +use curve::EdwardsBasepointTable; use scalar::Scalar; pub const d: FieldElement = FieldElement([ @@ -226,7 +226,7 @@ pub const bi: [AffineNielsPoint; 8] = [ /// /// The table is defined so `constants::base[i][j-1] = j*(16^2i)*B`, /// for `0 ≤ i < 32`, `1 ≤ j < 9`. -pub const ED25519_BASEPOINT_TABLE: BasepointTable = BasepointTable([ +pub const ED25519_BASEPOINT_TABLE: EdwardsBasepointTable = EdwardsBasepointTable([ [ AffineNielsPoint{ y_plus_x: FieldElement([25967493, -14356035, 29566456, 3660896, -12694345, 4014787, 27544626, -11754271, -6079156, 2047605]), diff --git a/src/curve.rs b/src/curve.rs index 817a43e..b736f65 100644 --- a/src/curve.rs +++ b/src/curve.rs @@ -827,27 +827,27 @@ impl ScalarMult for ExtendedPoint { /// Precomputation #[derive(Clone)] -pub struct BasepointTable(pub [[AffineNielsPoint; 8]; 32]); +pub struct EdwardsBasepointTable(pub [[AffineNielsPoint; 8]; 32]); -impl BasepointTable { +impl EdwardsBasepointTable { /// Create a table of precomputed multiples of `basepoint`. - pub fn create(basepoint: &ExtendedPoint) -> Box { + pub fn create(basepoint: &ExtendedPoint) -> Box { // Create the table storage - // XXX this is a dirty hack, does placement new work here? - let mut table = box [[AffineNielsPoint::identity(); 8]; 32]; + // XXX can we be assured that this is not allocated on the stack? + // XXX can we skip the initialization without too much unsafety? + let mut table = box EdwardsBasepointTable([[AffineNielsPoint::identity(); 8]; 32]); let mut P = basepoint.clone(); for i in 0..32 { // P = (16^2)^i * B let mut jP = P.to_affine_niels(); for j in 1..9 { // table[i][j-1] is supposed to be j*(16^2)^i*B - table[i][j-1] = jP; + table.0[i][j-1] = jP; jP = (&P + &jP).to_extended().to_affine_niels(); } P = P.mult_by_pow_2(8); } - // XXX can we do just 1 alloc instead of 2? - return Box::new(BasepointTable(*table)); + return table } /// Construct an `ExtendedPoint` from a `Scalar`, `scalar`, by @@ -1313,7 +1313,7 @@ mod test { /// Test precomputed basepoint mult #[test] fn test_precomputed_basepoint_mult() { - let table = BasepointTable::create(&constants::ED25519_BASEPOINT); + let table = EdwardsBasepointTable::create(&constants::ED25519_BASEPOINT); let aB_1 = ExtendedPoint::basepoint_mult(&A_SCALAR); let aB_2 = table.basepoint_mult(&A_SCALAR); assert_eq!(aB_1.compress_edwards(), @@ -1490,6 +1490,6 @@ mod bench { #[bench] fn create_basepoint_table(b: &mut Bencher) { let aB = ExtendedPoint::basepoint_mult(&A_SCALAR); - b.iter(|| BasepointTable::create(&aB)); + b.iter(|| EdwardsBasepointTable::create(&aB)); } }