arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/bls12_377/src/curves/g2.rs
bls12_377/src/curves/g2.rsRaw
  1use ark_ec::models::{ModelParameters, SWModelParameters};
  2use ark_ff::{
  3    biginteger::{BigInteger256, BigInteger384},
  4    field_new, Zero,
  5};
  6
  7use crate::{g1, Fq, Fq2, Fr};
  8
  9#[derive(Clone, Default, PartialEq, Eq)]
 10pub struct Parameters;
 11
 12impl ModelParameters for Parameters {
 13    type BaseField = Fq2;
 14    type ScalarField = Fr;
 15}
 16
 17impl SWModelParameters for Parameters {
 18    /// COEFF_A = [0, 0]
 19    #[rustfmt::skip]
 20    const COEFF_A: Fq2 = field_new!(Fq2,
 21        g1::Parameters::COEFF_A,
 22        g1::Parameters::COEFF_A,
 23    );
 24
 25    // As per https://eprint.iacr.org/2012/072.pdf,
 26    // this curve has b' = b/i, where b is the COEFF_B of G1, and x^6 -i is
 27    // the irreducible poly used to extend from Fp2 to Fp12.
 28    // In our case, i = u (App A.3, T_6).
 29    /// COEFF_B = [0,
 30    /// 155198655607781456406391640216936120121836107652948796323930557600032281009004493664981332883744016074664192874906]
 31    #[rustfmt::skip]
 32    const COEFF_B: Fq2 = field_new!(Fq2,
 33        field_new!(Fq, BigInteger384([0, 0, 0, 0, 0, 0])),
 34        field_new!(Fq, BigInteger384([
 35            9255502405446297221,
 36            10229180150694123945,
 37            9215585410771530959,
 38            13357015519562362907,
 39            5437107869987383107,
 40            16259554076827459,
 41        ])),
 42    );
 43
 44    /// COFACTOR =
 45    /// 7923214915284317143930293550643874566881017850177945424769256759165301436616933228209277966774092486467289478618404761412630691835764674559376407658497
 46    #[rustfmt::skip]
 47    const COFACTOR: &'static [u64] = &[
 48        0x0000000000000001,
 49        0x452217cc90000000,
 50        0xa0f3622fba094800,
 51        0xd693e8c36676bd09,
 52        0x8c505634fae2e189,
 53        0xfbb36b00e1dcc40c,
 54        0xddd88d99a6f6a829,
 55        0x26ba558ae9562a,
 56    ];
 57
 58    /// COFACTOR_INV = COFACTOR^{-1} mod r
 59    /// = 6764900296503390671038341982857278410319949526107311149686707033187604810669
 60    #[rustfmt::skip]
 61    const COFACTOR_INV: Fr = field_new!(Fr, BigInteger256([
 62        15499857013495546999,
 63        4613531467548868169,
 64        14546778081091178013,
 65        549402535258503313,
 66    ]));
 67
 68    /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
 69    const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
 70        (G2_GENERATOR_X, G2_GENERATOR_Y);
 71
 72    #[inline(always)]
 73    fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {
 74        Self::BaseField::zero()
 75    }
 76}
 77
 78#[rustfmt::skip]
 79pub const G2_GENERATOR_X: Fq2 = field_new!(Fq2, G2_GENERATOR_X_C0, G2_GENERATOR_X_C1);
 80#[rustfmt::skip]
 81pub const G2_GENERATOR_Y: Fq2 = field_new!(Fq2, G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1);
 82
 83/// G2_GENERATOR_X_C0 =
 84/// 233578398248691099356572568220835526895379068987715365179118596935057653620464273615301663571204657964920925606294
 85#[rustfmt::skip]
 86pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, BigInteger384([
 87    0x68904082f268725b,
 88    0x668f2ea74f45328b,
 89    0xebca7a65802be84f,
 90    0x1e1850f4c1ada3e6,
 91    0x830dc22d588ef1e9,
 92    0x1862a81767c0982,
 93]));
 94
 95/// G2_GENERATOR_X_C1 =
 96/// 140913150380207355837477652521042157274541796891053068589147167627541651775299824604154852141315666357241556069118
 97#[rustfmt::skip]
 98pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, BigInteger384([
 99    0x5f02a915c91c7f39,
100    0xf8c553ba388da2a7,
101    0xd51a416dbd198850,
102    0xe943c6f38ae3073a,
103    0xffe24aa8259a4981,
104    0x11853391e73dfdd,
105]));
106
107/// G2_GENERATOR_Y_C0 =
108/// 63160294768292073209381361943935198908131692476676907196754037919244929611450776219210369229519898517858833747423
109#[rustfmt::skip]
110pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, BigInteger384([
111    0xd5b19b897881430f,
112    0x5be9118a5b371ed,
113    0x6063f91f86c131ee,
114    0x3244a61be8f4ec19,
115    0xa02e425b9f9a3a12,
116    0x18af8c04f3360d2,
117]));
118
119/// G2_GENERATOR_Y_C1 =
120/// 149157405641012693445398062341192467754805999074082136895788947234480009303640899064710353187729182149407503257491
121#[rustfmt::skip]
122pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, BigInteger384([
123    0x57601ac71a5b96f5,
124    0xe99acc1714f2440e,
125    0x2339612f10118ea9,
126    0x8321e68a3b1cd722,
127    0x2b543b050cc74917,
128    0x590182b396c112,
129]));