Skip to content
This repository has been archived by the owner on Nov 9, 2023. It is now read-only.

Commit

Permalink
Move specific u64_backend values to it's constants spec file
Browse files Browse the repository at this point in the history
  • Loading branch information
CPerezz committed Sep 13, 2019
1 parent 284c394 commit 405f541
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 66 deletions.
69 changes: 60 additions & 9 deletions src/backend/u64/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::backend::u64::field::FieldElement;
use crate::backend::u64::scalar::Scalar;
use crate::edwards::*;
use crate::ristretto::{RistrettoPoint, CompressedRistretto};


/// `L` is the order of base point for Doppio, in this case it is equivalent to 2^249 + 14490550575682688738086195780655237219
Expand Down Expand Up @@ -35,6 +36,63 @@ pub const LFACTOR_FIELD: u64 = 1439961107955227;
// operation`. It's defined as: `R^2 = (2^253)^2 % L`
pub const INV_RR: FieldElement = FieldElement([2210115751650724, 3809421927348411, 2357176729341513, 3420097284349172, 7483527818736]);

/// Edwards `a` variable value = `-1 (mod l)` equals:
/// `7237005577332262213973186563042994240857116359379907606001950938285454250988`
/// where `l = Prime of the field = 2^252 + 27742317777372353535851937790883648493`
pub static EDWARDS_A: FieldElement = FieldElement([671914833335276, 3916664325105025, 1367801, 0, 17592186044416]);

/// Edwards `d` variable value = `-126296/126297 (mod l)` equals:
/// `951605751702391019481481818669129158712512026257330939079110344917983315091`
/// where `l = Prime of the field = 2^252 + 27742317777372353535851937790883648493`
pub static EDWARDS_D: FieldElement = FieldElement([3304133203739795, 2446467598308289, 1534112949566882, 2032729967918914, 2313225441931]);

/// Holds the value of one of both `sqrt(-1 (mod p)) values.
/// `SQRT_MINUS_ONE = 3034649101460298094273452163494570791663566989388331537498831373842135895065`.
pub const SQRT_MINUS_ONE: FieldElement = FieldElement([3075585030474777, 2451921961843096, 1194333869305507, 2218299809671669, 7376823328646]);

/// `(+)1/SQRT(a) (mod l)` equals: `4202356475871964119699734399548423449193549369991576068503119564443318355924`.
pub static INV_SQRT_A: FieldElement = FieldElement([2099929430230996, 1464742363261928, 3309265759432790, 2285299817698826, 10215362715769]);

/// `(-)SQRT(a) (mod l)` equals: `4202356475871964119699734399548423449193549369991576068503119564443318355924`.
pub static MINUS_SQRT_A: FieldElement = FieldElement([2099929430230996, 1464742363261928, 3309265759432790, 2285299817698826, 10215362715769]);

/// `INV_SQRT_A_MINUS_D = 482283834104289360917429750399313974390948281833312135312952165682596457149`.
pub const INV_SQRT_A_MINUS_D: FieldElement = FieldElement([550050132044477, 3953042081665262, 2971403105229349, 212915494370164, 1172367057772]);

/// `SQRT_AD_MINUS_ONE = `.
pub const SQRT_AD_MINUS_ONE : FieldElement = FieldElement([3601277882726560, 1817821323014817, 1726005090908779, 2111284621343800, 648674458156]);

/// 4Coset of a RistrettoPoint.
pub(crate) const FOUR_COSET_GROUP: [EdwardsPoint; 4] =
[
EdwardsPoint {
X: FieldElement([1, 0, 0, 0, 0]),
Y: FieldElement([0, 0, 0, 0, 0]),
Z: FieldElement([1, 0, 0, 0, 0]),
T: FieldElement([0, 0, 0, 0, 0])
},

EdwardsPoint {
X: FieldElement([2099929430230996, 1464742363261928, 3309265759432790, 2285299817698826, 10215362715769]),
Y: FieldElement([0, 0, 0, 0, 0]),
Z: FieldElement([1, 0, 0, 0, 0]),
T: FieldElement([0, 0, 0, 0, 0])
},

EdwardsPoint {
X: FieldElement([0, 0, 0, 0, 0]),
Y: FieldElement([671914833335276, 3916664325105025, 1367801, 0, 17592186044416]),
Z: FieldElement([1, 0, 0, 0, 0]),
T: FieldElement([0, 0, 0, 0, 0])
},

EdwardsPoint {
X: FieldElement([3075585030474777, 2451921961843096, 1194333869305507, 2218299809671669, 7376823328646]),
Y: FieldElement([0, 0, 0, 0, 0]),
Z: FieldElement([1, 0, 0, 0, 0]),
T: FieldElement([0, 0, 0, 0, 0])
},
];

/// Holds the value of the Curve basepoint, which has been constructed
/// from taking `y-coodrinate = 3/5 (mod l)`.
Expand All @@ -45,12 +103,5 @@ pub const BASEPOINT: EdwardsPoint = EdwardsPoint {
T: FieldElement([3634527586288175, 2006028620404053, 3424252198034825, 2478951925947079, 4567251727358])
};

