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::{field_new, Zero};
7
8pub type G2Affine = bls12::G2Affine<crate::Parameters>;
9pub type G2Projective = bls12::G2Projective<crate::Parameters>;
10
11#[derive(Clone, Default, PartialEq, Eq)]
12pub struct Parameters;
13
14impl ModelParameters for Parameters {
15 type BaseField = Fq2;
16 type ScalarField = Fr;
17}
18
19impl SWModelParameters for Parameters {
20 /// COEFF_A = [0, 0]
21 const COEFF_A: Fq2 = field_new!(Fq2, g1::Parameters::COEFF_A, g1::Parameters::COEFF_A,);
22
23 /// COEFF_B = [4, 4]
24 const COEFF_B: Fq2 = field_new!(Fq2, g1::Parameters::COEFF_B, g1::Parameters::COEFF_B,);
25
26 /// COFACTOR = (x^8 - 4 x^7 + 5 x^6) - (4 x^4 + 6 x^3 - 4 x^2 - 4 x + 13) //
27 /// 9
28 /// = 305502333931268344200999753193121504214466019254188142667664032982267604182971884026507427359259977847832272839041616661285803823378372096355777062779109
29 #[rustfmt::skip]
30 const COFACTOR: &'static [u64] = &[
31 0xcf1c38e31c7238e5,
32 0x1616ec6e786f0c70,
33 0x21537e293a6691ae,
34 0xa628f1cb4d9e82ef,
35 0xa68a205b2e5a7ddf,
36 0xcd91de4547085aba,
37 0x91d50792876a202,
38 0x5d543a95414e7f1,
39 ];
40
41 /// COFACTOR_INV = COFACTOR^{-1} mod r
42 /// 26652489039290660355457965112010883481355318854675681319708643586776743290055
43 #[rustfmt::skip]
44 const COFACTOR_INV: Fr = field_new!(Fr, "26652489039290660355457965112010883481355318854675681319708643586776743290055");
45
46 /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
47 const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
48 (G2_GENERATOR_X, G2_GENERATOR_Y);
49
50 #[inline(always)]
51 fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {
52 Self::BaseField::zero()
53 }
54}
55
56pub const G2_GENERATOR_X: Fq2 = field_new!(Fq2, G2_GENERATOR_X_C0, G2_GENERATOR_X_C1);
57pub const G2_GENERATOR_Y: Fq2 = field_new!(Fq2, G2_GENERATOR_Y_C0, G2_GENERATOR_Y_C1);
58
59/// G2_GENERATOR_X_C0 =
60/// 352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160
61#[rustfmt::skip]
62pub const G2_GENERATOR_X_C0: Fq = field_new!(Fq, "352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160");
63
64/// G2_GENERATOR_X_C1 =
65/// 3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758
66#[rustfmt::skip]
67pub const G2_GENERATOR_X_C1: Fq = field_new!(Fq, "3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758");
68
69/// G2_GENERATOR_Y_C0 =
70/// 1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905
71#[rustfmt::skip]
72pub const G2_GENERATOR_Y_C0: Fq = field_new!(Fq, "1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905");
73
74/// G2_GENERATOR_Y_C1 =
75/// 927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582
76#[rustfmt::skip]
77pub const G2_GENERATOR_Y_C1: Fq = field_new!(Fq, "927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582");