arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/bw6_761/src/curves/g2.rs
bw6_761/src/curves/g2.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 G2Affine = Affine<Config>;
 11pub type G2Projective = 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    /// 26642435879335816683987677701488073867751118270052650655942102502312977592501693353047140953112195348280268661194869
 22    #[rustfmt::skip]
 23    const COFACTOR: &'static [u64] = &[
 24        0x3de5800000000075,
 25        0x832ba4061000003b,
 26        0xc61c554757551c0c,
 27        0xc856a0853c9db94c,
 28        0x2c77d5ac34cb12ef,
 29        0xad1972339049ce76,
 30    ];
 31
 32    /// COFACTOR^(-1) mod r =
 33    /// 214911522365886453591244899095480747723790054550866810551297776298664428889000553861210287833206024638187939842124
 34    const COFACTOR_INV: Fr = MontFp!("214911522365886453591244899095480747723790054550866810551297776298664428889000553861210287833206024638187939842124");
 35}
 36
 37impl SWCurveConfig for Config {
 38    /// COEFF_A = 0
 39    const COEFF_A: Fq = Fq::ZERO;
 40
 41    /// COEFF_B = 4
 42    const COEFF_B: Fq = MontFp!("4");
 43
 44    /// AFFINE_GENERATOR_COEFFS = (G2_GENERATOR_X, G2_GENERATOR_Y)
 45    const GENERATOR: G2Affine = G2Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y);
 46
 47    #[inline(always)]
 48    fn mul_by_a(_elem: Self::BaseField) -> Self::BaseField {
 49        use ark_ff::Zero;
 50        Self::BaseField::zero()
 51    }
 52}
 53
 54impl GLVConfig for Config {
 55    const ENDO_COEFFS: &'static [Self::BaseField] = &[
 56        MontFp!("4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775648"),
 57    ];
 58
 59    const LAMBDA: Self::ScalarField =
 60        MontFp!("80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945");
 61
 62    const SCALAR_DECOMP_COEFFS: [(bool, <Self::ScalarField as PrimeField>::BigInt); 4] = [
 63        (
 64            true,
 65            BigInt!("293634935485640680722085584138834120315328839056164388863"),
 66        ),
 67        (
 68            false,
 69            BigInt!("293634935485640680722085584138834120324914961969255022593"),
 70        ),
 71        (
 72            true,
 73            BigInt!("293634935485640680722085584138834120324914961969255022593"),
 74        ),
 75        (
 76            true,
 77            BigInt!("587269870971281361444171168277668240640243801025419411456"),
 78        ),
 79    ];
 80
 81    fn endomorphism(p: &Projective<Self>) -> Projective<Self> {
 82        let mut res = (*p).clone();
 83        res.x *= Self::ENDO_COEFFS[0];
 84        res
 85    }
 86
 87    fn endomorphism_affine(p: &Affine<Self>) -> Affine<Self> {
 88        let mut res = (*p).clone();
 89        res.x *= Self::ENDO_COEFFS[0];
 90        res
 91    }
 92}
 93
 94/// G2_GENERATOR_X =
 95///  6445332910596979336035888152774071626898886139774101364933948236926875073754470830732273879639675437155036544153105017729592600560631678554299562762294743927912429096636156401171909259073181112518725201388196280039960074422214428
 96pub const G2_GENERATOR_X: Fq = MontFp!("6445332910596979336035888152774071626898886139774101364933948236926875073754470830732273879639675437155036544153105017729592600560631678554299562762294743927912429096636156401171909259073181112518725201388196280039960074422214428");
 97
 98/// G2_GENERATOR_Y =
 99/// 562923658089539719386922163444547387757586534741080263946953401595155211934630598999300396317104182598044793758153214972605680357108252243146746187917218885078195819486220416605630144001533548163105316661692978285266378674355041
100pub const G2_GENERATOR_Y: Fq = MontFp!("562923658089539719386922163444547387757586534741080263946953401595155211934630598999300396317104182598044793758153214972605680357108252243146746187917218885078195819486220416605630144001533548163105316661692978285266378674355041");