arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/ed_on_mnt4_753/src/curves/mod.rs
ed_on_mnt4_753/src/curves/mod.rsRaw
  1use ark_ec::{
  2    models::{ModelParameters, MontgomeryModelParameters, TEModelParameters},
  3    twisted_edwards_extended::{GroupAffine, GroupProjective},
  4};
  5use ark_ff::{biginteger::BigInteger768, field_new};
  6
  7use crate::{fq::Fq, fr::Fr};
  8
  9#[cfg(test)]
 10mod tests;
 11
 12pub type EdwardsAffine = GroupAffine<EdwardsParameters>;
 13pub type EdwardsProjective = GroupProjective<EdwardsParameters>;
 14
 15#[derive(Clone, Default, PartialEq, Eq)]
 16pub struct EdwardsParameters;
 17
 18impl ModelParameters for EdwardsParameters {
 19    type BaseField = Fq;
 20    type ScalarField = Fr;
 21}
 22
 23// Many parameters need to be written down in the Montgomery residue form,
 24// discussed below. Some useful numbers:
 25// R for Fq: 11407975440035778516953587871987109648531742722982233186120790377529569367095961954159305159259556262528904776132787438725571821295685691762729353555475679813615501328617736020411951837995932262333059670631633855898874183380802
 26// R for Fr: 933352698056040166367534174176950366489065242993745918174914647273231163953185260894581718311971532174387033963715296372791285468903747270837716556902938133611910788060028435531754797383796835009316018259656953442114538695438
 27
 28impl TEModelParameters for EdwardsParameters {
 29    /// COEFF_A = -1
 30    /// Needs to be in the Montgomery residue form in Fq
 31    /// I.e., -1 * R for Fq
 32    ///     = 30490515527883174885390626919253527479638967196971715885662712543495783445475144818899588604530782658889166195755671038597601236195908163306966888299320716352105914996732328421058466299850466207278876048428274308321910292779199
 33    #[rustfmt::skip]
 34    const COEFF_A: Fq = field_new!(Fq, BigInteger768([
 35        2265581976117350591u64,
 36        18442012872391748519u64,
 37        3807704300793525789u64,
 38        12280644139289115082u64,
 39        10655371227771325282u64,
 40        1346491763263331896u64,
 41        7477357615964975877u64,
 42        12570239403004322603u64,
 43        2180620924574446161u64,
 44        12129628062772479841u64,
 45        8853285699251153944u64,
 46        362282887012814u64,
 47    ]));
 48
 49    /// COEFF_D = 317690
 50    /// Needs to be in the Montgomery residue form in Fq
 51    /// I.e., 317690 * R for Fq
 52    ///     = 22147310944926701613095824060993292411108298129020138512675871596899298127988454048404371067902679066037332245471578749765607461010546427833106841035248048771826362113332201923280907352099197626899000000763383579702914883060881
 53    #[rustfmt::skip]
 54    const COEFF_D: Fq = field_new!(Fq, BigInteger768([
 55        17599538631181665425u64,
 56        541385733032329781u64,
 57        10984951882154109942u64,
 58        6745898816867096302u64,
 59        8606788232777167026u64,
 60        17697068798460151905u64,
 61        7726746940317276687u64,
 62        16708084840201435716u64,
 63        10141323747759975110u64,
 64        6527904409415579649u64,
 65        18367733563217133340u64,
 66        263150412834478u64,
 67    ]));
 68
 69    /// COFACTOR = 8
 70    const COFACTOR: &'static [u64] = &[8];
 71
 72    /// COFACTOR_INV (mod r) =
 73    /// 4582647449616135528381398492791944685893671397494963179726320631987147963874964803303316505414568319530101512550297775574042810022553679071007001162683923594233560231270043634777390699589793776691858866199511300853468155295505
 74    /// Needs to be in the Montgomery residue form in Fr
 75    /// I.e., COFACTOR_INV * R for Fr
 76    ///     = 1425996930004472314619198483998388706066467840372779148265098797191196170886995244269913144907444532816113097116978062210611142118628305286285286330379702579339648914584658878663580978127201397716695606910888919424112361707074
 77    #[rustfmt::skip]
 78    const COFACTOR_INV: Fr = field_new!(Fr, BigInteger768([
 79        18349096995079034434u64,
 80        12232096963923221952u64,
 81        10313403112747203584u64,
 82        7266093872567585103u64,
 83        9102010985112647012u64,
 84        11539789563873699451u64,
 85        5062476400815403157u64,
 86        3112383580531982668u64,
 87        9803941911066678468u64,
 88        11670110706913295633u64,
 89        5956199581925454898u64,
 90        16943442107464u64,
 91    ]));
 92
 93    /// Generated randomly
 94    const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y);
 95
 96    type MontgomeryModelParameters = EdwardsParameters;
 97
 98    /// Multiplication by `a` is just negation.
 99    #[inline(always)]
