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