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::{biginteger::BigInteger320, 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, BigInteger320([
 44            9511110677122940475,
 45            13403516020116973437,
 46            1464701424831086967,
 47            4646785117660390394,
 48            1747881737068,
 49        ])),
 50    );
 51
 52    /// COFACTOR =
 53    /// 475922286169261325753349249653048451545124879932565935237842521413255878328503110407553025
 54    #[rustfmt::skip]
 55    const COFACTOR: &'static [u64] = &[
 56        15480692783052488705,
 57        9802782456999489873,
 58        14622846468721090623,
 59        11702080941310629006,
 60        4110145082483,
 61    ];
 62
 63    /// COFACTOR^(-1) mod r =
 64    /// 475922286169261325753349249653048451545124878207887910632124039320641839552134835598065665
 65    #[rustfmt::skip]
 66    const COFACTOR_INV: Fr = field_new!(Fr, BigInteger320([
 67        8065818351154103109,
 68        7537800592537321232,
 69        747075088561892445,
 70        6335802185495034136,
 71        1874289794052,
 72    ]));
 73
 74    /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
 75    const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
 76        (G2_GENERATOR_X, G2_GENERATOR_Y);
 77
 78    #[inline(always)]
 79    fn mul_by_a(elt: &Fq2) -> Fq2 {
 80        field_new!(Fq2, MUL_BY_A_C0 * &elt.c0, MUL_BY_A_C1 * &elt.c1,)
 81    }
 82}
 83
 84const G2_GENERATOR_X: Fq2 = field_new!(Fq2, G2_GENERATOR_X_C0, G2_GENERATOR_X_C1);
 85const G2_GENERATOR_Y: Fq2 = field_new!(Fq2, G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1);
 86
 87// Generator of G2
 88// These are two Fq elements each because X and Y (and Z) are elements of Fq^2
 89// X = 438374926219350099854919100077809681842783509163790991847867546339851681564223481322252708,
 90// 37620953615500480110935514360923278605464476459712393277679280819942849043649216370485641,
 91// Y = 37437409008528968268352521034936931842973546441370663118543015118291998305624025037512482,
 92// 424621479598893882672393190337420680597584695892317197646113820787463109735345923009077489,
 93#[rustfmt::skip]
 94pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, BigInteger320([
 95    5356671649366391794,
 96    2684151262065976452,
 97    4683110650642896126,
 98    10421299515941681582,
 99    1618695480960
100]));
101
102#[rustfmt::skip]
103pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, BigInteger320([
104    133394645290266480,
105    15395232932057272770,
106    18271324022738539173,
107    9095178119640120034,
108    2303787573609
109]));
110
111#[rustfmt::skip]
112pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, BigInteger320([
113    16920448081812496532,
114    15580160192086626100,
115    3974467672100342742,
116    8216505962266760277,
117    2643162835232
118]));
119
120#[rustfmt::skip]
121pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, BigInteger320([
122    73816197493558356,
123    8663991890578965996,
124    11575903875707445958,
125    17953546933481201011,
126    2167465829200
127]));