100    fn mul_by_a(elem: &Self::BaseField) -> Self::BaseField {
101        -*elem
102    }
103}
104
105impl MontgomeryModelParameters for EdwardsParameters {
106    /// COEFF_A = 40212480635445336270302172549278415015971955924352275480357619589919378421241453024646804979794897776496091377551124233752850182852486874251193367187677349266115879541798515219680194853352256809837126277708211496794264654247419
107    /// Needs to be in the Montgomery residue form in Fq
108    /// I.e., COEFF_A * R for Fq
109    ///     = 30548714567617468394128273134168309733495884043859854416819409495212098575586848195824755026287273763308450716502830186864520759966983420083939453225231731740328282532297868204762840705631404761799649264638732114864775402781225
110    #[rustfmt::skip]
111    const COEFF_A: Fq = field_new!(Fq, BigInteger768([
112        4717325759818398249u64,
113        9984799932299155706u64,
114        1320735555238925850u64,
115        17027346723122076572u64,
116        2632519042034336982u64,
117        15439824589583270152u64,
118        8351651296737343223u64,
119        11351622927160584696u64,
120        3108522085485690820u64,
121        6958456540352275598u64,
122        16034686916204205245u64,
123        362974397660347u64,
124    ]));
125    /// COEFF_B = 1686010332473617132042042241962222112198753995601673591425883331105974391329653748412088783995441144921979594337334243570322874639106980818502874667119046899605536783551549221790223284494141659774809441351696667426519821912580
126    /// Needs to be in the Montgomery residue form in Fq
127    //  I.e., COEFF_B * R for Fq
128    //      = 30432316488148881376652980704338745225782050350083577354506015591779468315363441441974422182774291554469881675008511890330681712424832906529994323373409700963883547461166788637354091894069527652758102832217816501779045182777173
129    #[rustfmt::skip]
130    const COEFF_B: Fq = field_new!(Fq, BigInteger768([
131        18260582266125854549u64,
132        8452481738774789715u64,
133        6294673046348125729u64,
134        7533941555456153592u64,
135        231479339798761966u64,
136        5699903010652945257u64,
137        6603063935192608530u64,
138        13788855878848060510u64,
139        1252719763663201502u64,
140        17300799585192684084u64,
141        1671884482298102643u64,
142        361591376365281u64,
143    ]));
144
145    type TEModelParameters = EdwardsParameters;
146}
147
148/// GENERATOR_X =
149/// 41126137307536311801428235632419266329480236393691483739251051053325519918069469184425962602019877935619960143044210127218431046103600632347238890180171944971817510488009355627861577881883236134824745174469522277738875418206826
150/// Needs to be in the Montgomery residue form in Fq
151/// I.e., GENERATOR_X * R for Fq
152///     = 17458296603084005843875564204476809882690765950143935590811069375604430769391871724158635621148427226413334766092842987247361751645959801401160673759590522483750685475882467271029344718076741595831312033991612062403782328664175
153#[rustfmt::skip]
154const GENERATOR_X: Fq = field_new!(Fq, BigInteger768([
155    13391543849638641775u64,
156    1472718285337442467u64,
157    1704796371472020786u64,
158    1309193942690519845u64,
159    11187264906425773918u64,
160    11963130799714018220u64,
161    10821241385017749516u64,
162    4661882526685671286u64,
163    8328914571224024668u64,
164    17202160931109725769u64,
165    4708938015393622850u64,
166    207436377712515u64,
167]));
168
169/// GENERATOR_Y =
170/// 18249602579663240810999977712212098844157230095713722119136881953011435881503578209163288529034825612841855863913294174196656077002578342108932925693640046298989762289691399012056048139253937882385653600831389370198228562812681
171/// Needs to be in the Montgomery residue form in Fq
172/// I.e., GENERATOR_Y * R for Fq
173///     = 9017791529346511307345374145466037779022974291216533108328228023141994468888559894991603799439817566592668010556604996318161436165296215592281656017954181737938978992370627048110847574165717052386876801764386102664064737203581
174#[rustfmt::skip]
175const GENERATOR_Y: Fq = field_new!(Fq, BigInteger768([
176    16764059510974436733u64,
177    10694630934032454957u64,
178    15899992550979352399u64,
179    17663221529566141065u64,
180    3780246386961240559u64,
181    6062186621379836072u64,
182    11042203340250178810u64,
183    1263100291243127914u64,
184    14407501552666806512u64,
185    13385165116432280059u64,
186    11978187531853934313u64,
187    107147796394053u64,
188]));