arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/mnt6_298/src/curves/g2.rs
mnt6_298/src/curves/g2.rsRaw
 1use ark_ec::{
 2    mnt6,
 3    mnt6::MNT6Parameters,
 4    models::{ModelParameters, SWModelParameters},
 5};
 6use ark_ff::{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 = 5 * 11
23    #[rustfmt::skip]
24pub const MUL_BY_A_C0: Fq = field_new!(Fq, "55");
25
26/// MUL_BY_A_C1 = NONRESIDUE * COEFF_A
27    #[rustfmt::skip]
28pub const MUL_BY_A_C1: Fq = field_new!(Fq, "55");
29
30/// MUL_BY_A_C2 = COEFF_A
31pub const MUL_BY_A_C2: Fq = g1::Parameters::COEFF_A;
32
33impl SWModelParameters for Parameters {
34    const COEFF_A: Fq3 = crate::Parameters::TWIST_COEFF_A;
35    #[rustfmt::skip]
36    const COEFF_B: Fq3 = field_new!(Fq3,
37        // 5 * G1::COEFF_B
38        field_new!(Fq, "57578116384997352636487348509878309737146377454014423897662211075515354005624851787652233"),
39        FQ_ZERO,
40        FQ_ZERO,
41    );
42
43    /// COFACTOR =
44    /// 226502022472576270196498690498308461791828762732602586162207535351960270082712694977333372361549082214519252261735048131889018501404377856786623430385820659037970876666767495659520
45    #[rustfmt::skip]
46    const COFACTOR: &'static [u64] = &[
47        15308190245346869248,
48        10669098443577192943,
49        4561413759929581409,
50        3680089780298582849,
51        17336300687782721465,
52        10745756320947240891,
53        17479264233688728128,
54        16828697388537672097,
55        4184034152442024798,
56        915787,
57    ];
58
59    /// COFACTOR^(-1) mod r =
60    /// 79320381028210220958891541608841408590854146655427655872973753568875979721417185067925504
61    #[rustfmt::skip]
62    const COFACTOR_INV: Fr = field_new!(Fr, "79320381028210220958891541608841408590854146655427655872973753568875979721417185067925504");
63
64    /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
65    const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
66        (G2_GENERATOR_X, G2_GENERATOR_Y);
67
68    #[inline(always)]
69    fn mul_by_a(elt: &Fq3) -> Fq3 {
70        field_new!(
71            Fq3,
72            MUL_BY_A_C0 * &elt.c1,
73            MUL_BY_A_C1 * &elt.c2,
74            MUL_BY_A_C2 * &elt.c0,
75        )
76    }
77}
78
79const G2_GENERATOR_X: Fq3 =
80    field_new!(Fq3, G2_GENERATOR_X_C0, G2_GENERATOR_X_C1, G2_GENERATOR_X_C2);
81const G2_GENERATOR_Y: Fq3 =
82    field_new!(Fq3, G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1, G2_GENERATOR_Y_C2);
83
84pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, "421456435772811846256826561593908322288509115489119907560382401870203318738334702321297427");
85pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, "103072927438548502463527009961344915021167584706439945404959058962657261178393635706405114");
86pub const G2_GENERATOR_X_C2: Fq = field_new!(Fq, "143029172143731852627002926324735183809768363301149009204849580478324784395590388826052558");
87
88pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, "464673596668689463130099227575639512541218133445388869383893594087634649237515554342751377");
89pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, "100642907501977375184575075967118071807821117960152743335603284583254620685343989304941678");
90pub const G2_GENERATOR_Y_C2: Fq = field_new!(Fq, "123019855502969896026940545715841181300275180157288044663051565390506010149881373807142903");