From d94edc6a36411658b3235e18adbf22b4b3aff2b4 Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Sun, 8 Jan 2017 20:41:39 -0500 Subject: [PATCH] Move compressed basepoint into constants Would be good to have the basepoint itself, but this doesn't seem possible: the fields of an ExtendedPoint are not public, so we can't construct them outside of curve.rs (by design, to prevent constructing invalid points). Maybe const fn support could change this. --- src/constants.rs | 11 +++++++++++ src/curve.rs | 11 +---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index a624c6a..4c5176d 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -19,6 +19,7 @@ use field::FieldElement; use curve::PreComputedPoint; +use curve::CompressedPoint; pub const d: FieldElement = FieldElement([ -10913610, 13857413, -15372611, 6949391, 114729, @@ -54,6 +55,16 @@ pub const HALF_Q_MINUS_1_BYTES: [u8; 32] = [ // halfQMinus1Bytes 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, ]; +/// Basepoint has y = 4/5. +/// +/// Generated with Sage: these are the bytes of 4/5 in 𝔽_p. The +/// sign bit is 0 since the basepoint has x chosen to be positive. +pub const BASE_CMPRSSD: CompressedPoint = + CompressedPoint([0x58, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, + 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, + 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, + 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66]); + pub const bi: [PreComputedPoint; 8] = [ PreComputedPoint{ 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 1ce690d..8af03a5 100644 --- a/src/curve.rs +++ b/src/curve.rs @@ -821,19 +821,10 @@ mod test { use field::FieldElement; use scalar::Scalar; use constants; + use constants::BASE_CMPRSSD; use super::*; use super::select_precomputed_point; - /// Basepoint has y = 4/5. - /// - /// Generated with Sage: these are the bytes of 4/5 in 𝔽_p. The - /// sign bit is 0 since the basepoint has x chosen to be positive. - static BASE_CMPRSSD: CompressedPoint = - CompressedPoint([0x58, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, - 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, - 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, - 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66]); - /// X coordinate of the basepoint. /// = 15112221349535400772501151409588531511454012693041857206046113283949847762202 static BASE_X_COORD_BYTES: [u8; 32] =