airbender_crypto/bn254/fields/
fq6.rs1use super::{Fq, Fq2, Fq2Config};
2#[cfg(any(
3 all(target_arch = "riscv32", feature = "bigint_ops"),
4 test,
5 feature = "proving"
6))]
7use crate::ark_ff_delegation::MontFp;
8#[cfg(not(any(
9 all(target_arch = "riscv32", feature = "bigint_ops"),
10 test,
11 feature = "proving"
12)))]
13use ark_ff::MontFp;
14use ark_ff::{AdditiveGroup, Field, Fp2Config, Fp6, Fp6Config};
15
16pub type Fq6 = Fp6<Fq6Config>;
17
18#[derive(Clone, Copy)]
19pub struct Fq6Config;
20
21impl Fp6Config for Fq6Config {
22 type Fp2Config = Fq2Config;
23
24 const NONRESIDUE: Fq2 = Fq2::new(MontFp!("9"), Fq::ONE);
26
27 const FROBENIUS_COEFF_FP6_C1: &'static [Fq2] = &[
28 Fq2::new(Fq::ONE, Fq::ZERO),
30 Fq2::new(
32 MontFp!(
33 "21575463638280843010398324269430826099269044274347216827212613867836435027261"
34 ),
35 MontFp!(
36 "10307601595873709700152284273816112264069230130616436755625194854815875713954"
37 ),
38 ),
39 Fq2::new(
41 MontFp!(
42 "21888242871839275220042445260109153167277707414472061641714758635765020556616"
43 ),
44 Fq::ZERO,
45 ),
46 Fq2::new(
48 MontFp!("3772000881919853776433695186713858239009073593817195771773381919316419345261"),
49 MontFp!("2236595495967245188281701248203181795121068902605861227855261137820944008926"),
50 ),
51 Fq2::new(
53 MontFp!("2203960485148121921418603742825762020974279258880205651966"),
54 Fq::ZERO,
55 ),
56 Fq2::new(
58 MontFp!(
59 "18429021223477853657660792034369865839114504446431234726392080002137598044644"
60 ),
61 MontFp!("9344045779998320333812420223237981029506012124075525679208581902008406485703"),
62 ),
63 ];
64
65 const FROBENIUS_COEFF_FP6_C2: &'static [Fq2] = &[
66 Fq2::new(Fq::ONE, Fq::ZERO),
68 Fq2::new(
70 MontFp!("2581911344467009335267311115468803099551665605076196740867805258568234346338"),
71 MontFp!(
72 "19937756971775647987995932169929341994314640652964949448313374472400716661030"
73 ),
74 ),
75 Fq2::new(
77 MontFp!("2203960485148121921418603742825762020974279258880205651966"),
78 Fq::ZERO,
79 ),
80 Fq2::new(
82 MontFp!("5324479202449903542726783395506214481928257762400643279780343368557297135718"),
83 MontFp!(
84 "16208900380737693084919495127334387981393726419856888799917914180988844123039"
85 ),
86 ),
87 Fq2::new(
89 MontFp!(
90 "21888242871839275220042445260109153167277707414472061641714758635765020556616"
91 ),
92 Fq::ZERO,
93 ),
94 Fq2::new(
96 MontFp!(
97 "13981852324922362344252311234282257507216387789820983642040889267519694726527"
98 ),
99 MontFp!("7629828391165209371577384193250820201684255241773809077146787135900891633097"),
100 ),
101 ];
102
103 #[inline(always)]
104 fn mul_fp2_by_nonresidue_in_place(fe: &mut Fq2) -> &mut Fq2 {
105 let mut f = *fe;
107 f.double_in_place().double_in_place().double_in_place();
108 let mut c0 = fe.c1;
109 Fq2Config::mul_fp_by_nonresidue_in_place(&mut c0);
110 c0 += &f.c0;
111 c0 += &fe.c0;
112 let c1 = f.c1 + fe.c1 + fe.c0;
113 *fe = Fq2::new(c0, c1);
114 fe
115 }
116}