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