arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/bw6_761/src/curves/g1.rs
bw6_761/src/curves/g1.rsRaw
 1use ark_ec::{
 2    models::{short_weierstrass::SWCurveConfig, CurveConfig},
 3    scalar_mul::glv::GLVConfig,
 4    short_weierstrass::{Affine, Projective},
 5};
 6use ark_ff::{AdditiveGroup, BigInt, MontFp, PrimeField};
 7
 8use crate::{Fq, Fr};
 9
10pub type G1Affine = Affine<Config>;
11pub type G1Projective = Projective<Config>;
12
13#[derive(Clone, Default, PartialEq, Eq)]
14pub struct Config;
15
16impl CurveConfig for Config {
17    type BaseField = Fq;
18    type ScalarField = Fr;
19
20    /// COFACTOR =
21    /// 26642435879335816683987677701488073867751118270052650655942102502312977592501693353047140953112195348280268661194876
22    #[rustfmt::skip]
23    const COFACTOR: &'static [u64] = &[
24        0x3de580000000007c,
25        0x832ba4061000003b,
26        0xc61c554757551c0c,
27        0xc856a0853c9db94c,
28        0x2c77d5ac34cb12ef,
29        0xad1972339049ce76,
30    ];
31
32    /// COFACTOR^(-1) mod r =
33    /// 91141326767669940707819291241958318717982251277713150053234367522357946997763584490607453720072232540829942217804
34    const COFACTOR_INV: Fr = MontFp!("91141326767669940707819291241958318717982251277713150053234367522357946997763584490607453720072232540829942217804");
35}
36
37impl SWCurveConfig for Config {
38    /// COEFF_A = 0
39    const COEFF_A: Fq = Fq::ZERO;
40
41    /// COEFF_B = -1
42    const COEFF_B: Fq = MontFp!("-1");
43
44    /// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y)
45    const GENERATOR: G1Affine = G1Affine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y);
46    #[inline(always)]
47    fn mul_by_a(_elem: Self::BaseField) -> Self::BaseField {
48        use ark_ff::Zero;
49        Self::BaseField::zero()
50    }
51}
52
53impl GLVConfig for Config {
54    const ENDO_COEFFS: &'static [Self::BaseField] = &[MontFp!(
55        "4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775648"
56    )];
57
58    const LAMBDA: Self::ScalarField =
59        MontFp!("258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231");
60
61    const SCALAR_DECOMP_COEFFS: [(bool, <Self::ScalarField as PrimeField>::BigInt); 4] = [
62        (
63            true,
64            BigInt!("293634935485640680722085584138834120324914961969255022593"),
65        ),
66        (
67            false,
68            BigInt!("293634935485640680722085584138834120315328839056164388863"),
69        ),
70        (
71            true,
72            BigInt!("293634935485640680722085584138834120315328839056164388863"),
73        ),
74        (
75            true,
76            BigInt!("587269870971281361444171168277668240640243801025419411456"),
77        ),
78    ];
79
80    fn endomorphism(p: &Projective<Self>) -> Projective<Self> {
81        let mut res = (*p).clone();
82        res.x *= Self::ENDO_COEFFS[0];
83        res
84    }
85
86    fn endomorphism_affine(p: &Affine<Self>) -> Affine<Self> {
87        let mut res = (*p).clone();
88        res.x *= Self::ENDO_COEFFS[0];
89        res
90    }
91}
92
93/// G1_GENERATOR_X =
94/// 6238772257594679368032145693622812838779005809760824733138787810501188623461307351759238099287535516224314149266511977132140828635950940021790489507611754366317801811090811367945064510304504157188661901055903167026722666149426237
95pub const G1_GENERATOR_X: Fq = MontFp!("6238772257594679368032145693622812838779005809760824733138787810501188623461307351759238099287535516224314149266511977132140828635950940021790489507611754366317801811090811367945064510304504157188661901055903167026722666149426237");
96
97/// G1_GENERATOR_Y =
98/// 2101735126520897423911504562215834951148127555913367997162789335052900271653517958562461315794228241561913734371411178226936527683203879553093934185950470971848972085321797958124416462268292467002957525517188485984766314758624099
99pub const G1_GENERATOR_Y: Fq = MontFp!("2101735126520897423911504562215834951148127555913367997162789335052900271653517958562461315794228241561913734371411178226936527683203879553093934185950470971848972085321797958124416462268292467002957525517188485984766314758624099");