Trait winter_math::FieldElement[][src]

pub trait FieldElement: Copy + Clone + Debug + Display + Default + Send + Sync + Eq + PartialEq + Sized + Add<Self, Output = Self> + Sub<Self, Output = Self> + Mul<Self, Output = Self> + Div<Self, Output = Self> + AddAssign<Self> + SubAssign<Self> + MulAssign<Self> + DivAssign<Self> + Neg<Output = Self> + From<Self::BaseField> + From<u128> + From<u64> + From<u32> + From<u16> + From<u8> + for<'a> TryFrom<&'a [u8]> + AsBytes + Serializable + Deserializable {
    type PositiveInteger: Debug + Copy + PartialEq + PartialOrd + ShrAssign + Shl<u32, Output = Self::PositiveInteger> + Shr<u32, Output = Self::PositiveInteger> + BitAnd<Output = Self::PositiveInteger> + From<u32> + From<u64>;
    type BaseField: StarkField;

    const ELEMENT_BYTES: usize;
    const IS_MALLEABLE: bool;
    const ZERO: Self;
    const ONE: Self;
Show 14 methods fn inv(self) -> Self;
fn conjugate(&self) -> Self;
fn rand() -> Self;
fn from_random_bytes(bytes: &[u8]) -> Option<Self>;
fn elements_into_bytes(elements: Vec<Self>) -> Vec<u8>;
fn elements_as_bytes(elements: &[Self]) -> &[u8];
unsafe fn bytes_as_elements(
        bytes: &[u8]
    ) -> Result<&[Self], DeserializationError>;
fn prng_vector(seed: [u8; 32], n: usize) -> Vec<Self>;
fn normalize(&mut self); fn double(self) -> Self { ... }
fn square(self) -> Self { ... }
fn cube(self) -> Self { ... }
fn exp(self, power: Self::PositiveInteger) -> Self { ... }
fn zeroed_vector(n: usize) -> Vec<Self> { ... }
}
Expand description

Defines an element in a finite field.

This trait defines basic arithmetic operations for elements in finite fields (e.g. addition subtraction, multiplication, division) as well as several convenience functions (e.g. double, square cube). Moreover, it defines interfaces for serializing and deserializing field elements.

The elements could be in a prime field or an extension of a prime field. Currently, only quadratic field extensions are supported.

Associated Types

A type defining positive integers big enough to describe a field modulus for Self::BaseField with no loss of precision.

Base field type for this finite field. For prime fields, BaseField should be set to Self.

Associated Constants

Number of bytes needed to encode an element

True if internal representation of an element can be redundant - i.e., multiple internal representations map to the same canonical representation.

The additive identity.

The multiplicative identity.

Required methods

Returns a multiplicative inverse of this field element. If this element is ZERO, ZERO is returned.

Returns a conjugate of this field element.

Returns a cryptographically-secure random element drawn uniformly from the entire field.

Returns a field element if the set of bytes forms a valid field element, otherwise returns None. The element is expected to be in canonical representation. This function is primarily intended for sampling random field elements from a hash function output.

Converts a vector of field elements into a vector of bytes. The elements may be in the internal representation rather than in the canonical representation. This conversion is intended to be zero-copy (i.e. by re-interpreting the underlying memory).

Converts a list of elements into a list of bytes. The elements may be in the internal representation rather than in the canonical representation. This conversion is intended to be zero-copy (i.e. by re-interpreting the underlying memory).

Converts a list of bytes into a list of field elements. The elements are assumed to encoded in the internal representation rather than in the canonical representation. The conversion is intended to be zero-copy (i.e. by re-interpreting the underlying memory).

Errors

An error is returned if:

  • Memory alignment of bytes does not match memory alignment of field element data.
  • Length of bytes does not divide into whole number of elements.

Safety

This function is unsafe because it does not check whether underlying bytes represent valid field elements according to their internal representation.

Returns a vector of n pseudo-random elements drawn uniformly from the entire field based on the provided seed.

Normalizes internal representation of this element.

Normalization is applicable only to malleable field elements; for non-malleable elements this is a no-op.

Provided methods

Returns this field element added to itself.

Returns this field element raised to power 2.

Returns this field element raised to power 3.

Exponentiates this field element by power parameter.

Returns a vector of length n initialized with all ZERO elements.

Specialized implementations of this function may be faster than the generic implementation.

Implementors