arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/bls12_381/src/fields/fq6.rs
bls12_381/src/fields/fq6.rsRaw
  1use crate::*;
  2use ark_ff::{biginteger::BigInteger384, field_new, fields::*};
  3
  4pub type Fq6 = Fp6<Fq6Parameters>;
  5
  6#[derive(Clone, Copy)]
  7pub struct Fq6Parameters;
  8
  9impl Fp6Parameters for Fq6Parameters {
 10    type Fp2Params = Fq2Parameters;
 11
 12    /// NONRESIDUE = (U + 1)
 13    #[rustfmt::skip]
 14    const NONRESIDUE: Fq2 = field_new!(Fq2,
 15        field_new!(Fq, BigInteger384([
 16            0x760900000002fffd,
 17            0xebf4000bc40c0002,
 18            0x5f48985753c758ba,
 19            0x77ce585370525745,
 20            0x5c071a97a256ec6d,
 21            0x15f65ec3fa80e493,
 22        ])),
 23        field_new!(Fq, BigInteger384([
 24            0x760900000002fffd,
 25            0xebf4000bc40c0002,
 26            0x5f48985753c758ba,
 27            0x77ce585370525745,
 28            0x5c071a97a256ec6d,
 29            0x15f65ec3fa80e493,
 30        ])),
 31    );
 32
 33    #[rustfmt::skip]
 34    const FROBENIUS_COEFF_FP6_C1: &'static [Fq2] = &[
 35        // Fq2(u + 1)**(((q^0) - 1) / 3)
 36        field_new!(Fq2,
 37            field_new!(Fq, BigInteger384([
 38                0x760900000002fffd,
 39                0xebf4000bc40c0002,
 40                0x5f48985753c758ba,
 41                0x77ce585370525745,
 42                0x5c071a97a256ec6d,
 43                0x15f65ec3fa80e493,
 44            ])),
 45            field_new!(Fq, BigInteger384([0x0, 0x0, 0x0, 0x0, 0x0, 0x0])),
 46        ),
 47        // Fq2(u + 1)**(((q^1) - 1) / 3)
 48        field_new!(Fq2,
 49            field_new!(Fq, BigInteger384([0x0, 0x0, 0x0, 0x0, 0x0, 0x0])),
 50            field_new!(Fq, BigInteger384([
 51                0xcd03c9e48671f071,
 52                0x5dab22461fcda5d2,
 53                0x587042afd3851b95,
 54                0x8eb60ebe01bacb9e,
 55                0x3f97d6e83d050d2,
 56                0x18f0206554638741,
 57            ])),
 58        ),
 59        // Fq2(u + 1)**(((q^2) - 1) / 3)
 60        field_new!(Fq2,
 61            field_new!(Fq, BigInteger384([
 62                0x30f1361b798a64e8,
 63                0xf3b8ddab7ece5a2a,
 64                0x16a8ca3ac61577f7,
 65                0xc26a2ff874fd029b,
 66                0x3636b76660701c6e,
 67                0x51ba4ab241b6160,
 68            ])),
 69            field_new!(Fq, BigInteger384([0x0, 0x0, 0x0, 0x0, 0x0, 0x0])),
 70        ),
 71        // Fq2(u + 1)**(((q^3) - 1) / 3)
 72        field_new!(Fq2,
 73            field_new!(Fq, BigInteger384([0x0, 0x0, 0x0, 0x0, 0x0, 0x0])),
 74            field_new!(Fq, BigInteger384([
 75                0x760900000002fffd,
 76                0xebf4000bc40c0002,
 77                0x5f48985753c758ba,
 78                0x77ce585370525745,
 79                0x5c071a97a256ec6d,
 80                0x15f65ec3fa80e493,
 81            ])),
 82        ),
 83        // Fq2(u + 1)**(((q^4) - 1) / 3)
 84        field_new!(Fq2,
 85            field_new!(Fq, BigInteger384([
 86                0xcd03c9e48671f071,
 87                0x5dab22461fcda5d2,
 88                0x587042afd3851b95,
 89                0x8eb60ebe01bacb9e,
 90                0x3f97d6e83d050d2,
 91                0x18f0206554638741,
 92            ])),
 93            field_new!(Fq, BigInteger384([0x0, 0x0, 0x0, 0x0, 0x0, 0x0])),
 94        ),
 95        // Fq2(u + 1)**(((q^5) - 1) / 3)
 96        field_new!(Fq2,
 97            field_new!(Fq, BigInteger384([0x0, 0x0, 0x0, 0x0, 0x0, 0x0])),
 98            field_new!(Fq, BigInteger384([
 99                0x30f1361b798a64e8,
100                0xf3b8ddab7ece5a2a,
101                0x16a8ca3ac61577f7,
102                0xc26a2ff874fd029b,
103                0x3636b76660701c6e,
104                0x51ba4ab241b6160,
105            ])),
106        ),
107    ];
108
109    #[rustfmt::skip]
110    const FROBENIUS_COEFF_FP6_C2: &'static [Fq2] = &[
111        // Fq2(u + 1)**(((2q^0) - 2) / 3)
112        field_new!(Fq2,
113            field_new!(Fq, BigInteger384([
114                0x760900000002fffd,
115                0xebf4000bc40c0002,
116                0x5f48985753c758ba,
117                0x77ce585370525745,
118                0x5c071a97a256ec6d,
119                0x15f65ec3fa80e493,
120            ])),
121            field_new!(Fq, BigInteger384([0x0, 0x0, 0x0, 0x0, 0x0, 0x0])),
122        ),
123        // Fq2(u + 1)**(((2q^1) - 2) / 3)
124        field_new!(Fq2,
125            field_new!(Fq, BigInteger384([
126                0x890dc9e4867545c3,
127                0x2af322533285a5d5,
128                0x50880866309b7e2c,
129                0xa20d1b8c7e881024,
130                0x14e4f04fe2db9068,
131                0x14e56d3f1564853a,
132            ])),
133            field_new!(Fq, BigInteger384([0x0, 0x0, 0x0, 0x0, 0x0, 0x0])),
134        ),
135        // Fq2(u + 1)**(((2q^2) - 2) / 3)
136        field_new!(Fq2,
137            field_new!(Fq, BigInteger384([
138                0xcd03c9e48671f071,
139                0x5dab22461fcda5d2,
140                0x587042afd3851b95,
141                0x8eb60ebe01bacb9e,
142                0x3f97d6e83d050d2,
143                0x18f0206554638741,
144            ])),
145            field_new!(Fq, BigInteger384([0x0, 0x0, 0x0, 0x0, 0x0, 0x0])),
146        ),
147        // Fq2(u + 1)**(((2q^3) - 2) / 3)
148        field_new!(Fq2,
149            field_new!(Fq, BigInteger384([
150                0x43f5fffffffcaaae,
151                0x32b7fff2ed47fffd,
152                0x7e83a49a2e99d69,
153                0xeca8f3318332bb7a,
154                0xef148d1ea0f4c069,
155                0x40ab3263eff0206,
156            ])),
157            field_new!(Fq, BigInteger384([0x0, 0x0, 0x0, 0x0, 0x0, 0x0])),
158        ),
159        // Fq2(u + 1)**(((2q^4) - 2) / 3)
160        field_new!(Fq2,
161            field_new!(Fq, BigInteger384([
162                0x30f1361b798a64e8,
163                0xf3b8ddab7ece5a2a,
164                0x16a8ca3ac61577f7,
165                0xc26a2ff874fd029b,
166                0x3636b76660701c6e,
167                0x51ba4ab241b6160,
168            ])),
169            field_new!(Fq, BigInteger384([0x0, 0x0, 0x0, 0x0, 0x0, 0x0])),
170        ),
171        // Fq2(u + 1)**(((2q^5) - 2) / 3)
172        field_new!(Fq2,
173            field_new!(Fq, BigInteger384([
174                0xecfb361b798dba3a,
175                0xc100ddb891865a2c,
176                0xec08ff1232bda8e,
177                0xd5c13cc6f1ca4721,
178                0x47222a47bf7b5c04,
179                0x110f184e51c5f59,
180            ])),
181            field_new!(Fq, BigInteger384([0x0, 0x0, 0x0, 0x0, 0x0, 0x0])),
182        ),
183    ];
184
185    /// Multiply this element by the quadratic nonresidue 1 + u.
186    /// Make this generic.
187    fn mul_fp2_by_nonresidue(fe: &Fq2) -> Fq2 {
188        let mut copy = *fe;
189        let t0 = copy.c0;
190        copy.c0 -= &fe.c1;
191        copy.c1 += &t0;
192        copy
193    }
194}