From 089efbbbbe91c2cf97a00cb19711e3d2e76667b1 Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Mon, 30 Oct 2017 16:52:27 -0700 Subject: [PATCH] Prune constants that are no longer used anywhere --- src/constants.rs | 40 ---------------------------------------- src/constants_32bit.rs | 37 ------------------------------------- src/constants_64bit.rs | 22 ---------------------- 3 files changed, 99 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index 09880dd..86a71a5 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -28,20 +28,6 @@ pub use constants_64bit::*; #[cfg(not(feature="radix_51"))] pub use constants_32bit::*; -/// (p-1)/2, in little-endian bytes. -pub const HALF_P_MINUS_1_BYTES: [u8; 32] = - [0xf6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f]; - -/// `HALF_Q_MINUS_1_BYTES` is (2^255-20)/2 expressed in little endian form. -pub const HALF_Q_MINUS_1_BYTES: [u8; 32] = [ // halfQMinus1Bytes - 0xf6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 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 @@ -123,13 +109,6 @@ mod test { } } - #[test] - fn test_half() { - let one = FieldElement::one(); - let two = &one + &one; - assert_eq!(one, &two * &constants::HALF); - } - /// Test that the constant for sqrt(-486664) really is a square /// root of -486664. #[test] @@ -204,14 +183,6 @@ mod test { assert_eq!(d2, constants::d2); } - #[test] - fn test_d4() { - let mut four = FieldElement::zero(); - // XXX should have a way to create small field elements - four.0[0] = 4; - assert_eq!(&constants::d * &four, constants::d4); - } - #[test] fn test_sqrt_ad_minus_one() { let a = FieldElement::minus_one(); @@ -220,15 +191,4 @@ mod test { assert_eq!(should_be_ad_minus_one, ad_minus_one); } - #[test] - fn test_a_minus_d() { - let a = FieldElement::minus_one(); - let a_minus_d = &a - &constants::d; - assert_eq!(a_minus_d, constants::a_minus_d); - let (_, invsqrt_a_minus_d) = constants::a_minus_d.invsqrt(); - assert_eq!(invsqrt_a_minus_d, constants::invsqrt_a_minus_d); - let inv_a_minus_d = invsqrt_a_minus_d.square(); - assert_eq!(inv_a_minus_d, constants::inv_a_minus_d); - assert_eq!(&inv_a_minus_d * &a_minus_d, FieldElement::one()); - } } diff --git a/src/constants_32bit.rs b/src/constants_32bit.rs index 6cbe4db..fd86cd1 100644 --- a/src/constants_32bit.rs +++ b/src/constants_32bit.rs @@ -31,14 +31,6 @@ pub const d2: FieldElement32 = FieldElement32([ -21827239, -5839606, -30745221, 13898782, 229458, 15978800, -12551817, -6495438, 29715968, 9444199, ]); -pub const d4: FieldElement32 = FieldElement32([ - 23454405, -11679213, 5618422, -5756869, 458917, - -1596832, -25103633, -12990876, -7676928, -14666033 ]); - -pub const a_minus_d: FieldElement32 = FieldElement32([ - 10913609, -13857413, 15372611, -6949391, -114729, - 8787816, 6275908, 3247719, 18696448, 12055116, ]); - pub const sqrt_ad_minus_one: FieldElement32 = FieldElement32([ 24849947, -153582, -23613485, 6347715, -21072328, -667138, -25271143, -15367704, -870347, 14525639 ]); @@ -48,18 +40,6 @@ pub const invsqrt_a_minus_d: FieldElement32 = FieldElement32([ 120897, 20826367, -7060776, 6093568, -1986012 ]); -#[cfg(not(feature="radix_51"))] -pub const inv_a_minus_d: FieldElement32 = FieldElement32([ - -121666, 0, 0, 0, 0, 0, 0, 0, 0, 0 -]); - -/// (p-1)/2, in little-endian bytes. -pub const HALF_P_MINUS_1_BYTES: [u8; 32] = - [0xf6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f]; - /// Precomputed value of one of the square roots of -1 (mod p) pub const SQRT_M1: FieldElement32 = FieldElement32([ -32595792, -7943725, 9377950, 3500415, 12389472, @@ -71,10 +51,6 @@ pub const MSQRT_M1: FieldElement32 = FieldElement32([ 32595792, 7943725, -9377950, -3500415, -12389472, 272473, 25146209, 2005654, -326686, -11406482, ]); -/// Precomputed value of 1/2 (mod p). -pub const HALF: FieldElement32 = FieldElement32([ - 10, 0, 0, 0, 0, 0, 0, 0, 0, -16777216, ]); - /// In Montgomery form y² = x³+Ax²+x, Curve25519 has A=486662. pub const A: FieldElement32 = FieldElement32([ 486662, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]); @@ -82,24 +58,11 @@ pub const A: FieldElement32 = FieldElement32([ /// `APLUS2_OVER_FOUR` is (A+2)/4. (This is used internally within the Montgomery ladder.) pub const APLUS2_OVER_FOUR: FieldElement32 = FieldElement32([121666, 0, 0, 0, 0, 0, 0, 0, 0, 0]); -/// `SQRT_MINUS_A` is sqrt(-486662) -// XXX I think that this was used in Adam's code for his elligator -// implementation, but that should maybe be using sqrt(-486664) -// instead...? - hdevalence -pub const SQRT_MINUS_A: FieldElement32 = FieldElement32([ // sqrtMinusA - 12222970, 8312128, 11511410, -9067497, 15300785, - 241793, -25456130, -14121551, 12187136, -3972024, ]); - /// `SQRT_MINUS_APLUS2` is sqrt(-486664) pub const SQRT_MINUS_APLUS2: FieldElement32 = FieldElement32([ -12222970, -8312128, -11511410, 9067497, -15300785, -241793, 25456130, 14121551, -12187136, 3972024]); -/// `SQRT_MINUS_HALF` is sqrt(-1/2) -pub const SQRT_MINUS_HALF: FieldElement32 = FieldElement32([ // sqrtMinusHalf - -17256545, 3971863, 28865457, -1750208, 27359696, - -16640980, 12573105, 1002827, -163343, 11073975, ]); - /// Basepoint has y = 4/5. This is called `_POINT` to distinguish it from `_TABLE`, which should /// be used for scalar multiplication (it's much faster). pub const ED25519_BASEPOINT_POINT: ExtendedPoint = ExtendedPoint{ diff --git a/src/constants_64bit.rs b/src/constants_64bit.rs index f497b0d..bf03063 100644 --- a/src/constants_64bit.rs +++ b/src/constants_64bit.rs @@ -23,16 +23,10 @@ use edwards::ExtendedPoint; use edwards::AffineNielsPoint; use edwards::EdwardsBasepointTable; -pub const p: FieldElement64 = FieldElement64([2251799813685229, 2251799813685247, 2251799813685247, 2251799813685247, 2251799813685247]); - pub const d: FieldElement64 = FieldElement64([929955233495203, 466365720129213, 1662059464998953, 2033849074728123, 1442794654840575]); pub const d2: FieldElement64 = FieldElement64([1859910466990425, 932731440258426, 1072319116312658, 1815898335770999, 633789495995903]); -pub const d4: FieldElement64 = FieldElement64([1468021120295602, 1865462880516853, 2144638232625316, 1379996857856750, 1267578991991807]); - -pub const a_minus_d: FieldElement64 = FieldElement64([1321844580190025, 1785434093556034, 589740348686294, 217950738957124, 809005158844672]); - pub const sqrt_ad_minus_one: FieldElement64 = FieldElement64([ 2241493124984347, 425987919032274, 2207028919301688, 1220490630685848, 974799131293748 ]); @@ -41,10 +35,6 @@ pub const invsqrt_a_minus_d: FieldElement64 = FieldElement64([ 278908739862762, 821645201101625, 8113234426968, 1777959178193151, 2118520810568447 ]); -pub const inv_a_minus_d: FieldElement64 = FieldElement64([ - 2251799813563563, 2251799813685247, 2251799813685247, 2251799813685247, 2251799813685247 -]); - /// Precomputed value of one of the square roots of -1 (mod p) pub const SQRT_M1: FieldElement64 = FieldElement64([1718705420411056, 234908883556509, 2233514472574048, 2117202627021982, 765476049583133]); @@ -52,27 +42,15 @@ pub const SQRT_M1: FieldElement64 = FieldElement64([1718705420411056, 2349088835 /// i.e., `MSQRT_M1 = -SQRT_M1`. pub const MSQRT_M1: FieldElement64 = FieldElement64([533094393274173, 2016890930128738, 18285341111199, 134597186663265, 1486323764102114]); -/// Precomputed value of 1/2 (mod p). -pub const HALF: FieldElement64 = FieldElement64([2251799813685239, 2251799813685247, 2251799813685247, 2251799813685247, 1125899906842623]); - /// In Montgomery form y² = x³+Ax²+x, Curve25519 has A=486662. pub const A: FieldElement64 = FieldElement64([486662, 0, 0, 0, 0]); /// `APLUS2_OVER_FOUR` is (A+2)/4. (This is used internally within the Montgomery ladder.) pub const APLUS2_OVER_FOUR: FieldElement64 = FieldElement64([121666, 0, 0, 0, 0]); -/// `SQRT_MINUS_A` is sqrt(-486662) -// XXX I think that this was used in Adam's code for his elligator -// implementation, but that should maybe be using sqrt(-486664) -// instead...? - hdevalence -pub const SQRT_MINUS_A: FieldElement64 = FieldElement64([557817479725543, 1643290402203250, 16226468853936, 1304118542701054, 1985241807451647]); - /// `SQRT_MINUS_APLUS2` is sqrt(-486664) pub const SQRT_MINUS_APLUS2: FieldElement64 = FieldElement64([1693982333959686, 608509411481997, 2235573344831311, 947681270984193, 266558006233600]); -/// `SQRT_MINUS_HALF` is sqrt(-1/2) -pub const SQRT_MINUS_HALF: FieldElement64 = FieldElement64([266547196637087, 2134345371906993, 1135042577398223, 67298593331632, 743161882051057]); - /// Basepoint has y = 4/5. This is called `_POINT` to distinguish it from `_TABLE`, which should /// be used for scalar multiplication (it's much faster). pub const ED25519_BASEPOINT_POINT: ExtendedPoint = ExtendedPoint{