arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/mnt6_753/src/curves/g2.rs
mnt6_753/src/curves/g2.rsRaw
  1use ark_ec::{
  2    mnt6,
  3    mnt6::MNT6Parameters,
  4    models::{ModelParameters, SWModelParameters},
  5};
  6use ark_ff::{biginteger::BigInteger768, field_new};
  7
  8use crate::{g1, Fq, Fq3, Fr, FQ_ZERO};
  9
 10pub type G2Affine = mnt6::G2Affine<crate::Parameters>;
 11pub type G2Projective = mnt6::G2Projective<crate::Parameters>;
 12pub type G2Prepared = mnt6::G2Prepared<crate::Parameters>;
 13
 14#[derive(Clone, Default, PartialEq, Eq)]
 15pub struct Parameters;
 16
 17impl ModelParameters for Parameters {
 18    type BaseField = Fq3;
 19    type ScalarField = Fr;
 20}
 21
 22/// MUL_BY_A_C0 = NONRESIDUE * COEFF_A
 23#[rustfmt::skip]
 24pub const MUL_BY_A_C0: Fq = field_new!(Fq, BigInteger768([
 25    10895242587870565906,
 26    6757387713923212228,
 27    12683949709867392876,
 28    1229095484098138811,
 29    18111217745394181988,
 30    3648021353977015866,
 31    7900332254549424237,
 32    5988529219097278134,
 33    11544487525720487778,
 34    7317517692149492894,
 35    9905728181042915773,
 36    470678396104534
 37]));
 38
 39/// MUL_BY_A_C1 = NONRESIDUE * COEFF_A
 40#[rustfmt::skip]
 41pub const MUL_BY_A_C1: Fq = field_new!(Fq, BigInteger768([
 42    10895242587870565906,
 43    6757387713923212228,
 44    12683949709867392876,
 45    1229095484098138811,
 46    18111217745394181988,
 47    3648021353977015866,
 48    7900332254549424237,
 49    5988529219097278134,
 50    11544487525720487778,
 51    7317517692149492894,
 52    9905728181042915773,
 53    470678396104534
 54]));
 55
 56/// MUL_BY_A_C2 = COEFF_A
 57pub const MUL_BY_A_C2: Fq = g1::Parameters::COEFF_A;
 58
 59impl SWModelParameters for Parameters {
 60    const COEFF_A: Fq3 = crate::Parameters::TWIST_COEFF_A;
 61    // B coefficient of MNT6-753 G2 =
 62    // ```
 63    // mnt6753_twist_coeff_b = mnt6753_Fq3(mnt6753_G1::coeff_b * mnt6753_Fq3::non_residue,
 64    //                                  mnt6753_Fq::zero(), mnt6753_Fq::zero());
 65    // non_residue = mnt6753_Fq3::non_residue = mnt6753_Fq("11");
 66    //  = (G1_B_COEFF * NON_RESIDUE, ZERO, ZERO);
 67    //  =
 68    //  (2189526091197672465268098090392210500740714959757583916377481826443393499947557697773546040576162515434508768057245887856591913752342600919117433675080691499697020523783784738694360040853591723916201150207746019687604267190251,
 69    //  0, 0)
 70    // ```
 71    #[rustfmt::skip]
 72    const COEFF_B: Fq3 = field_new!(
 73        Fq3,
 74        field_new!(Fq, BigInteger768([
 75                3284231658830416104,
 76                13720030246451177991,
 77                6276939417009443243,
 78                8340612253649729185,
 79                4863511590806861670,
 80                15883218135158530927,
 81                4865336109262680856,
 82                16600307443495218926,
 83                10112528487499131659,
 84                17308657107605697754,
 85                5326857497786417651,
 86                206191604157846
 87        ])),
 88        FQ_ZERO,
 89        FQ_ZERO,
 90    );
 91
 92    /// COFACTOR =
 93    /// 1755483545388786116744270475466687259186947712032004459714210070280389500116987496124098574823389466285978151140155508638765729019174599527183600372094760023144398285325863550664578643924584541949466179502227232245309952839189635010671372908411609248348904807785904229403747495114436660255866932060472369629692502198423138429922875792635236729929780298333055698257230963645509826963717287902205842627121011526048163097042046361575549171961352924692480000
 94    #[rustfmt::skip]
 95    const COFACTOR: &'static [u64] = &[
 96        17839255819456086016,
 97        500623104730997740,
 98        2110252009236161768,
 99        1500878543414750896,
100        12839751506594314239,
101        8978537329634833065,
102        13830010955957826199,
103        7626514311663165506,
104        14876243211944528805,
105        2316601947950921451,
106        2601177562497904269,
107        18300670698693155036,
108        17321427554953155530,
109        12586270719596716948,
110        807965545138267130,
111        13086323046094411844,
112        16597411233431396880,
113        5578519820383338987,
114        16478065054289650824,
115        12110148809888520863,
116        5901144846689643164,
117        3407195776166256068,
118        14663852814447346059,
119        13435169368,
120    ];
121
122    /// COFACTOR^(-1) mod r =
123    /// 6983081827986492233724035798540106188028451653325658178630583820170892135428517795509815627298389820236345161981341515817589065927929152555581161598204976128690232061758269440757592419606754539638220064054062394397574161203200
124    #[rustfmt::skip]
125    const COFACTOR_INV: Fr = field_new!(Fr, BigInteger768([
126            9418103049026957703,
127            3464743017686961509,
128            7872172759259099794,
129            17514322419398292337,
130            1496353716802911167,
131            16961719271566193274,
132            15426671498718617736,
133            9230857178223113223,
134            11731938389074297274,
135            16450973680014766981,
136            431917267220694852,
137            94637508603012
138    ]));
139
140    /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
141    const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
142        (G2_GENERATOR_X, G2_GENERATOR_Y);
143
144    #[inline(always)]
145    fn mul_by_a(elt: &Fq3) -> Fq3 {
146        field_new!(
147            Fq3,
148            MUL_BY_A_C0 * &elt.c1,
149            MUL_BY_A_C1 * &elt.c2,
150            MUL_BY_A_C2 * &elt.c0,
151        )
152    }
153}
154
155const G2_GENERATOR_X: Fq3 =
156    field_new!(Fq3, G2_GENERATOR_X_C0, G2_GENERATOR_X_C1, G2_GENERATOR_X_C2);
157const G2_GENERATOR_Y: Fq3 =
158    field_new!(Fq3, G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1, G2_GENERATOR_Y_C2);
159
160// Generator of G2
161// These are three Fq elements each because X and Y (and Z) are elements of Fq^3
162// X = 27250797394340459586637772414334383652934225310678303542554641987990991970766156209996739240400887081904395745019996048910447071686918567661896491214767494514394154061111870331668445455228882471000120574964265209669155206168252,
163// 35762481056967998715733586393399457882827322353696313323665483142561285210083843314423554450886956650265947502285422529615273790981238406393402603210224104850580302463396274854098657541573494421834514772635884262388058080180368,
164// 36955296703808958167583270646821654948157955258947892285629161090141878438357164213613114995903637211606408001037026832604054121847388692538440756596264746452765613740820430501353237866984394057660379098674983614861254438847846,
165// Y = 2540920530670785421282147216459500299597350984927286541981768941513322907384197363939300669100157141915897390694710534916701460991329498878429407641200901974650893207493883271892985923686300670742888673128384350189165542294615,
166// 7768974215205248225654340523113146529854477025417883273460270519532499370133542215655437897583245920162220909271982265882784840026754554720358946490360213245668334549692889019612343620295335698052097726325099648573158597797497,
167// 21014872727619291834131369222699267167761185012487859171850226473555446863681002782100371394603357586906967186931035615146288030444598977758226767063525819170917389755555854704165900869058188909090444447822088242504281789869689,
168#[rustfmt::skip]
169pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, BigInteger768([
170    12772807549130126376,
171    2873211972983293592,
172    15999100872160401842,
173    5277158980096688998,
174    12258756012310206056,
175    11885883517271414939,
176    6373672746025419911,
177    13662747456330091710,
178    11960680427306056040,
179    15150766304321120168,
180    9480712498131729809,
181    413066879180657
182]));
183
184#[rustfmt::skip]
185pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, BigInteger768([
186    10478274013728260378,
187    15392361149861123784,
188    17610084573134912261,
189    14474130264887792371,
190    16754378329454263996,
191    3186303078832273968,
192    7143189323629797683,
193    897486443141339765,
194    3675579496642106405,
195    4429391539758461550,
196    18414257413872084180,
197    331209511183940
198]));
199
200#[rustfmt::skip]
201pub const G2_GENERATOR_X_C2: Fq = field_new!(Fq, BigInteger768([
202    5133712986240959624,
203    10763134357204872827,
204    8672341403101541980,
205    18084133226637702602,
206    4689040548070804594,
207    7352115990101270007,
208    14358820512747653623,
209    10167201669589504005,
210    3117673189936726036,
211    9407838052466059644,
212    7246385421116647671,
213    464288782946273
214]));
215
216#[rustfmt::skip]
217pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, BigInteger768([
218    710862246533630948,
219    9314168172257972041,
220    4722111556929662508,
221    4408676313209842703,
222    10491088158750500898,
223    13211840969745661306,
224    13985341743807087374,
225    7111198859398088665,
226    158194789363472891,
227    7682183069894584797,
228    9510326135325230913,
229    338826428359581
230]));
231
232#[rustfmt::skip]
233pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, BigInteger768([
234    10889422482835557076,
235    6073207585023077555,
236    16059368148547235058,
237    14871121891082823821,
238    15156344465408677175,
239    12695157488434086405,
240    7840105431702704631,
241    4763759818130023465,
242    12295696339556388640,
243    352741974984397506,
244    10581333776569094279,
245    204002329498100
246]));
247
248#[rustfmt::skip]
249pub const G2_GENERATOR_Y_C2: Fq = field_new!(Fq, BigInteger768([
250    11263496889641203707,
251    16306762242042931049,
252    8275973312257833978,
253    12034012818098316014,
254    5392903691498465561,
255    4572635011530974247,
256    696221667645211601,
257    11098678912660456319,
258    5477755854538915619,
259    11442390115310629698,
260    10262065045802790037,
261    17901561410539
262]));