# Trait ff::PrimeField

source · ```
pub trait PrimeField: Field + From<u64> {
type Repr: Copy + Default + Send + Sync + 'static + AsRef<[u8]> + AsMut<[u8]>;
const NUM_BITS: u32;
const CAPACITY: u32;
const S: u32;
// Required methods
fn from_repr(repr: Self::Repr) -> CtOption<Self>;
fn to_repr(&self) -> Self::Repr;
fn is_odd(&self) -> Choice;
fn multiplicative_generator() -> Self;
fn root_of_unity() -> Self;
// Provided methods
fn from_str_vartime(s: &str) -> Option<Self> { ... }
fn from_repr_vartime(repr: Self::Repr) -> Option<Self> { ... }
fn is_even(&self) -> Choice { ... }
}
```

## Expand description

This represents an element of a prime field.

## Required Associated Types§

## Required Associated Constants§

## Required Methods§

source#### fn from_repr(repr: Self::Repr) -> CtOption<Self>

#### fn from_repr(repr: Self::Repr) -> CtOption<Self>

Attempts to convert a byte representation of a field element into an element of this prime field, failing if the input is not canonical (is not smaller than the field’s modulus).

The byte representation is interpreted with the same endianness as elements
returned by `PrimeField::to_repr`

.

source#### fn to_repr(&self) -> Self::Repr

#### fn to_repr(&self) -> Self::Repr

Converts an element of the prime field into the standard byte representation for this field.

The endianness of the byte representation is implementation-specific. Generic encodings of field elements should be treated as opaque.

source#### fn multiplicative_generator() -> Self

#### fn multiplicative_generator() -> Self

Returns a fixed multiplicative generator of `modulus - 1`

order. This element must
also be a quadratic nonresidue.

It can be calculated using SageMath as `GF(modulus).primitive_element()`

.

Implementations of this method MUST ensure that this is the generator used to
derive `Self::root_of_unity`

.

source#### fn root_of_unity() -> Self

#### fn root_of_unity() -> Self

Returns the `2^s`

root of unity.

It can be calculated by exponentiating `Self::multiplicative_generator`

by `t`

,
where `t = (modulus - 1) >> Self::S`

.

## Provided Methods§

source#### fn from_str_vartime(s: &str) -> Option<Self>

#### fn from_str_vartime(s: &str) -> Option<Self>

Interpret a string of numbers as a (congruent) prime field element. Does not accept unnecessary leading zeroes or a blank string.

##### §Security

This method provides **no** constant-time guarantees.

source#### fn from_repr_vartime(repr: Self::Repr) -> Option<Self>

#### fn from_repr_vartime(repr: Self::Repr) -> Option<Self>

Attempts to convert a byte representation of a field element into an element of this prime field, failing if the input is not canonical (is not smaller than the field’s modulus).

The byte representation is interpreted with the same endianness as elements
returned by `PrimeField::to_repr`

.

##### §Security

This method provides **no** constant-time guarantees. Implementors of the
`PrimeField`

trait **may** optimise this method using non-constant-time logic.

## Object Safety§

**not**object safe.