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::{
 2    models::{short_weierstrass::SWCurveConfig, CurveConfig},
 3    short_weierstrass::Affine,
 4};
 5use ark_ff::{Field, MontFp, Zero};
 6
 7use crate::{g1, Fq, Fq2, Fr};
 8
 9pub type G2Affine = Affine<Parameters>;
10#[derive(Clone, Default, PartialEq, Eq)]
11pub struct Parameters;
12
13impl CurveConfig for Parameters {
14    type BaseField = Fq2;
15    type ScalarField = Fr;
16
17    /// COFACTOR =
18    /// 7923214915284317143930293550643874566881017850177945424769256759165301436616933228209277966774092486467289478618404761412630691835764674559376407658497
19    #[rustfmt::skip]
20    const COFACTOR: &'static [u64] = &[
21        0x0000000000000001,
22        0x452217cc90000000,
23        0xa0f3622fba094800,
24        0xd693e8c36676bd09,
25        0x8c505634fae2e189,
26        0xfbb36b00e1dcc40c,
27        0xddd88d99a6f6a829,
28        0x26ba558ae9562a,
29    ];
30
31    /// COFACTOR_INV = COFACTOR^{-1} mod r
32    /// = 6764900296503390671038341982857278410319949526107311149686707033187604810669
33    const COFACTOR_INV: Fr =
34        MontFp!("6764900296503390671038341982857278410319949526107311149686707033187604810669");
35}
36
37impl SWCurveConfig for Parameters {
38    /// COEFF_A = [0, 0]
39    const COEFF_A: Fq2 = Fq2::new(g1::Parameters::COEFF_A, g1::Parameters::COEFF_A);
40
41    // As per https://eprint.iacr.org/2012/072.pdf,
42    // this curve has b' = b/i, where b is the COEFF_B of G1, and x^6 -i is
43    // the irreducible poly used to extend from Fp2 to Fp12.
44    // In our case, i = u (App A.3, T_6).
45    /// COEFF_B = [0,
46    /// 155198655607781456406391640216936120121836107652948796323930557600032281009004493664981332883744016074664192874906]
47    const COEFF_B: Fq2 = Fq2::new(
48        Fq::ZERO,
49        MontFp!("155198655607781456406391640216936120121836107652948796323930557600032281009004493664981332883744016074664192874906"),
50    );
51
52    /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
53    const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y);
54
55    #[inline(always)]
56    fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {
57        Self::BaseField::zero()
58    }
59}
60
61pub const G2_GENERATOR_X: Fq2 = Fq2::new(G2_GENERATOR_X_C0, G2_GENERATOR_X_C1);
62pub const G2_GENERATOR_Y: Fq2 = Fq2::new(G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1);
63
64/// G2_GENERATOR_X_C0 =
65/// 233578398248691099356572568220835526895379068987715365179118596935057653620464273615301663571204657964920925606294
66pub const G2_GENERATOR_X_C0: Fq = MontFp!("233578398248691099356572568220835526895379068987715365179118596935057653620464273615301663571204657964920925606294");
67
68/// G2_GENERATOR_X_C1 =
69/// 140913150380207355837477652521042157274541796891053068589147167627541651775299824604154852141315666357241556069118
70pub const G2_GENERATOR_X_C1: Fq = MontFp!("140913150380207355837477652521042157274541796891053068589147167627541651775299824604154852141315666357241556069118");
71
72/// G2_GENERATOR_Y_C0 =
73/// 63160294768292073209381361943935198908131692476676907196754037919244929611450776219210369229519898517858833747423
74pub const G2_GENERATOR_Y_C0: Fq = MontFp!("63160294768292073209381361943935198908131692476676907196754037919244929611450776219210369229519898517858833747423");
75
76/// G2_GENERATOR_Y_C1 =
77/// 149157405641012693445398062341192467754805999074082136895788947234480009303640899064710353187729182149407503257491
78pub const G2_GENERATOR_Y_C1: Fq = MontFp!("149157405641012693445398062341192467754805999074082136895788947234480009303640899064710353187729182149407503257491");