ark-curves-cherry-picked/bls12_381/src/fields/fr.rs
bls12_381/src/fields/fr.rsRaw
1use ark_ff::{
2 biginteger::BigInteger256 as BigInteger,
3 fields::{FftParameters, Fp256, Fp256Parameters, FpParameters},
4};
5
6pub type Fr = Fp256<FrParameters>;
7
8pub struct FrParameters;
9
10impl Fp256Parameters for FrParameters {}
11impl FftParameters for FrParameters {
12 type BigInt = BigInteger;
13
14 const TWO_ADICITY: u32 = 32;
15
16 #[rustfmt::skip]
17 const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInteger([
18 0xb9b58d8c5f0e466a,
19 0x5b1b4c801819d7ec,
20 0xaf53ae352a31e64,
21 0x5bf3adda19e9b27b,
22 ]);
23}
24impl FpParameters for FrParameters {
25 /// MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513
26 #[rustfmt::skip]
27 const MODULUS: BigInteger = BigInteger([
28 0xffffffff00000001,
29 0x53bda402fffe5bfe,
30 0x3339d80809a1d805,
31 0x73eda753299d7d48,
32 ]);
33
34 const MODULUS_BITS: u32 = 255;
35
36 const CAPACITY: u32 = Self::MODULUS_BITS - 1;
37
38 const REPR_SHAVE_BITS: u32 = 1;
39
40 #[rustfmt::skip]
41 const R: BigInteger = BigInteger([
42 0x1fffffffe,
43 0x5884b7fa00034802,
44 0x998c4fefecbc4ff5,
45 0x1824b159acc5056f,
46 ]);
47
48 #[rustfmt::skip]
49 const R2: BigInteger = BigInteger([
50 0xc999e990f3f29c6d,
51 0x2b6cedcb87925c23,
52 0x5d314967254398f,
53 0x748d9d99f59ff11,
54 ]);
55
56 const INV: u64 = 0xfffffffeffffffff;
57
58 //
59 #[rustfmt::skip]
60 const GENERATOR: BigInteger = BigInteger([
61 0xefffffff1,
62 0x17e363d300189c0f,
63 0xff9c57876f8457b0,
64 0x351332208fc5a8c4,
65 ]);
66
67 #[rustfmt::skip]
68 const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
69 0x7fffffff80000000,
70 0xa9ded2017fff2dff,
71 0x199cec0404d0ec02,
72 0x39f6d3a994cebea4,
73 ]);
74
75 // T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
76
77 // T = (MODULUS - 1) / 2^S =
78 // 12208678567578594777604504606729831043093128246378069236549469339647
79 #[rustfmt::skip]
80 const T: BigInteger = BigInteger([
81 0xfffe5bfeffffffff,
82 0x9a1d80553bda402,
83 0x299d7d483339d808,
84 0x73eda753,
85 ]);
86
87 // (T - 1) / 2 =
88 // 6104339283789297388802252303364915521546564123189034618274734669823
89 #[rustfmt::skip]
90 const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
91 0x7fff2dff7fffffff,
92 0x4d0ec02a9ded201,
93 0x94cebea4199cec04,
94 0x39f6d3a9,
95 ]);
96}