mina_curves/pasta/fields/
fp.rs

1use super::fft::{FftParameters, Fp256Parameters};
2use ark_ff::{
3    biginteger::BigInteger256 as BigInteger,
4    fields::{MontBackend, MontConfig},
5    Fp256,
6};
7
8#[derive(MontConfig)]
9#[modulus = "28948022309329048855892746252171976963363056481941560715954676764349967630337"]
10#[generator = "5"]
11pub struct FqConfig;
12pub type Fp = Fp256<MontBackend<FqConfig, 4>>;
13
14pub struct FpParameters;
15
16impl Fp256Parameters for FpParameters {}
17
18impl FftParameters for FpParameters {
19    type BigInt = BigInteger;
20
21    const TWO_ADICITY: u32 = 32;
22
23    #[rustfmt::skip]
24    const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInteger::new([
25        0xa28db849bad6dbf0, 0x9083cd03d3b539df, 0xfba6b9ca9dc8448e, 0x3ec928747b89c6da
26    ]);
27}
28
29impl super::fft::FpParameters for FpParameters {
30    // 28948022309329048855892746252171976963363056481941560715954676764349967630337
31    const MODULUS: BigInteger = BigInteger::new([
32        0x992d30ed00000001,
33        0x224698fc094cf91b,
34        0x0,
35        0x4000000000000000,
36    ]);
37
38    const R: BigInteger = BigInteger::new([
39        0x34786d38fffffffd,
40        0x992c350be41914ad,
41        0xffffffffffffffff,
42        0x3fffffffffffffff,
43    ]);
44
45    const R2: BigInteger = BigInteger::new([
46        0x8c78ecb30000000f,
47        0xd7d30dbd8b0de0e7,
48        0x7797a99bc3c95d18,
49        0x96d41af7b9cb714,
50    ]);
51
52    const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger::new([
53        0xcc96987680000000,
54        0x11234c7e04a67c8d,
55        0x0,
56        0x2000000000000000,
57    ]);
58
59    // T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
60    const T: BigInteger = BigInteger::new([0x94cf91b992d30ed, 0x224698fc, 0x0, 0x40000000]);
61
62    const T_MINUS_ONE_DIV_TWO: BigInteger =
63        BigInteger::new([0x4a67c8dcc969876, 0x11234c7e, 0x0, 0x20000000]);
64
65    // GENERATOR = 5
66    const GENERATOR: BigInteger = BigInteger::new([
67        0xa1a55e68ffffffed,
68        0x74c2a54b4f4982f3,
69        0xfffffffffffffffd,
70        0x3fffffffffffffff,
71    ]);
72
73    const MODULUS_BITS: u32 = 255;
74
75    const CAPACITY: u32 = Self::MODULUS_BITS - 1;
76
77    const REPR_SHAVE_BITS: u32 = 1;
78
79    // -(MODULUS^{-1} mod 2^64) mod 2^64
80    const INV: u64 = 11037532056220336127;
81}