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