arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/mnt4_298/src/curves/g2.rs
mnt4_298/src/curves/g2.rsRaw
 1use crate::{Fq, Fq2, Fr, FQ_ZERO, G1_COEFF_A_NON_RESIDUE};
 2use ark_ec::{
 3    mnt4,
 4    mnt4::MNT4Parameters,
 5    models::{ModelParameters, SWModelParameters},
 6};
 7use ark_ff::field_new;
 8
 9pub type G2Affine = mnt4::G2Affine<crate::Parameters>;
10pub type G2Projective = mnt4::G2Projective<crate::Parameters>;
11pub type G2Prepared = mnt4::G2Prepared<crate::Parameters>;
12
13#[derive(Clone, Default, PartialEq, Eq)]
14pub struct Parameters;
15
16impl ModelParameters for Parameters {
17    type BaseField = Fq2;
18    type ScalarField = Fr;
19}
20
21/// MUL_BY_A_C0 = NONRESIDUE * COEFF_A
22#[rustfmt::skip]
23pub const MUL_BY_A_C0: Fq = G1_COEFF_A_NON_RESIDUE;
24
25/// MUL_BY_A_C1 = NONRESIDUE * COEFF_A
26#[rustfmt::skip]
27pub const MUL_BY_A_C1: Fq = G1_COEFF_A_NON_RESIDUE;
28
29impl SWModelParameters for Parameters {
30    const COEFF_A: Fq2 = crate::Parameters::TWIST_COEFF_A;
31    // B coefficient of MNT4-298 G2 =
32    // ```
33    // mnt4298_twist_coeff_b = mnt4298_Fq2(mnt4298_Fq::zero(),
34    //                                  mnt4298_G1::coeff_b * mnt4298_Fq2::non_residue);
35    // non_residue = mnt4298_Fq2::non_residue = mnt4298_Fq("13");
36    //  = (ZERO, G1_B_COEFF * NON_RESIDUE);
37    //  =
38    //  (0, 67372828414711144619833451280373307321534573815811166723479321465776723059456513877937430)
39    // ```
40    #[rustfmt::skip]
41    const COEFF_B: Fq2 = field_new!(Fq2,
42        FQ_ZERO,
43        field_new!(Fq, "67372828414711144619833451280373307321534573815811166723479321465776723059456513877937430"),
44    );
45
46    /// COFACTOR =
47    /// 475922286169261325753349249653048451545124879932565935237842521413255878328503110407553025
48    #[rustfmt::skip]
49    const COFACTOR: &'static [u64] = &[
50        15480692783052488705,
51        9802782456999489873,
52        14622846468721090623,
53        11702080941310629006,
54        4110145082483,
55    ];
56
57    /// COFACTOR^(-1) mod r =
58    /// 475922286169261325753349249653048451545124878207887910632124039320641839552134835598065665
59    #[rustfmt::skip]
60    const COFACTOR_INV: Fr = field_new!(Fr, "475922286169261325753349249653048451545124878207887910632124039320641839552134835598065665");
61
62    /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
63    const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
64        (G2_GENERATOR_X, G2_GENERATOR_Y);
65
66    #[inline(always)]
67    fn mul_by_a(elt: &Fq2) -> Fq2 {
68        field_new!(Fq2, MUL_BY_A_C0 * &elt.c0, MUL_BY_A_C1 * &elt.c1,)
69    }
70}
71
72const G2_GENERATOR_X: Fq2 = field_new!(Fq2, G2_GENERATOR_X_C0, G2_GENERATOR_X_C1);
73const G2_GENERATOR_Y: Fq2 = field_new!(Fq2, G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1);
74
75// Generator of G2
76// These are two Fq elements each because X and Y (and Z) are elements of Fq^2
77// X = 438374926219350099854919100077809681842783509163790991847867546339851681564223481322252708,
78//     37620953615500480110935514360923278605464476459712393277679280819942849043649216370485641,
79// Y = 37437409008528968268352521034936931842973546441370663118543015118291998305624025037512482,
80//     424621479598893882672393190337420680597584695892317197646113820787463109735345923009077489,
81#[rustfmt::skip]
82pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, "438374926219350099854919100077809681842783509163790991847867546339851681564223481322252708");
83
84#[rustfmt::skip]
85pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, "37620953615500480110935514360923278605464476459712393277679280819942849043649216370485641");
86
87#[rustfmt::skip]
88pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, "37437409008528968268352521034936931842973546441370663118543015118291998305624025037512482");
89
90#[rustfmt::skip]
91pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, "424621479598893882672393190337420680597584695892317197646113820787463109735345923009077489");