arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/mnt4_753/src/curves/g2.rs
mnt4_753/src/curves/g2.rsRaw
  1use ark_ec::{
  2    mnt4,
  3    mnt4::MNT4Parameters,
  4    models::{ModelParameters, SWModelParameters},
  5};
  6use ark_ff::{biginteger::BigInteger768, field_new};
  7
  8use crate::{Fq, Fq2, Fr, FQ_ZERO, G1_COEFF_A_NON_RESIDUE};
  9
 10pub type G2Affine = mnt4::G2Affine<crate::Parameters>;
 11pub type G2Projective = mnt4::G2Projective<crate::Parameters>;
 12pub type G2Prepared = mnt4::G2Prepared<crate::Parameters>;
 13
 14#[derive(Clone, Default, PartialEq, Eq)]
 15pub struct Parameters;
 16
 17impl ModelParameters for Parameters {
 18    type BaseField = Fq2;
 19    type ScalarField = Fr;
 20}
 21
 22/// MUL_BY_A_C0 = NONRESIDUE * COEFF_A
 23#[rustfmt::skip]
 24pub const MUL_BY_A_C0: Fq = G1_COEFF_A_NON_RESIDUE;
 25
 26/// MUL_BY_A_C1 = NONRESIDUE * COEFF_A
 27#[rustfmt::skip]
 28pub const MUL_BY_A_C1: Fq = G1_COEFF_A_NON_RESIDUE;
 29
 30impl SWModelParameters for Parameters {
 31    const COEFF_A: Fq2 = crate::Parameters::TWIST_COEFF_A;
 32    // B coefficient of MNT4-753 G2 =
 33    // ```
 34    // mnt4753_twist_coeff_b = mnt4753_Fq2(mnt4753_Fq::zero(),
 35    //                                  mnt4753_G1::coeff_b * mnt4753_Fq2::non_residue);
 36    // non_residue = mnt4753_Fq2::non_residue = mnt4753_Fq("13");
 37    //  = (ZERO, G1_B_COEFF * NON_RESIDUE);
 38    //  =
 39    //  (0, 39196523001581428369576759982967177918859161321667605855515469914917622337081756705006832951954384669101573360625169461998308377011601613979275218690841934572954991361632773738259652003389826903175898479855893660378722437317212)
 40    // ```
 41    #[rustfmt::skip]
 42    const COEFF_B: Fq2 = field_new!(Fq2,
 43        FQ_ZERO,
 44        field_new!(Fq, BigInteger768([
 45            15129916544657421551,
 46            11332543254671606602,
 47            11913830318987286849,
 48            13905314883394440110,
 49            16479690325073358448,
 50            14869098639251228898,
 51            10663986895980443550,
 52            10768989312009479656,
 53            9469728929095040349,
 54            4512954369775881939,
 55            8788997129423430122,
 56            459763387588954,
 57        ])),
 58    );
 59
 60    /// COFACTOR =
 61    /// 41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888049094905534395567574915333486969589229856772141392370549616644545554517640527237829320384324374366385444967219201
 62    #[rustfmt::skip]
 63    const COFACTOR: &'static [u64] = &[
 64        16436257212445032449,
 65        8690275530472745198,
 66        17315389657026393162,
 67        1645397558963170979,
 68        3544984605440726586,
 69        12665092767997125024,
 70        11083680675069097885,
 71        575819899841080717,
 72        6825179918269667443,
 73        13256793349531086829,
 74        1162650133526138285,
 75        497830423872529,
 76    ];
 77
 78    /// COFACTOR^(-1) mod r =
 79    /// 102345604409665481004734934052318066391634848395005988700111949231215905051467807945653833683883449458834877235200
 80    #[rustfmt::skip]
 81    const COFACTOR_INV: Fr = field_new!(Fr, BigInteger768([
 82        1879390364380281898,
 83        7926794171490610432,
 84        6437239504245874253,
 85        16688141022047191858,
 86        17059416847145768464,
 87        15065047661241262516,
 88        16537575340937777321,
 89        3324411942044534547,
 90        3878293904770657570,
 91        18116939243856833744,
 92        7557533897589069385,
 93        78370361203778,
 94    ]));
 95
 96    /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
 97    const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
 98        (G2_GENERATOR_X, G2_GENERATOR_Y);
 99
100    #[inline(always)]
101    fn mul_by_a(elt: &Fq2) -> Fq2 {
102        field_new!(Fq2, MUL_BY_A_C0 * &elt.c0, MUL_BY_A_C1 * &elt.c1,)
103    }
104}
105
106const G2_GENERATOR_X: Fq2 = field_new!(Fq2, G2_GENERATOR_X_C0, G2_GENERATOR_X_C1);
107const G2_GENERATOR_Y: Fq2 = field_new!(Fq2, G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1);
108
109// Generator of G2
110// These are two Fq elements each because X and Y (and Z) are elements of Fq^2
111// X = 29483965110843144675703364744708836524643960105538608078862508397502447349913068434941060515343254862580437318493682762113105361632548148204806052114008731372757389645383891982211245013965175213456066452587869519098351487925167,
112// 19706011319630172391076079624799753948158506771222147486237995321925443331396169656568431378974558350664383559981183980668976846806019030432389169137953988990802000581078994008283967768348275973921598166274857631001635633631000,
113// Y = 39940152670760519653940320314827327941993141403708338666925204282084477074754642625849927569427860786384998614863651207257467076192649385174108085803168743803491780568503369317093191101779534035377266300185099318717465441820654,
114// 17608637424964395737041291373756657139607306440193731804102457011726690702169238966996114255971643893157857311132388792357391583164125870757541009035041469463366528798593952884745987697403056488744603829437448927398468360797245,
115#[rustfmt::skip]
116pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, BigInteger768([
117    7263636080534048301,
118    7643227961769035653,
119    15787777614640869937,
120    17661317895964274771,
121    4142647779394287783,
122    15064949873659932676,
123    4579259080596351332,
124    2207443675339702626,
125    5738725620118622838,
126    4338467638707299712,
127    6558861849926282439,
128    341078935870328
129]));
130
131#[rustfmt::skip]
132pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, BigInteger768([
133    13073882729051113867,
134    195909455108318710,
135    10527070038778509320,
136    16605710222187477118,
137    10442518358308209073,
138    7776589986153052354,
139    16034091384000651523,
140    17429232381273855185,
141    512853344493546034,
142    7982076214836075255,
143    3601416800138513610,
144    399028695285184
145]));
146
147#[rustfmt::skip]
148pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, BigInteger768([
149    4867672648970469422,
150    2453112364260322863,
151    11918672197974895143,
152    3923647310180624143,
153    12707123323825700670,
154    15781895092544451511,
155    17747112377690960911,
156    16511994611001933567,
157    15360620366665804029,
158    10252080383738480571,
159    5722654046339742760,
160    316853130349807
161]));
162
163#[rustfmt::skip]
164pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, BigInteger768([
165    17322957246732430708,
166    11825815087694023697,
167    7654216682602683900,
168    13544637981229618042,
169    17057060382219081849,
170    4038731408172002692,
171    6631723222530012253,
172    10585926166286435412,
173    16050667328028620117,
174    16598483946296156500,
175    11771818132648686020,
176    1230430296095
177]));