arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/bls12_381/src/curves/g1.rs
bls12_381/src/curves/g1.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 G1Affine = bls12::G1Affine<crate::Parameters>;
12pub type G1Projective = bls12::G1Projective<crate::Parameters>;
13
14#[derive(Clone, Default, PartialEq, Eq)]
15pub struct Parameters;
16
17impl ModelParameters for Parameters {
18    type BaseField = Fq;
19    type ScalarField = Fr;
20}
21
22impl SWModelParameters for Parameters {
23    /// COEFF_A = 0
24    const COEFF_A: Fq = field_new!(Fq, BigInteger384([0x0, 0x0, 0x0, 0x0, 0x0, 0x0]));
25
26    /// COEFF_B = 4
27    #[rustfmt::skip]
28    const COEFF_B: Fq = field_new!(Fq, BigInteger384([
29        0xaa270000000cfff3,
30        0x53cc0032fc34000a,
31        0x478fe97a6b0a807f,
32        0xb1d37ebee6ba24d7,
33        0x8ec9733bbf78ab2f,
34        0x9d645513d83de7e,
35    ]));
36
37    /// COFACTOR = (x - 1)^2 / 3  = 76329603384216526031706109802092473003
38    const COFACTOR: &'static [u64] = &[0x8c00aaab0000aaab, 0x396c8c005555e156];
39
40    /// COFACTOR_INV = COFACTOR^{-1} mod r
41    /// = 52435875175126190458656871551744051925719901746859129887267498875565241663483
42    #[rustfmt::skip]
43    const COFACTOR_INV: Fr = field_new!(Fr, BigInteger256([
44        288839107172787499,
45        1152722415086798946,
46        2612889808468387987,
47        5124657601728438008,
48    ]));
49
50    /// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y)
51    const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
52        (G1_GENERATOR_X, G1_GENERATOR_Y);
53
54    #[inline(always)]
55    fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {
56        Self::BaseField::zero()
57    }
58}
59
60/// G1_GENERATOR_X =
61/// 3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507
62#[rustfmt::skip]
63pub const G1_GENERATOR_X: Fq = field_new!(Fq, BigInteger384([
64    0x5cb38790fd530c16,
65    0x7817fc679976fff5,
66    0x154f95c7143ba1c1,
67    0xf0ae6acdf3d0e747,
68    0xedce6ecc21dbf440,
69    0x120177419e0bfb75,
70]));
71
72/// G1_GENERATOR_Y =
73/// 1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569
74#[rustfmt::skip]
75pub const G1_GENERATOR_Y: Fq = field_new!(Fq, BigInteger384([
76    0xbaac93d50ce72271,
77    0x8c22631a7918fd8e,
78    0xdd595f13570725ce,
79    0x51ac582950405194,
80    0xe1c8c3fad0059c0,
81    0xbbc3efc5008a26a,
82]));