Skip to main content

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