arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/ed_on_bls12_381_bandersnatch/src/fields/fr.rs
ed_on_bls12_381_bandersnatch/src/fields/fr.rsRaw
  1use ark_ff::{
  2    biginteger::{BigInt, BigInteger256 as BigInteger},
  3    fields::{FftParameters, Fp256, Fp256Parameters, FpParameters},
  4};
  5
  6pub type Fr = Fp256<FrParameters>;
  7
  8pub struct FrParameters;
  9
 10impl Fp256Parameters for FrParameters {}
 11impl FftParameters for FrParameters {
 12    type BigInt = BigInteger;
 13
 14    /// Let `N` be the size of the multiplicative group defined by the field.
 15    /// Then `TWO_ADICITY` is the two-adicity of `N`, i.e. the integer `s`
 16    /// such that `N = 2^s * t` for some odd integer `t`.
 17    const TWO_ADICITY: u32 = 5;
 18
 19    /// 2^s root of unity computed by GENERATOR^t
 20    /// 4740934665446857387895054948191089665295030226009829406950782728666658007874
 21    #[rustfmt::skip]
 22    const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
 23        0xa4dcdba087826b42,
 24        0x6e4ab162f57f862a,
 25        0xabc5492749348d6a,
 26        0xa7b462035f8c169,
 27    ]);
 28}
 29impl FpParameters for FrParameters {
 30    /// The modulus of the field.
 31    /// MODULUS = 13108968793781547619861935127046491459309155893440570251786403306729687672801.
 32    #[rustfmt::skip]
 33    const MODULUS: BigInteger = BigInt::new([
 34        0x74fd06b52876e7e1,
 35        0xff8f870074190471,
 36        0x0cce760202687600,
 37        0x1cfb69d4ca675f52,
 38    ]);
 39
 40    /// The number of bits needed to represent the `Self::MODULUS`.
 41    const MODULUS_BITS: u32 = 253;
 42
 43    /// The number of bits that can be reliably stored.
 44    /// (Should equal `SELF::MODULUS_BITS - 1`)
 45    const CAPACITY: u32 = Self::MODULUS_BITS - 1;
 46
 47    /// The number of bits that must be shaved from the beginning of
 48    /// the representation when randomly sampling.
 49    const REPR_SHAVE_BITS: u32 = 4;
 50
 51    /// Let `M` be the power of 2^64 nearest to `Self::MODULUS_BITS`. Then
 52    /// `R = M % Self::MODULUS`.
 53    /// R = 10920338887063814464675503992315976178796737518116002025166357554075628257528
 54    #[rustfmt::skip]
 55    const R: BigInteger = BigInt::new([
 56        0x5817ca56bc48c0f8,
 57        0x0383c7fc5f37dc74,
 58        0x998c4fefecbc4ff8,
 59        0x1824b159acc5056f,
 60    ]);
 61
 62    /// R2 = R^2 % Self::MODULUS
 63    /// R2 = 4932290691328759802879919559207542894238895193980447506221046538067943049163
 64    #[rustfmt::skip]
 65    const R2: BigInteger = BigInt::new([
 66        0xdbb4f5d658db47cb,
 67        0x40fa7ca27fecb938,
 68        0xaa9e6daec0055cea,
 69        0xae793ddb14aec7d
 70    ]);
 71
 72    /// INV = -MODULUS^{-1} mod 2^64
 73    /// INV = 17410672245482742751
 74    const INV: u64 = 0xf19f22295cc063df;
 75
 76    /// A multiplicative generator of the field.
 77    /// `Self::GENERATOR` is an element having multiplicative order
 78    /// `Self::MODULUS - 1`.
 79    /// n = 9962557815892774795293348142308860067333132192265356416788884706064406244838
 80    #[rustfmt::skip]
 81    const GENERATOR: BigInteger = BigInt::new([
 82        0x56b6f3ab7b616de6,
 83        0x114f419d6c9083e5,
 84        0xbf518d217780c4b9,
 85        0x16069b9f45dbce7f,
 86    ]);
 87
 88    /// (Self::MODULUS - 1) / 2
 89    /// 6554484396890773809930967563523245729654577946720285125893201653364843836400
 90    const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
 91        0xba7e835a943b73f0,
 92        0x7fc7c3803a0c8238,
 93        0x06673b0101343b00,
 94        0xe7db4ea6533afa9,
 95    ]);
 96
 97    /// t for 2^s * t = MODULUS - 1, and t coprime to 2.
 98    /// t = 409655274805673363120685472720202858103411121670017820368325103335302739775
 99    ///   = (modulus-1)/2^5
100    const T: BigInteger = BigInt::new([
101        0x8ba7e835a943b73f,
102        0x07fc7c3803a0c823,
103        0x906673b0101343b0,
104        0xe7db4ea6533afa,
105    ]);
106
107    /// (t - 1) / 2
108    ///  = 204827637402836681560342736360101429051705560835008910184162551667651369887
109    const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
110        0xc5d3f41ad4a1db9f,
111        0x03fe3e1c01d06411,
112        0x483339d80809a1d8,
113        0x73eda753299d7d,
114    ]);
115}