Trait ff::Field

source ·
pub trait Field: Sized + Eq + Copy + Clone + Default + Send + Sync + Debug + 'static + ConditionallySelectable + ConstantTimeEq + Add<Output = Self> + Sub<Output = Self> + Mul<Output = Self> + Neg<Output = Self> + for<'a> Add<&'a Self, Output = Self> + for<'a> Mul<&'a Self, Output = Self> + for<'a> Sub<&'a Self, Output = 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: AsRef<[u64]>>(&self, exp: S) -> Self { ... }
}
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: AsRef<[u64]>>(&self, exp: S) -> Self

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.

Object Safety§

This trait is not object safe.

Implementors§