arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/ed_on_mnt4_298/src/fields/fr.rs
ed_on_mnt4_298/src/fields/fr.rsRaw
  1use ark_ff::{
  2    biginteger::{BigInt, BigInteger320 as BigInteger},
  3    fields::{FftParameters, Fp320, Fp320Parameters, FpParameters},
  4};
  5
  6pub type Fr = Fp320<FrParameters>;
  7
  8pub struct FrParameters;
  9
 10impl Fp320Parameters for FrParameters {}
 11impl FftParameters for FrParameters {
 12    type BigInt = BigInteger;
 13
 14    const TWO_ADICITY: u32 = 1u32;
 15
 16    // ROOT_OF_UNITY = GENERATOR ^ t =
 17    // 118980571542315331438337312413262112886281219744507561120271964887686106682370032123932630
 18    // t is defined below
 19    // This number needs to be in the Montgomery residue form.
 20    // I.e., write
 21    // 118980571542315331438337312413262112886281219744507561120271964887686106682370032123932630
 22    // * R
 23    // = 14596494758349247937872919467301196219547084259323651055171406111196152579418790325693086
 24    #[rustfmt::skip]
 25    const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
 26        4913018085921565342u64,
 27        18164325898792356216u64,
 28        11499902056485864693u64,
 29        12113224729248979119u64,
 30        126057789046u64,
 31    ]);
 32}
 33impl FpParameters for FrParameters {
 34    // MODULUS = 118980571542315331438337312413262112886281219744507561120271964887686106682370032123932631
 35    // Factors of MODULUS - 1:
 36    //      2
 37    //      5
 38    //      17
 39    //      47
 40    //      3645289
 41    //      42373926857
 42    //      96404785755712297250936212793128201320333033128042968811755970858369
 43    #[rustfmt::skip]
 44    const MODULUS: BigInteger = BigInt::new([
 45        15535567651727634391u64,
 46        14992835038329117496u64,
 47        12879083654034347181u64,
 48        16760578290609820963u64,
 49        1027536270620u64,
 50    ]);
 51
 52    const MODULUS_BITS: u32 = 296;
 53
 54    const CAPACITY: u32 = Self::MODULUS_BITS - 1;
 55
 56    const REPR_SHAVE_BITS: u32 = 24;
 57
 58    // see ark-ff/src/fields/mod.rs for more information
 59    // R = pow(2,320) %
 60    // 118980571542315331438337312413262112886281219744507561120271964887686106682370032123932631
 61    // R = 104384076783966083500464392945960916666734135485183910065100558776489954102951241798239545
 62    #[rustfmt::skip]
 63    const R: BigInteger = BigInt::new([
 64        10622549565806069049u64,
 65        15275253213246312896u64,
 66        1379181597548482487u64,
 67        4647353561360841844u64,
 68        901478481574u64
 69    ]);
 70
 71    // R2 = R * R %
 72    // 118980571542315331438337312413262112886281219744507561120271964887686106682370032123932631
 73    // R2 = 64940318866745953005690402896764745514897573584912026577721076893188083397226247459368768
 74    #[rustfmt::skip]
 75    const R2: BigInteger = BigInt::new([
 76        16858329796171722560u64,
 77        12060416575249219689u64,
 78        17034911964548502611u64,
 79        14718631438675169669u64,
 80        560835539754u64
 81    ]);
 82
 83    // INV = -(118980571542315331438337312413262112886281219744507561120271964887686106682370032123932631)^(-1) % 2^64
 84    const INV: u64 = 9223688842165816345u64;
 85
 86    // GENERATOR = 7
 87    // This number needs to be in the Montgomery residue form.
 88    // I.e., write 7 * R =
 89    // 16805108233870595873226876142153739349451629929242003734072122109313038626438499844081029
 90    #[rustfmt::skip]
 91    const GENERATOR: BigInteger = BigInt::new([
 92        18037929197695780229u64,
 93        16969762262749485294u64,
 94        6166745553471500787u64,
 95        5754981480705173590u64,
 96        145131747294u64,
 97    ]);
 98
 99    // (n-1)/2 = 59490285771157665719168656206631056443140609872253780560135982443843053341185016061966315
100    #[rustfmt::skip]
101    const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
102        7767783825863817195u64,
103        16719789556019334556u64,
104        15662913863871949398u64,
105        8380289145304910481u64,
106        513768135310u64,
107    ]);
108
109    // t = (n - 1) / 2^{TWO_ADICITY} =
110    // 59490285771157665719168656206631056443140609872253780560135982443843053341185016061966315
111    const T: BigInteger = BigInt::new([
112        7767783825863817195u64,
113        16719789556019334556u64,
114        15662913863871949398u64,
115        8380289145304910481u64,
116        513768135310u64,
117    ]);
118
119    // (t-1)/2 = 29745142885578832859584328103315528221570304936126890280067991221921526670592508030983157
120    const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
121        3883891912931908597u64,
122        8359894778009667278u64,
123        17054828968790750507u64,
124        4190144572652455240u64,
125        256884067655u64,
126    ]);
127}