ark-curves-cherry-picked/bls12_381/src/fields/fq.rs
bls12_381/src/fields/fq.rsRaw
1use ark_ff::{
2 biginteger::{BigInt, BigInteger384 as BigInteger},
3 field_new,
4 fields::{FftParameters, Fp384, Fp384Parameters, FpParameters},
5};
6
7pub type Fq = Fp384<FqParameters>;
8
9pub struct FqParameters;
10
11impl Fp384Parameters 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 0x43f5fffffffcaaae,
20 0x32b7fff2ed47fffd,
21 0x7e83a49a2e99d69,
22 0xeca8f3318332bb7a,
23 0xef148d1ea0f4c069,
24 0x40ab3263eff0206,
25 ]);
26}
27impl FpParameters for FqParameters {
28 /// MODULUS = 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787
29 #[rustfmt::skip]
30 const MODULUS: BigInteger = BigInt::new([
31 0xb9feffffffffaaab,
32 0x1eabfffeb153ffff,
33 0x6730d2a0f6b0f624,
34 0x64774b84f38512bf,
35 0x4b1ba7b6434bacd7,
36 0x1a0111ea397fe69a,
37 ]);
38
39 const MODULUS_BITS: u32 = 381;
40
41 const CAPACITY: u32 = Self::MODULUS_BITS - 1;
42
43 const REPR_SHAVE_BITS: u32 = 3;
44
45 /// R = 3380320199399472671518931668520476396067793891014375699959770179129436917079669831430077592723774664465579537268733
46 #[rustfmt::skip]
47 const R: BigInteger = BigInt::new([
48 0x760900000002fffd,
49 0xebf4000bc40c0002,
50 0x5f48985753c758ba,
51 0x77ce585370525745,
52 0x5c071a97a256ec6d,
53 0x15f65ec3fa80e493,
54 ]);
55
56 #[rustfmt::skip]
57 const R2: BigInteger = BigInt::new([
58 0xf4df1f341c341746,
59 0xa76e6a609d104f1,
60 0x8de5476c4c95b6d5,
61 0x67eb88a9939d83c0,
62 0x9a793e85b519952d,
63 0x11988fe592cae3aa,
64 ]);
65
66 const INV: u64 = 0x89f3fffcfffcfffd;
67
68 /// GENERATOR = 2
69 /// Encoded in Montgomery form, so the value is
70 /// 2 * R % q = 2758230843577277949620073511305048635578704962089743514587482222134842183668501798417467556318533664893264801977679
71 #[rustfmt::skip]
72 const GENERATOR: BigInteger = BigInt::new([
73 0x321300000006554f,
74 0xb93c0018d6c40005,
75 0x57605e0db0ddbb51,
76 0x8b256521ed1f9bcb,
77 0x6cf28d7901622c03,
78 0x11ebab9dbb81e28c,
79 ]);
80
81 #[rustfmt::skip]
82 const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
83 0xdcff7fffffffd555,
84 0xf55ffff58a9ffff,
85 0xb39869507b587b12,
86 0xb23ba5c279c2895f,
87 0x258dd3db21a5d66b,
88 0xd0088f51cbff34d,
89 ]);
90
91 /// T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
92 /// For T coprime to 2
93 #[rustfmt::skip]
94 const T: BigInteger = BigInt::new([
95 0xdcff7fffffffd555,
96 0xf55ffff58a9ffff,
97 0xb39869507b587b12,
98 0xb23ba5c279c2895f,
99 0x258dd3db21a5d66b,
100 0xd0088f51cbff34d,
101 ]);
102
103 #[rustfmt::skip]
104 const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
105 0xee7fbfffffffeaaa,
106 0x7aaffffac54ffff,
107 0xd9cc34a83dac3d89,
108 0xd91dd2e13ce144af,
109 0x92c6e9ed90d2eb35,
110 0x680447a8e5ff9a6,
111 ]);
112}
113
114pub const FQ_ONE: Fq = field_new!(Fq, "1");
115pub const FQ_ZERO: Fq = field_new!(Fq, "0");