arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/pallas/src/fields/fq.rs
pallas/src/fields/fq.rsRaw
 1use ark_ff::{
 2    biginteger::BigInteger256 as BigInteger,
 3    fields::{FftParameters, Fp256, Fp256Parameters},
 4};
 5
 6pub type Fq = Fp256<FqParameters>;
 7
 8pub struct FqParameters;
 9
10impl Fp256Parameters for FqParameters {}
11impl FftParameters for FqParameters {
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 p.
18    const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInteger([
19        0xa28db849bad6dbf0,
20        0x9083cd03d3b539df,
21        0xfba6b9ca9dc8448e,
22        0x3ec928747b89c6da,
23    ]);
24}
25
26impl ark_ff::fields::FpParameters for FqParameters {
27    // 28948022309329048855892746252171976963363056481941560715954676764349967630337
28    const MODULUS: BigInteger = BigInteger([
29        0x992d30ed00000001,
30        0x224698fc094cf91b,
31        0x0000000000000000,
32        0x4000000000000000,
33    ]);
34
35    // R = 2^256 mod p
36    const R: BigInteger = BigInteger([
37        0x34786d38fffffffd,
38        0x992c350be41914ad,
39        0xffffffffffffffff,
40        0x3fffffffffffffff,
41    ]);
42
43    // R2 = (2^256)^2 mod p
44    const R2: BigInteger = BigInteger([
45        0x8c78ecb30000000f,
46        0xd7d30dbd8b0de0e7,
47        0x7797a99bc3c95d18,
48        0x096d41af7b9cb714,
49    ]);
50
51    const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
52        0xcc96987680000000,
53        0x11234c7e04a67c8d,
54        0x0000000000000000,
55        0x2000000000000000,
56    ]);
57
58    // T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
59    const T: BigInteger = BigInteger([
60        0x094cf91b992d30ed,
61        0x00000000224698fc,
62        0x0000000000000000,
63        0x0000000040000000,
64    ]);
65
66    const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
67        0x04a67c8dcc969876,
68        0x0000000011234c7e,
69        0x0000000000000000,
70        0x0000000020000000,
71    ]);
72
73    // GENERATOR = 5
74    // Encoded in Montgomery form, so the value here is 5R mod p.
75    const GENERATOR: BigInteger = BigInteger([
76        0xa1a55e68ffffffed,
77        0x74c2a54b4f4982f3,
78        0xfffffffffffffffd,
79        0x3fffffffffffffff,
80    ]);
81
82    const MODULUS_BITS: u32 = 255;
83
84    const CAPACITY: u32 = Self::MODULUS_BITS - 1;
85
86    const REPR_SHAVE_BITS: u32 = 1;
87
88    // INV = -p^{-1} (mod 2^64)
89    const INV: u64 = 11037532056220336127;
90}