mina_curves/pasta/fields/
mod.rs

1use ark_ff::Field;
2pub mod fp;
3pub use self::fp::*;
4
5pub mod fq;
6pub use self::fq::*;
7
8pub mod fft;
9
10#[derive(Debug, PartialEq)]
11pub enum LegendreSymbol {
12    Zero = 0,
13    QuadraticResidue = 1,
14    QuadraticNonResidue = -1,
15}
16
17impl LegendreSymbol {
18    pub fn is_zero(&self) -> bool {
19        *self == LegendreSymbol::Zero
20    }
21
22    pub fn is_qnr(&self) -> bool {
23        *self == LegendreSymbol::QuadraticNonResidue
24    }
25
26    pub fn is_qr(&self) -> bool {
27        *self == LegendreSymbol::QuadraticResidue
28    }
29}
30
31/// The interface for a field that supports an efficient square-root operation.
32pub trait SquareRootField: Field {
33    /// Returns a `LegendreSymbol`, which indicates whether this field element is
34    ///  1 : a quadratic residue
35    ///  0 : equal to 0
36    /// -1 : a quadratic non-residue
37    fn legendre(&self) -> LegendreSymbol;
38
39    /// Returns the square root of self, if it exists.
40    #[must_use]
41    fn sqrt(&self) -> Option<Self>;
42
43    /// Sets `self` to be the square root of `self`, if it exists.
44    fn sqrt_in_place(&mut self) -> Option<&mut Self>;
45}