arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/bls12_381/src/fields/fq.rs
bls12_381/src/fields/fq.rsRaw
  1use ark_ff::{
  2    biginteger::BigInteger384 as BigInteger,
  3    field_new,
  4    fields::{FftParameters, Fp384, Fp384Parameters, FpParameters},
  5};
  6
  7pub type Fq = Fp384<FqParameters>;
  8
  9pub struct FqParameters;
 10
 11impl Fp384Parameters for FqParameters {}
 12impl FftParameters for FqParameters {
 13    type BigInt = BigInteger;
 14
 15    const TWO_ADICITY: u32 = 1;
 16
 17    #[rustfmt::skip]
 18    const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInteger([
 19        0x43f5fffffffcaaae,
 20        0x32b7fff2ed47fffd,
 21        0x7e83a49a2e99d69,
 22        0xeca8f3318332bb7a,
 23        0xef148d1ea0f4c069,
 24        0x40ab3263eff0206,
 25    ]);
 26}
 27impl FpParameters for FqParameters {
 28    /// MODULUS = 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787
 29    #[rustfmt::skip]
 30    const MODULUS: BigInteger = BigInteger([
 31        0xb9feffffffffaaab,
 32        0x1eabfffeb153ffff,
 33        0x6730d2a0f6b0f624,
 34        0x64774b84f38512bf,
 35        0x4b1ba7b6434bacd7,
 36        0x1a0111ea397fe69a,
 37    ]);
 38
 39    const MODULUS_BITS: u32 = 381;
 40
 41    const CAPACITY: u32 = Self::MODULUS_BITS - 1;
 42
 43    const REPR_SHAVE_BITS: u32 = 3;
 44
 45    #[rustfmt::skip]
 46    const R: BigInteger = BigInteger([
 47        0x760900000002fffd,
 48        0xebf4000bc40c0002,
 49        0x5f48985753c758ba,
 50        0x77ce585370525745,
 51        0x5c071a97a256ec6d,
 52        0x15f65ec3fa80e493,
 53    ]);
 54
 55    #[rustfmt::skip]
 56    const R2: BigInteger = BigInteger([
 57        0xf4df1f341c341746,
 58        0xa76e6a609d104f1,
 59        0x8de5476c4c95b6d5,
 60        0x67eb88a9939d83c0,
 61        0x9a793e85b519952d,
 62        0x11988fe592cae3aa,
 63    ]);
 64
 65    const INV: u64 = 0x89f3fffcfffcfffd;
 66
 67    // GENERATOR = 2
 68    #[rustfmt::skip]
 69    const GENERATOR: BigInteger = BigInteger([
 70        0x321300000006554f,
 71        0xb93c0018d6c40005,
 72        0x57605e0db0ddbb51,
 73        0x8b256521ed1f9bcb,
 74        0x6cf28d7901622c03,
 75        0x11ebab9dbb81e28c,
 76    ]);
 77
 78    #[rustfmt::skip]
 79    const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
 80        0xdcff7fffffffd555,
 81        0xf55ffff58a9ffff,
 82        0xb39869507b587b12,
 83        0xb23ba5c279c2895f,
 84        0x258dd3db21a5d66b,
 85        0xd0088f51cbff34d,
 86    ]);
 87
 88    // T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
 89
 90    #[rustfmt::skip]
 91    const T: BigInteger = BigInteger([
 92        0xdcff7fffffffd555,
 93        0xf55ffff58a9ffff,
 94        0xb39869507b587b12,
 95        0xb23ba5c279c2895f,
 96        0x258dd3db21a5d66b,
 97        0xd0088f51cbff34d,
 98    ]);
 99
100    #[rustfmt::skip]
101    const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
102        0xee7fbfffffffeaaa,
103        0x7aaffffac54ffff,
104        0xd9cc34a83dac3d89,
105        0xd91dd2e13ce144af,
106        0x92c6e9ed90d2eb35,
107        0x680447a8e5ff9a6,
108    ]);
109}
110
111pub const FQ_ONE: Fq = field_new!(Fq, FqParameters::R);
112pub const FQ_ZERO: Fq = field_new!(Fq, BigInteger([0, 0, 0, 0, 0, 0]));