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::{CubicExt, MontFp};
  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    const COFACTOR_INV: Fr = MontFp!(
 40        Fr,
 41        "79320381028210220958891541608841408590854146655427655872973753568875979721417185067925504"
 42    );
 43}
 44
 45/// MUL_BY_A_C0 = NONRESIDUE * COEFF_A = 5 * 11
 46pub const MUL_BY_A_C0: Fq = MontFp!(Fq, "55");
 47
 48/// MUL_BY_A_C1 = NONRESIDUE * COEFF_A
 49pub const MUL_BY_A_C1: Fq = MontFp!(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    const COEFF_B: Fq3 = CubicExt!(
 57        // 5 * G1::COEFF_B
 58        MontFp!(Fq, "57578116384997352636487348509878309737146377454014423897662211075515354005624851787652233"),
 59        FQ_ZERO,
 60        FQ_ZERO,
 61    );
 62
 63    /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
 64    const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
 65        (G2_GENERATOR_X, G2_GENERATOR_Y);
 66
 67    #[inline(always)]
 68    fn mul_by_a(elt: &Fq3) -> Fq3 {
 69        CubicExt!(
 70            MUL_BY_A_C0 * &elt.c1,
 71            MUL_BY_A_C1 * &elt.c2,
 72            MUL_BY_A_C2 * &elt.c0,
 73        )
 74    }
 75}
 76
 77const G2_GENERATOR_X: Fq3 = CubicExt!(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1, G2_GENERATOR_X_C2);
 78const G2_GENERATOR_Y: Fq3 = CubicExt!(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1, G2_GENERATOR_Y_C2);
 79
 80pub const G2_GENERATOR_X_C0: Fq = MontFp!(
 81    Fq,
 82    "421456435772811846256826561593908322288509115489119907560382401870203318738334702321297427"
 83);
 84pub const G2_GENERATOR_X_C1: Fq = MontFp!(
 85    Fq,
 86    "103072927438548502463527009961344915021167584706439945404959058962657261178393635706405114"
 87);
 88pub const G2_GENERATOR_X_C2: Fq = MontFp!(
 89    Fq,
 90    "143029172143731852627002926324735183809768363301149009204849580478324784395590388826052558"
 91);
 92
 93pub const G2_GENERATOR_Y_C0: Fq = MontFp!(
 94    Fq,
 95    "464673596668689463130099227575639512541218133445388869383893594087634649237515554342751377"
 96);
 97pub const G2_GENERATOR_Y_C1: Fq = MontFp!(
 98    Fq,
 99    "100642907501977375184575075967118071807821117960152743335603284583254620685343989304941678"
100);
101pub const G2_GENERATOR_Y_C2: Fq = MontFp!(
102    Fq,
103    "123019855502969896026940545715841181300275180157288044663051565390506010149881373807142903"
104);