halo2curves/ff_ext/
mod.rs

1pub mod cubic;
2pub mod inverse;
3pub mod jacobi;
4pub mod quadratic;
5use subtle::{Choice, ConstantTimeEq};
6
7pub trait Legendre {
8    fn legendre(&self) -> i64;
9
10    #[inline(always)]
11    fn ct_quadratic_non_residue(&self) -> Choice {
12        self.legendre().ct_eq(&-1)
13    }
14
15    #[inline(always)]
16    fn ct_quadratic_residue(&self) -> Choice {
17        // The legendre symbol returns 0 for 0
18        // and 1 for quadratic residues,
19        // we consider 0 a square hence quadratic residue.
20        self.legendre().ct_ne(&-1)
21    }
22}
23
24#[macro_export]
25macro_rules! extend_field_legendre {
26    ($field:ident ) => {
27        impl $crate::ff_ext::Legendre for $field {
28            #[inline(always)]
29            fn legendre(&self) -> i64 {
30                self.jacobi()
31            }
32        }
33    };
34}
35
36pub trait ExtField: ff::Field {
37    const NON_RESIDUE: Self;
38    #[must_use]
39    fn mul_by_nonresidue(&self) -> Self {
40        Self::NON_RESIDUE * self
41    }
42    fn frobenius_map(&mut self, power: usize);
43}