arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/pallas/src/fields/fr.rs
pallas/src/fields/fr.rsRaw
 1use ark_ff::{
 2    biginteger::{BigInt, BigInteger256 as BigInteger},
 3    fields::{FftParameters, Fp256, Fp256Parameters, FpParameters},
 4};
 5
 6pub struct FrParameters;
 7
 8pub type Fr = Fp256<FrParameters>;
 9
10impl Fp256Parameters for FrParameters {}
11impl FftParameters for FrParameters {
12    type BigInt = BigInteger;
13
14    const TWO_ADICITY: u32 = 32;
15
16    // TWO_ADIC_ROOT_OF_UNITY = GENERATOR^T
17    // Encoded in Montgomery form, so the value here is (5^T)R mod q.
18    const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
19        0x218077428c9942de,
20        0xcc49578921b60494,
21        0xac2e5d27b2efbee2,
22        0x0b79fa897f2db056,
23    ]);
24}
25
26impl FpParameters for FrParameters {
27    // 28948022309329048855892746252171976963363056481941647379679742748393362948097
28    const MODULUS: BigInteger = BigInt::new([
29        0x8c46eb2100000001,
30        0x224698fc0994a8dd,
31        0x0000000000000000,
32        0x4000000000000000,
33    ]);
34
35    // R = 2^256 mod q
36    const R: BigInteger = BigInt::new([
37        0x5b2b3e9cfffffffd,
38        0x992c350be3420567,
39        0xffffffffffffffff,
40        0x3fffffffffffffff,
41    ]);
42
43    // R2 = (2^256)^2 mod q
44    const R2: BigInteger = BigInt::new([
45        0xfc9678ff0000000f,
46        0x67bb433d891a16e3,
47        0x7fae231004ccf590,
48        0x096d41af7ccfdaa9,
49    ]);
50
51    const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
52        0xc623759080000000,
53        0x11234c7e04ca546e,
54        0x0000000000000000,
55        0x2000000000000000,
56    ]);
57
58    // T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
59
60    const T: BigInteger = BigInt::new([
61        0x0994a8dd8c46eb21,
62        0x00000000224698fc,
63        0x0000000000000000,
64        0x0000000040000000,
65    ]);
66
67    const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
68        0x04ca546ec6237590,
69        0x0000000011234c7e,
70        0x0000000000000000,
71        0x0000000020000000,
72    ]);
73
74    // GENERATOR = 5
75    // Encoded in Montgomery form, so the value here is 5R mod q.
76    const GENERATOR: BigInteger = BigInt::new([
77        0x96bc8c8cffffffed,
78        0x74c2a54b49f7778e,
79        0xfffffffffffffffd,
80        0x3fffffffffffffff,
81    ]);
82
83    const MODULUS_BITS: u32 = 255;
84
85    const CAPACITY: u32 = Self::MODULUS_BITS - 1;
86
87    const REPR_SHAVE_BITS: u32 = 1;
88
89    // INV = -q^{-1} (mod 2^64)
90    const INV: u64 = 10108024940646105087;
91}