arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/bn254/src/fields/fq.rs
bn254/src/fields/fq.rsRaw
 1use ark_ff::{biginteger::BigInteger256 as BigInteger, field_new, fields::*};
 2
 3pub type Fq = Fp256<FqParameters>;
 4
 5pub struct FqParameters;
 6
 7impl Fp256Parameters for FqParameters {}
 8impl FftParameters for FqParameters {
 9    type BigInt = BigInteger;
10
11    const TWO_ADICITY: u32 = 1;
12
13    #[rustfmt::skip]
14    const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInteger([
15        0x68c3488912edefaa,
16        0x8d087f6872aabf4f,
17        0x51e1a24709081231,
18        0x2259d6b14729c0fa,
19    ]);
20}
21impl FpParameters for FqParameters {
22    /// MODULUS = 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177
23    #[rustfmt::skip]
24    const MODULUS: BigInteger = BigInteger([
25        0x3c208c16d87cfd47,
26        0x97816a916871ca8d,
27        0xb85045b68181585d,
28        0x30644e72e131a029,
29    ]);
30
31    const MODULUS_BITS: u32 = 254;
32
33    const CAPACITY: u32 = Self::MODULUS_BITS - 1;
34
35    const REPR_SHAVE_BITS: u32 = 2;
36
37    #[rustfmt::skip]
38    const R: BigInteger = BigInteger([
39        0xd35d438dc58f0d9d,
40        0x0a78eb28f5c70b3d,
41        0x666ea36f7879462c,
42        0xe0a77c19a07df2f,
43    ]);
44
45    #[rustfmt::skip]
46    const R2: BigInteger = BigInteger([
47        0xf32cfc5b538afa89,
48        0xb5e71911d44501fb,
49        0x47ab1eff0a417ff6,
50        0x6d89f71cab8351f,
51    ]);
52
53    const INV: u64 = 9786893198990664585u64;
54
55    // GENERATOR = 3
56    #[rustfmt::skip]
57    const GENERATOR: BigInteger = BigInteger([
58        0x7a17caa950ad28d7,
59        0x1f6ac17ae15521b9,
60        0x334bea4e696bd284,
61        0x2a1f6744ce179d8e,
62    ]);
63
64    #[rustfmt::skip]
65    const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
66        0x9e10460b6c3e7ea3,
67        0xcbc0b548b438e546,
68        0xdc2822db40c0ac2e,
69        0x183227397098d014,
70    ]);
71
72    // T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
73
74    // T = (MODULUS - 1) // 2^S =
75    // 10944121435919637611123202872628637544348155578648911831344518947322613104291
76    #[rustfmt::skip]
77    const T: BigInteger = BigInteger([
78        0x9e10460b6c3e7ea3,
79        0xcbc0b548b438e546,
80        0xdc2822db40c0ac2e,
81        0x183227397098d014,
82    ]);
83
84    // (T - 1) // 2 =
85    // 1837921289030710838195067919506396475074392872918698035817074744121558668640693829665401097909504529
86    #[rustfmt::skip]
87    const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
88        0x4f082305b61f3f51,
89        0x65e05aa45a1c72a3,
90        0x6e14116da0605617,
91        0xc19139cb84c680a,
92    ]);
93}
94
95pub const FQ_ONE: Fq = field_new!(Fq, "1");
96pub const FQ_ZERO: Fq = field_new!(Fq, "0");