arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/bls12_377/src/fields/fq.rs
bls12_377/src/fields/fq.rsRaw
  1use ark_ff::{
  2    biginteger::{BigInt, BigInteger384 as BigInteger},
  3    fields::*,
  4};
  5
  6pub type Fq = Fp384<FqParameters>;
  7
  8pub struct FqParameters;
  9
 10impl Fp384Parameters for FqParameters {}
 11impl FftParameters for FqParameters {
 12    type BigInt = BigInteger;
 13
 14    const TWO_ADICITY: u32 = 46u32;
 15
 16    #[rustfmt::skip]
 17    const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
 18        2022196864061697551u64,
 19        17419102863309525423u64,
 20        8564289679875062096u64,
 21        17152078065055548215u64,
 22        17966377291017729567u64,
 23        68610905582439508u64,
 24    ]);
 25}
 26impl FpParameters for FqParameters {
 27    /// MODULUS = 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177
 28    #[rustfmt::skip]
 29    const MODULUS: BigInteger = BigInt::new([
 30        0x8508c00000000001,
 31        0x170b5d4430000000,
 32        0x1ef3622fba094800,
 33        0x1a22d9f300f5138f,
 34        0xc63b05c06ca1493b,
 35        0x1ae3a4617c510ea,
 36    ]);
 37
 38    const MODULUS_BITS: u32 = 377;
 39
 40    const CAPACITY: u32 = Self::MODULUS_BITS - 1;
 41
 42    const REPR_SHAVE_BITS: u32 = 7;
 43
 44    /// R = 85013442423176922659824578519796707547925331718418265885885478904210582549405549618995257669764901891699128663912
 45    #[rustfmt::skip]
 46    const R: BigInteger = BigInt::new([
 47        202099033278250856u64,
 48        5854854902718660529u64,
 49        11492539364873682930u64,
 50        8885205928937022213u64,
 51        5545221690922665192u64,
 52        39800542322357402u64,
 53    ]);
 54
 55    #[rustfmt::skip]
 56    const R2: BigInteger = BigInt::new([
 57        0xb786686c9400cd22,
 58        0x329fcaab00431b1,
 59        0x22a5f11162d6b46d,
 60        0xbfdf7d03827dc3ac,
 61        0x837e92f041790bf9,
 62        0x6dfccb1e914b88,
 63    ]);
 64
 65    const INV: u64 = 9586122913090633727u64;
 66
 67    /// GENERATOR = -5
 68    /// Encoded in Montgomery form, so the value here is
 69    /// (-5 * R) % q = 92261639910053574722182574790803529333160366917737991650341130812388023949653897454961487930322210790384999596794
 70    #[rustfmt::skip]
 71    const GENERATOR: BigInteger = BigInt::new([
 72        0xfc0b8000000002fa,
 73        0x97d39cf6e000018b,
 74        0x2072420fbfa05044,
 75        0xcbbcbd50d97c3802,
 76        0xbaf1ec35813f9eb,
 77        0x9974a2c0945ad2,
 78    ]);
 79
 80    #[rustfmt::skip]
 81    const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
 82        0x4284600000000000,
 83        0xb85aea218000000,
 84        0x8f79b117dd04a400,
 85        0x8d116cf9807a89c7,
 86        0x631d82e03650a49d,
 87        0xd71d230be28875,
 88    ]);
 89
 90    // T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
 91    // For T coprime to 2
 92
 93    // T = (MODULUS - 1) // 2^S =
 94    // 3675842578061421676390135839012792950148785745837396071634149488243117337281387659330802195819009059
 95    #[rustfmt::skip]
 96    const T: BigInteger = BigInt::new([
 97        0x7510c00000021423,
 98        0x88bee82520005c2d,
 99        0x67cc03d44e3c7bcd,
100        0x1701b28524ec688b,
101        0xe9185f1443ab18ec,
102        0x6b8,
103    ]);
104
105    // (T - 1) // 2 =
106    // 1837921289030710838195067919506396475074392872918698035817074744121558668640693829665401097909504529
107    #[rustfmt::skip]
108    const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
109        0xba88600000010a11,
110        0xc45f741290002e16,
111        0xb3e601ea271e3de6,
112        0xb80d94292763445,
113        0x748c2f8a21d58c76,
114        0x35c,
115    ]);
116}
117
118#[allow(dead_code)]
119pub const FQ_ONE: Fq = Fq::new(FqParameters::R);
120#[allow(dead_code)]
121pub const FQ_ZERO: Fq = Fq::new(BigInt::new([0, 0, 0, 0, 0, 0]));