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::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 /// COFACTOR =
22 /// 41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888049094905534395567574915333486969589229856772141392370549616644545554517640527237829320384324374366385444967219201
23 #[rustfmt::skip]
24 const COFACTOR: &'static [u64] = &[
25 16436257212445032449,
26 8690275530472745198,
27 17315389657026393162,
28 1645397558963170979,
29 3544984605440726586,
30 12665092767997125024,
31 11083680675069097885,
32 575819899841080717,
33 6825179918269667443,
34 13256793349531086829,
35 1162650133526138285,
36 497830423872529,
37 ];
38
39 /// COFACTOR^(-1) mod r =
40 /// 102345604409665481004734934052318066391634848395005988700111949231215905051467807945653833683883449458834877235200
41 #[rustfmt::skip]
42 const COFACTOR_INV: Fr = field_new!(Fr, "102345604409665481004734934052318066391634848395005988700111949231215905051467807945653833683883449458834877235200");
43}
44
45/// MUL_BY_A_C0 = NONRESIDUE * COEFF_A
46#[rustfmt::skip]
47pub const MUL_BY_A_C0: Fq = G1_COEFF_A_NON_RESIDUE;
48
49/// MUL_BY_A_C1 = NONRESIDUE * COEFF_A
50#[rustfmt::skip]
51pub const MUL_BY_A_C1: Fq = G1_COEFF_A_NON_RESIDUE;
52
53impl SWModelParameters for Parameters {
54 const COEFF_A: Fq2 = crate::Parameters::TWIST_COEFF_A;
55 // B coefficient of MNT4-753 G2 =
56 // ```
57 // mnt4753_twist_coeff_b = mnt4753_Fq2(mnt4753_Fq::zero(),
58 // mnt4753_G1::coeff_b * mnt4753_Fq2::non_residue);
59 // non_residue = mnt4753_Fq2::non_residue = mnt4753_Fq("13");
60 // = (ZERO, G1_B_COEFF * NON_RESIDUE);
61 // =
62 // (0, 39196523001581428369576759982967177918859161321667605855515469914917622337081756705006832951954384669101573360625169461998308377011601613979275218690841934572954991361632773738259652003389826903175898479855893660378722437317212)
63 // ```
64 #[rustfmt::skip]
65 const COEFF_B: Fq2 = field_new!(Fq2,
66 FQ_ZERO,
67 field_new!(Fq, "39196523001581428369576759982967177918859161321667605855515469914917622337081756705006832951954384669101573360625169461998308377011601613979275218690841934572954991361632773738259652003389826903175898479855893660378722437317212")
68 );
69
70 /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
71 const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
72 (G2_GENERATOR_X, G2_GENERATOR_Y);
73
74 #[inline(always)]
75 fn mul_by_a(elt: &Fq2) -> Fq2 {
76 field_new!(Fq2, MUL_BY_A_C0 * &elt.c0, MUL_BY_A_C1 * &elt.c1,)
77 }
78}
79
80const G2_GENERATOR_X: Fq2 = field_new!(Fq2, G2_GENERATOR_X_C0, G2_GENERATOR_X_C1);
81const G2_GENERATOR_Y: Fq2 = field_new!(Fq2, G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1);
82
83// Generator of G2
84// These are two Fq elements each because X and Y (and Z) are elements of Fq^2
85// X = 29483965110843144675703364744708836524643960105538608078862508397502447349913068434941060515343254862580437318493682762113105361632548148204806052114008731372757389645383891982211245013965175213456066452587869519098351487925167,
86// 19706011319630172391076079624799753948158506771222147486237995321925443331396169656568431378974558350664383559981183980668976846806019030432389169137953988990802000581078994008283967768348275973921598166274857631001635633631000,
87// Y = 39940152670760519653940320314827327941993141403708338666925204282084477074754642625849927569427860786384998614863651207257467076192649385174108085803168743803491780568503369317093191101779534035377266300185099318717465441820654,
88// 17608637424964395737041291373756657139607306440193731804102457011726690702169238966996114255971643893157857311132388792357391583164125870757541009035041469463366528798593952884745987697403056488744603829437448927398468360797245,
89#[rustfmt::skip]
90pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, "29483965110843144675703364744708836524643960105538608078862508397502447349913068434941060515343254862580437318493682762113105361632548148204806052114008731372757389645383891982211245013965175213456066452587869519098351487925167");
91
92#[rustfmt::skip]
93pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, "19706011319630172391076079624799753948158506771222147486237995321925443331396169656568431378974558350664383559981183980668976846806019030432389169137953988990802000581078994008283967768348275973921598166274857631001635633631000");
94
95#[rustfmt::skip]
96pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, "39940152670760519653940320314827327941993141403708338666925204282084477074754642625849927569427860786384998614863651207257467076192649385174108085803168743803491780568503369317093191101779534035377266300185099318717465441820654");
97
98#[rustfmt::skip]
99pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, "17608637424964395737041291373756657139607306440193731804102457011726690702169238966996114255971643893157857311132388792357391583164125870757541009035041469463366528798593952884745987697403056488744603829437448927398468360797245");