arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/bn254/src/curves/g2.rs
bn254/src/curves/g2.rsRaw
  1use ark_ec::models::{ModelParameters, SWModelParameters};
  2use ark_ff::{biginteger::BigInteger256, field_new, Zero};
  3
  4use crate::{g1, Fq, Fq2, Fr};
  5
  6#[derive(Clone, Default, PartialEq, Eq)]
  7pub struct Parameters;
  8
  9impl ModelParameters for Parameters {
 10    type BaseField = Fq2;
 11    type ScalarField = Fr;
 12}
 13
 14impl SWModelParameters for Parameters {
 15    /// COEFF_A = [0, 0]
 16    #[rustfmt::skip]
 17    const COEFF_A: Fq2 = field_new!(Fq2,
 18        g1::Parameters::COEFF_A,
 19        g1::Parameters::COEFF_A,
 20    );
 21
 22    /// COEFF_B = 3/(u+9)
 23    ///         = (19485874751759354771024239261021720505790618469301721065564631296452457478373, 266929791119991161246907387137283842545076965332900288569378510910307636690)
 24    #[rustfmt::skip]
 25    const COEFF_B: Fq2 = field_new!(Fq2,
 26        field_new!(Fq, BigInteger256([
 27            0x3bf938e377b802a8,
 28            0x020b1b273633535d,
 29            0x26b7edf049755260,
 30            0x2514c6324384a86d,
 31        ])),
 32        field_new!(Fq, BigInteger256([
 33            0x38e7ecccd1dcff67,
 34            0x65f0b37d93ce0d3e,
 35            0xd749d0dd22ac00aa,
 36            0x0141b9ce4a688d4d,
 37        ])),
 38    );
 39
 40    /// COFACTOR = (36 * X^4) + (36 * X^3) + (30 * X^2) + 6*X + 1
 41    ///          = 21888242871839275222246405745257275088844257914179612981679871602714643921549
 42    #[rustfmt::skip]
 43    const COFACTOR: &'static [u64] = &[
 44        0x345f2299c0f9fa8d,
 45        0x06ceecda572a2489,
 46        0xb85045b68181585e,
 47        0x30644e72e131a029,
 48    ];
 49
 50    /// COFACTOR_INV = COFACTOR^{-1} mod r
 51    #[rustfmt::skip]
 52    const COFACTOR_INV: Fr = field_new!(Fr, BigInteger256([
 53        0x7fff17d53ff2895e,
 54        0xd0617390cf7919e5,
 55        0xb9af426b22d0eb61,
 56        0x270485e31bd72a4d,
 57    ]));
 58
 59    /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
 60    const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
 61        (G2_GENERATOR_X, G2_GENERATOR_Y);
 62
 63    #[inline(always)]
 64    fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {
 65        Self::BaseField::zero()
 66    }
 67}
 68
 69#[rustfmt::skip]
 70pub const G2_GENERATOR_X: Fq2 = field_new!(Fq2, G2_GENERATOR_X_C0, G2_GENERATOR_X_C1);
 71#[rustfmt::skip]
 72pub const G2_GENERATOR_Y: Fq2 = field_new!(Fq2, G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1);
 73
 74/// G2_GENERATOR_X_C0 =
 75/// 10857046999023057135944570762232829481370756359578518086990519993285655852781
 76#[rustfmt::skip]
 77pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, BigInteger256([
 78    0x8e83b5d102bc2026,
 79    0xdceb1935497b0172,
 80    0xfbb8264797811adf,
 81    0x19573841af96503b,
 82]));
 83
 84/// G2_GENERATOR_X_C1 =
 85/// 11559732032986387107991004021392285783925812861821192530917403151452391805634
 86#[rustfmt::skip]
 87pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, BigInteger256([
 88    0xafb4737da84c6140,
 89    0x6043dd5a5802d8c4,
 90    0x09e950fc52a02f86,
 91    0x14fef0833aea7b6b,
 92]));
 93
 94/// G2_GENERATOR_Y_C0 =
 95/// 8495653923123431417604973247489272438418190587263600148770280649306958101930
 96#[rustfmt::skip]
 97pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, BigInteger256([
 98    0x619dfa9d886be9f6,
 99    0xfe7fd297f59e9b78,
100    0xff9e1a62231b7dfe,
101    0x28fd7eebae9e4206,
102]));
103
104/// G2_GENERATOR_Y_C1 =
105/// 4082367875863433681332203403145435568316851327593401208105741076214120093531
106#[rustfmt::skip]
107pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, BigInteger256([
108    0x64095b56c71856ee,
109    0xdc57f922327d3cbb,
110    0x55f935be33351076,
111    0x0da4a0e693fd6482,
112]));