Trait Field

Source
pub trait Field:
    Sized
    + Eq
    + Copy
    + Clone
    + Default
    + Send
    + Sync
    + Debug
    + 'static
    + ConditionallySelectable
    + ConstantTimeEq
    + Add<Output = Self, Output = Self>
    + Sub<Output = Self, Output = Self>
    + Mul<Output = Self, Output = Self>
    + Neg<Output = Self>
    + for<'a> Add<&'a Self>
    + for<'a> Mul<&'a Self>
    + for<'a> Sub<&'a Self>
    + MulAssign
    + AddAssign
    + SubAssign
    + for<'a> MulAssign<&'a Self>
    + for<'a> AddAssign<&'a Self>
    + for<'a> SubAssign<&'a Self> {
    // Required methods
    fn random(rng: impl RngCore) -> Self;
    fn zero() -> Self;
    fn one() -> Self;
    fn square(&self) -> Self;
    fn double(&self) -> Self;
    fn invert(&self) -> CtOption<Self>;
    fn sqrt(&self) -> CtOption<Self>;

    // Provided methods
    fn is_zero(&self) -> Choice { ... }
    fn is_zero_vartime(&self) -> bool { ... }
    fn cube(&self) -> Self { ... }
    fn pow_vartime<S>(&self, exp: S) -> Self
       where S: AsRef<[u64]> { ... }
}
Expand description

This trait represents an element of a field.

Required Methods§

Source

fn random(rng: impl RngCore) -> Self

Returns an element chosen uniformly at random using a user-provided RNG.

Source

fn zero() -> Self

Returns the zero element of the field, the additive identity.

Source

fn one() -> Self

Returns the one element of the field, the multiplicative identity.

Source

fn square(&self) -> Self

Squares this element.

Source

fn double(&self) -> Self

Doubles this element.

Source

fn invert(&self) -> CtOption<Self>

Computes the multiplicative inverse of this element, failing if the element is zero.

Source

fn sqrt(&self) -> CtOption<Self>

Returns the square root of the field element, if it is quadratic residue.

Provided Methods§

Source

fn is_zero(&self) -> Choice

Returns true iff this element is zero.

Source

fn is_zero_vartime(&self) -> bool

Returns true iff this element is zero.

§Security

This method provides no constant-time guarantees. Implementors of the Field trait may optimise this method using non-constant-time logic.

Source

fn cube(&self) -> Self

Cubes this element.

Source

fn pow_vartime<S>(&self, exp: S) -> Self
where S: AsRef<[u64]>,

Exponentiates self by exp, where exp is a little-endian order integer exponent.

This operation is variable time with respect to the exponent. If the exponent is fixed, this operation is effectively constant time.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Field for Fp

Source§

fn sqrt(&self) -> CtOption<Fp>

Computes the square root of this element, if it exists.

Source§

fn invert(&self) -> CtOption<Fp>

Computes the multiplicative inverse of this element, failing if the element is zero.

Source§

fn random(rng: impl RngCore) -> Fp

Source§

fn zero() -> Fp

Source§

fn one() -> Fp

Source§

fn double(&self) -> Fp

Source§

fn square(&self) -> Fp

Source§

fn pow_vartime<S>(&self, exp: S) -> Fp
where S: AsRef<[u64]>,

Source§

impl Field for Fq

Source§

fn sqrt(&self) -> CtOption<Fq>

Computes the square root of this element, if it exists.

Source§

fn invert(&self) -> CtOption<Fq>

Computes the multiplicative inverse of this element, failing if the element is zero.

Source§

fn random(rng: impl RngCore) -> Fq

Source§

fn zero() -> Fq

Source§

fn one() -> Fq

Source§

fn double(&self) -> Fq

Source§

fn square(&self) -> Fq

Source§

fn pow_vartime<S>(&self, exp: S) -> Fq
where S: AsRef<[u64]>,

Implementors§

impl Field for Scalar

impl Field for Fq

impl Field for Fr

impl Field for Fq

impl Field for Fr

impl Field for Fp

impl Field for Fq

impl Field for Fp

impl Field for Fq

impl Field for Fp

impl Field for Fq

impl Field for Fp

impl Field for Fq

impl<F: ExtField> Field for QuadExtField<F>
where QuadExtField<F>: QuadExtFieldArith<Base = F> + ExtField,

impl Field for Fp

impl Field for Fp12

impl Field for Fp2

impl Field for Scalar

impl Field for Fq

impl Field for Fq12

impl Field for Fq2

impl Field for Fq6

impl Field for Fr

impl Field for Fq

impl Field for Fr

impl Field for Fp

impl Field for Fq

impl Field for Fp

impl Field for Fq

impl Field for Fp

impl Field for Fq

impl Field for Fr

impl Field for Scalar