mina_curves/pasta/fields/
fq.rs

1use super::fft::{FftParameters, Fp256Parameters, FpParameters};
2use ark_ff::{biginteger::BigInteger256 as BigInteger, Fp256};
3
4pub struct FqParameters;
5
6use ark_ff::fields::{MontBackend, MontConfig};
7
8#[derive(MontConfig)]
9#[modulus = "28948022309329048855892746252171976963363056481941647379679742748393362948097"]
10#[generator = "5"]
11pub struct FrConfig;
12pub type Fq = Fp256<MontBackend<FrConfig, 4>>;
13
14impl Fp256Parameters for FqParameters {}
15
16impl FftParameters for FqParameters {
17    type BigInt = BigInteger;
18
19    const TWO_ADICITY: u32 = 32;
20
21    #[rustfmt::skip]
22    const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInteger::new([
23        0x218077428c9942de, 0xcc49578921b60494, 0xac2e5d27b2efbee2, 0xb79fa897f2db056
24    ]);
25}
26
27impl FpParameters for FqParameters {
28    // 28948022309329048855892746252171976963363056481941647379679742748393362948097
29    const MODULUS: BigInteger = BigInteger::new([
30        0x8c46eb2100000001,
31        0x224698fc0994a8dd,
32        0x0,
33        0x4000000000000000,
34    ]);
35
36    const R: BigInteger = BigInteger::new([
37        0x5b2b3e9cfffffffd,
38        0x992c350be3420567,
39        0xffffffffffffffff,
40        0x3fffffffffffffff,
41    ]);
42
43    const R2: BigInteger = BigInteger::new([
44        0xfc9678ff0000000f,
45        0x67bb433d891a16e3,
46        0x7fae231004ccf590,
47        0x96d41af7ccfdaa9,
48    ]);
49
50    const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger::new([
51        0xc623759080000000,
52        0x11234c7e04ca546e,
53        0x0,
54        0x2000000000000000,
55    ]);
56
57    // T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
58
59    const T: BigInteger = BigInteger::new([0x994a8dd8c46eb21, 0x224698fc, 0x0, 0x40000000]);
60
61    const T_MINUS_ONE_DIV_TWO: BigInteger =
62        BigInteger::new([0x4ca546ec6237590, 0x11234c7e, 0x0, 0x20000000]);
63
64    // GENERATOR = 5
65    const GENERATOR: BigInteger = BigInteger::new([
66        0x96bc8c8cffffffed,
67        0x74c2a54b49f7778e,
68        0xfffffffffffffffd,
69        0x3fffffffffffffff,
70    ]);
71
72    const MODULUS_BITS: u32 = 255;
73
74    const CAPACITY: u32 = Self::MODULUS_BITS - 1;
75
76    const REPR_SHAVE_BITS: u32 = 1;
77
78    // -(MODULUS^{-1} mod 2^64) mod 2^64
79    const INV: u64 = 10108024940646105087;
80}