/// Holds the value of the Curve basepoint, which has been constructed
/// from taking `y-coodrinate = 3/5 (mod l)`.
/// The positive sign is choosen for it, so we leave it on it's cannonical bytes
/// encoding.
pub const BASEPOINT_COMPRESSED: CompressedEdwardsY =
CompressedEdwardsY([194, 24, 45, 158, 220, 161, 164, 1,
231, 42, 46, 200, 184, 98, 31, 166,
153, 153, 153, 153, 153, 153, 153, 153,
153, 153, 153, 153, 153, 153, 153, 9]);
/// Ristretto Basepoint.
pub const RISTRETTO_BASEPOINT: RistrettoPoint = RistrettoPoint(BASEPOINT);
72 changes: 15 additions & 57 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,18 @@ use crate::ristretto::{CompressedRistretto, RistrettoPoint};
#[cfg(feature = "u64_backend")]
pub use crate::backend::u64::constants::*;

/// Edwards `a` variable value = `-1 (mod l)` equals:
/// `7237005577332262213973186563042994240857116359379907606001950938285454250988`
/// where `l = Prime of the field = 2^252 + 27742317777372353535851937790883648493`
pub static EDWARDS_A: FieldElement = FieldElement([671914833335276, 3916664325105025, 1367801, 0, 17592186044416]);

/// Edwards `d` variable value = `-126296/126297 (mod l)` equals:
/// `951605751702391019481481818669129158712512026257330939079110344917983315091`
/// where `l = Prime of the field = 2^252 + 27742317777372353535851937790883648493`
pub static EDWARDS_D: FieldElement = FieldElement([3304133203739795, 2446467598308289, 1534112949566882, 2032729967918914, 2313225441931]);

/// 4Coset of a RistrettoPoint.
pub(crate) const FOUR_COSET_GROUP: [EdwardsPoint; 4] =
[
EdwardsPoint {
X: FieldElement([1, 0, 0, 0, 0]),
Y: FieldElement([0, 0, 0, 0, 0]),
Z: FieldElement([1, 0, 0, 0, 0]),
T: FieldElement([0, 0, 0, 0, 0])
},

EdwardsPoint {
X: FieldElement([2099929430230996, 1464742363261928, 3309265759432790, 2285299817698826, 10215362715769]),
Y: FieldElement([0, 0, 0, 0, 0]),
Z: FieldElement([1, 0, 0, 0, 0]),
T: FieldElement([0, 0, 0, 0, 0])
},

EdwardsPoint {
X: FieldElement([0, 0, 0, 0, 0]),
Y: FieldElement([671914833335276, 3916664325105025, 1367801, 0, 17592186044416]),
Z: FieldElement([1, 0, 0, 0, 0]),
T: FieldElement([0, 0, 0, 0, 0])
},

EdwardsPoint {
X: FieldElement([3075585030474777, 2451921961843096, 1194333869305507, 2218299809671669, 7376823328646]),
Y: FieldElement([0, 0, 0, 0, 0]),
Z: FieldElement([1, 0, 0, 0, 0]),
T: FieldElement([0, 0, 0, 0, 0])
},
];

/// Holds the value of one of both `sqrt(-1 (mod p)) values.
/// `SQRT_MINUS_ONE = 3034649101460298094273452163494570791663566989388331537498831373842135895065`.
pub const SQRT_MINUS_ONE: FieldElement = FieldElement([3075585030474777, 2451921961843096, 1194333869305507, 2218299809671669, 7376823328646]);

/// `(+)1/SQRT(a) (mod l)` equals: `4202356475871964119699734399548423449193549369991576068503119564443318355924`.
pub static INV_SQRT_A: FieldElement = FieldElement([2099929430230996, 1464742363261928, 3309265759432790, 2285299817698826, 10215362715769]);

/// `(-)SQRT(a) (mod l)` equals: `4202356475871964119699734399548423449193549369991576068503119564443318355924`.
pub static MINUS_SQRT_A: FieldElement = FieldElement([2099929430230996, 1464742363261928, 3309265759432790, 2285299817698826, 10215362715769]);

/// `INV_SQRT_A_MINUS_D = 482283834104289360917429750399313974390948281833312135312952165682596457149`.
pub const INV_SQRT_A_MINUS_D: FieldElement = FieldElement([550050132044477, 3953042081665262, 2971403105229349, 212915494370164, 1172367057772]);

/// `SQRT_AD_MINUS_ONE = `.
pub const SQRT_AD_MINUS_ONE : FieldElement = FieldElement([3601277882726560, 1817821323014817, 1726005090908779, 2111284621343800, 648674458156]);
/// Holds the value of the Curve basepoint, which has been constructed
/// from taking `y-coodrinate = 3/5 (mod l)`.
/// The positive sign is choosen for it, so we leave it on it's cannonical bytes
/// encoding.
pub const BASEPOINT_COMPRESSED: CompressedEdwardsY =
CompressedEdwardsY([194, 24, 45, 158, 220, 161, 164, 1,
231, 42, 46, 200, 184, 98, 31, 166,
153, 153, 153, 153, 153, 153, 153, 153,
153, 153, 153, 153, 153, 153, 153, 9]);


/// Ristretto Basepoint on compressed format.
pub const RISTRETTO_BASEPOINT_COMPRESSED: CompressedRistretto =
CompressedRistretto([2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);

0 comments on commit 405f541

Please sign in to comment.