arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/bls12_381/src/curves/g2.rs
bls12_381/src/curves/g2.rsRaw
  1use crate::*;
  2use ark_ec::{
  3    bls12,
  4    models::{ModelParameters, SWModelParameters},
  5};
  6use ark_ff::{
  7    biginteger::{BigInteger256, BigInteger384},
  8    field_new, Zero,
  9};
 10
 11pub type G2Affine = bls12::G2Affine<crate::Parameters>;
 12pub type G2Projective = bls12::G2Projective<crate::Parameters>;
 13
 14#[derive(Clone, Default, PartialEq, Eq)]
 15pub struct Parameters;
 16
 17impl ModelParameters for Parameters {
 18    type BaseField = Fq2;
 19    type ScalarField = Fr;
 20}
 21
 22impl SWModelParameters for Parameters {
 23    /// COEFF_A = [0, 0]
 24    const COEFF_A: Fq2 = field_new!(Fq2, g1::Parameters::COEFF_A, g1::Parameters::COEFF_A,);
 25
 26    /// COEFF_B = [4, 4]
 27    const COEFF_B: Fq2 = field_new!(Fq2, g1::Parameters::COEFF_B, g1::Parameters::COEFF_B,);
 28
 29    /// COFACTOR = (x^8 - 4 x^7 + 5 x^6) - (4 x^4 + 6 x^3 - 4 x^2 - 4 x + 13) //
 30    /// 9
 31    /// = 305502333931268344200999753193121504214466019254188142667664032982267604182971884026507427359259977847832272839041616661285803823378372096355777062779109
 32    #[rustfmt::skip]
 33    const COFACTOR: &'static [u64] = &[
 34        0xcf1c38e31c7238e5,
 35        0x1616ec6e786f0c70,
 36        0x21537e293a6691ae,
 37        0xa628f1cb4d9e82ef,
 38        0xa68a205b2e5a7ddf,
 39        0xcd91de4547085aba,
 40        0x91d50792876a202,
 41        0x5d543a95414e7f1,
 42    ];
 43
 44    /// COFACTOR_INV = COFACTOR^{-1} mod r
 45    /// 26652489039290660355457965112010883481355318854675681319708643586776743290055
 46    #[rustfmt::skip]
 47    const COFACTOR_INV: Fr = field_new!(Fr, BigInteger256([
 48        6746407649509787816,
 49        1304054119431494378,
 50        2461312685643913071,
 51        5956596749362435284,
 52    ]));
 53
 54    /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
 55    const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
 56        (G2_GENERATOR_X, G2_GENERATOR_Y);
 57
 58    #[inline(always)]
 59    fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {
 60        Self::BaseField::zero()
 61    }
 62}
 63
 64pub const G2_GENERATOR_X: Fq2 = field_new!(Fq2, G2_GENERATOR_X_C0, G2_GENERATOR_X_C1);
 65pub const G2_GENERATOR_Y: Fq2 = field_new!(Fq2, G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1);
 66
 67/// G2_GENERATOR_X_C0 =
 68/// 352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160
 69#[rustfmt::skip]
 70pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, BigInteger384([
 71    0xf5f28fa202940a10,
 72    0xb3f5fb2687b4961a,
 73    0xa1a893b53e2ae580,
 74    0x9894999d1a3caee9,
 75    0x6f67b7631863366b,
 76    0x58191924350bcd7,
 77]));
 78
 79/// G2_GENERATOR_X_C1 =
 80/// 3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758
 81#[rustfmt::skip]
 82pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, BigInteger384([
 83    0xa5a9c0759e23f606,
 84    0xaaa0c59dbccd60c3,
 85    0x3bb17e18e2867806,
 86    0x1b1ab6cc8541b367,
 87    0xc2b6ed0ef2158547,
 88    0x11922a097360edf3,
 89]));
 90
 91/// G2_GENERATOR_Y_C0 =
 92/// 1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905
 93#[rustfmt::skip]
 94pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, BigInteger384([
 95    0x4c730af860494c4a,
 96    0x597cfa1f5e369c5a,
 97    0xe7e6856caa0a635a,
 98    0xbbefb5e96e0d495f,
 99    0x7d3a975f0ef25a2,
100    0x83fd8e7e80dae5,
101]));
102
103/// G2_GENERATOR_Y_C1 =
104/// 927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582
105#[rustfmt::skip]
106pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, BigInteger384([
107    0xadc0fc92df64b05d,
108    0x18aa270a2b1461dc,
109    0x86adac6a3be4eba0,
110    0x79495c4ec93da33a,
111    0xe7175850a43ccaed,
112    0xb2bc2a163de1bf2,
113]));