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