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