ark-curves-cherry-picked/bls12_381/src/fields/fr.rs
bls12_381/src/fields/fr.rsRaw
1use ark_ff::{
2 biginteger::{BigInt, 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 = BigInt::new([
18 0xb9b58d8c5f0e466a,
19 0x5b1b4c801819d7ec,
20 0xaf53ae352a31e64,
21 0x5bf3adda19e9b27b,
22 ]);
23}
24impl FpParameters for FrParameters {
25 /// MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513
26 #[rustfmt::skip]
27 const MODULUS: BigInteger = BigInt::new([
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 /// R = 10920338887063814464675503992315976177888879664585288394250266608035967270910
41 #[rustfmt::skip]
42 const R: BigInteger = BigInt::new([
43 0x1fffffffe,
44 0x5884b7fa00034802,
45 0x998c4fefecbc4ff5,
46 0x1824b159acc5056f,
47 ]);
48
49 #[rustfmt::skip]
50 const R2: BigInteger = BigInt::new([
51 0xc999e990f3f29c6d,
52 0x2b6cedcb87925c23,
53 0x5d314967254398f,
54 0x748d9d99f59ff11,
55 ]);
56
57 const INV: u64 = 0xfffffffeffffffff;
58
59 /// GENERATOR = 7
60 /// Encoded in Montgomery form, so the value here is
61 /// 7 * R % q = 24006497034320510773280787438025867407531605151569380937148207556313189711857
62 #[rustfmt::skip]
63 const GENERATOR: BigInteger = BigInt::new([
64 0xefffffff1,
65 0x17e363d300189c0f,
66 0xff9c57876f8457b0,
67 0x351332208fc5a8c4,
68 ]);
69
70 #[rustfmt::skip]
71 const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
72 0x7fffffff80000000,
73 0xa9ded2017fff2dff,
74 0x199cec0404d0ec02,
75 0x39f6d3a994cebea4,
76 ]);
77
78 // T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
79 // For T coprime to 2
80
81 // T = (MODULUS - 1) / 2^S =
82 // 12208678567578594777604504606729831043093128246378069236549469339647
83 #[rustfmt::skip]
84 const T: BigInteger = BigInt::new([
85 0xfffe5bfeffffffff,
86 0x9a1d80553bda402,
87 0x299d7d483339d808,
88 0x73eda753,
89 ]);
90
91 // (T - 1) / 2 =
92 // 6104339283789297388802252303364915521546564123189034618274734669823
93 #[rustfmt::skip]
94 const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
95 0x7fff2dff7fffffff,
96 0x4d0ec02a9ded201,
97 0x94cebea4199cec04,
98 0x39f6d3a9,
99 ]);
100}