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 /// COFACTOR =
21 /// 475922286169261325753349249653048451545124879932565935237842521413255878328503110407553025
22 #[rustfmt::skip]
23 const COFACTOR: &'static [u64] = &[
24 15480692783052488705,
25 9802782456999489873,
26 14622846468721090623,
27 11702080941310629006,
28 4110145082483,
29 ];
30
31 /// COFACTOR^(-1) mod r =
32 /// 475922286169261325753349249653048451545124878207887910632124039320641839552134835598065665
33 #[rustfmt::skip]
34 const COFACTOR_INV: Fr = field_new!(Fr, "475922286169261325753349249653048451545124878207887910632124039320641839552134835598065665");
35}
36
37/// MUL_BY_A_C0 = NONRESIDUE * COEFF_A
38#[rustfmt::skip]
39pub const MUL_BY_A_C0: Fq = G1_COEFF_A_NON_RESIDUE;
40
41/// MUL_BY_A_C1 = NONRESIDUE * COEFF_A
42#[rustfmt::skip]
43pub const MUL_BY_A_C1: Fq = G1_COEFF_A_NON_RESIDUE;
44
45impl SWModelParameters for Parameters {
46 const COEFF_A: Fq2 = crate::Parameters::TWIST_COEFF_A;
47 // B coefficient of MNT4-298 G2 =
48 // ```
49 // mnt4298_twist_coeff_b = mnt4298_Fq2(mnt4298_Fq::zero(),
50 // mnt4298_G1::coeff_b * mnt4298_Fq2::non_residue);
51 // non_residue = mnt4298_Fq2::non_residue = mnt4298_Fq("13");
52 // = (ZERO, G1_B_COEFF * NON_RESIDUE);
53 // =
54 // (0, 67372828414711144619833451280373307321534573815811166723479321465776723059456513877937430)
55 // ```
56 #[rustfmt::skip]
57 const COEFF_B: Fq2 = field_new!(Fq2,
58 FQ_ZERO,
59 field_new!(Fq, "67372828414711144619833451280373307321534573815811166723479321465776723059456513877937430"),
60 );
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");