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    /// COFACTOR =
 22    /// 226502022472576270196498690498308461791828762732602586162207535351960270082712694977333372361549082214519252261735048131889018501404377856786623430385820659037970876666767495659520
 23    #[rustfmt::skip]
 24    const COFACTOR: &'static [u64] = &[
 25        15308190245346869248,
 26        10669098443577192943,
 27        4561413759929581409,
 28        3680089780298582849,
 29        17336300687782721465,
 30        10745756320947240891,
 31        17479264233688728128,
 32        16828697388537672097,
 33        4184034152442024798,
 34        915787,
 35    ];
 36
 37    /// COFACTOR^(-1) mod r =
 38    /// 79320381028210220958891541608841408590854146655427655872973753568875979721417185067925504
 39    #[rustfmt::skip]
 40    const COFACTOR_INV: Fr = field_new!(Fr, "79320381028210220958891541608841408590854146655427655872973753568875979721417185067925504");
 41}
 42
 43/// MUL_BY_A_C0 = NONRESIDUE * COEFF_A = 5 * 11
 44    #[rustfmt::skip]
 45pub const MUL_BY_A_C0: Fq = field_new!(Fq, "55");
 46
 47/// MUL_BY_A_C1 = NONRESIDUE * COEFF_A
 48    #[rustfmt::skip]
 49pub const MUL_BY_A_C1: Fq = field_new!(Fq, "55");
 50
 51/// MUL_BY_A_C2 = COEFF_A
 52pub const MUL_BY_A_C2: Fq = g1::Parameters::COEFF_A;
 53
 54impl SWModelParameters for Parameters {
 55    const COEFF_A: Fq3 = crate::Parameters::TWIST_COEFF_A;
 56    #[rustfmt::skip]
 57    const COEFF_B: Fq3 = field_new!(Fq3,
 58        // 5 * G1::COEFF_B
 59        field_new!(Fq, "57578116384997352636487348509878309737146377454014423897662211075515354005624851787652233"),
 60        FQ_ZERO,
 61        FQ_ZERO,
 62    );
 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!(
 85    Fq,
 86    "421456435772811846256826561593908322288509115489119907560382401870203318738334702321297427"
 87);
 88pub const G2_GENERATOR_X_C1: Fq = field_new!(
 89    Fq,
 90    "103072927438548502463527009961344915021167584706439945404959058962657261178393635706405114"
 91);
 92pub const G2_GENERATOR_X_C2: Fq = field_new!(
 93    Fq,
 94    "143029172143731852627002926324735183809768363301149009204849580478324784395590388826052558"
 95);
 96
 97pub const G2_GENERATOR_Y_C0: Fq = field_new!(
 98    Fq,
 99    "464673596668689463130099227575639512541218133445388869383893594087634649237515554342751377"
100);
101pub const G2_GENERATOR_Y_C1: Fq = field_new!(
102    Fq,
103    "100642907501977375184575075967118071807821117960152743335603284583254620685343989304941678"
104);
105pub const G2_GENERATOR_Y_C2: Fq = field_new!(
106    Fq,
107    "123019855502969896026940545715841181300275180157288044663051565390506010149881373807142903"
108);