Trait pasta_curves::arithmetic::FieldExt[][src]

pub trait FieldExt: PrimeField + From<bool> + Ord + Group<Scalar = Self> {
    const MODULUS: &'static str;
    const ROOT_OF_UNITY: Self;
    const ROOT_OF_UNITY_INV: Self;
    const T_MINUS1_OVER2: [u64; 4];
    const DELTA: Self;
    const TWO_INV: Self;
    const RESCUE_ALPHA: u64;
    const RESCUE_INVALPHA: [u64; 4];
    const ZETA: Self;
Show 14 methods fn sqrt_ratio(num: &Self, div: &Self) -> (Choice, Self);
fn from_u64(v: u64) -> Self;
fn from_u128(v: u128) -> Self;
fn to_bytes(&self) -> [u8; 32];
fn from_bytes(bytes: &[u8; 32]) -> CtOption<Self>;
fn from_bytes_wide(bytes: &[u8; 64]) -> Self;
fn get_lower_128(&self) -> u128;
fn get_lower_32(&self) -> u32; fn sqrt_alt(&self) -> (Choice, Self) { ... }
fn rand() -> Self { ... }
fn write<W: Write>(&self, writer: &mut W) -> Result<()> { ... }
fn read<R: Read>(reader: &mut R) -> Result<Self> { ... }
fn pow(&self, by: &[u64; 4]) -> Self { ... }
fn pow_by_t_minus1_over2(&self) -> Self { ... }
}
Expand description

This trait is a common interface for dealing with elements of a finite field.

Associated Constants

Modulus of the field written as a string for display purposes

Generator of the $2^S$ multiplicative subgroup

Inverse of ROOT_OF_UNITY

The value $(T-1)/2$ such that $2^S \cdot T = p - 1$ with $T$ odd.

Generator of the $t-order$ multiplicative subgroup

Inverse of $2$ in the field.

Ideally the smallest prime $\alpha$ such that gcd($p - 1$, $\alpha$) = $1$

$RESCUE_INVALPHA \cdot RESCUE_ALPHA = 1 \mod p - 1$ such that (a^RESCUE_ALPHA)^RESCUE_INVALPHA = a.

Element of multiplicative order $3$.

Required methods

Computes:

  • (true, sqrt(num/div)), if num and div are nonzero and num/div is a square in the field;
  • (true, 0), if num is zero;
  • (false, 0), if num is nonzero and div is zero;
  • (false, sqrt(ROOT_OF_UNITY * num/div)), if num and div are nonzero and num/div is a nonsquare in the field;

where ROOT_OF_UNITY is a generator of the order 2^n subgroup (and therefore a nonsquare).

The choice of root from sqrt is unspecified.

Obtains a field element congruent to the integer v.

Obtains a field element congruent to the integer v.

Converts this field element to its normalized, little endian byte representation.

Attempts to obtain a field element from its normalized, little endian byte representation.

Obtains a field element that is congruent to the provided little endian byte representation of an integer.

Gets the lower 128 bits of this field element when expressed canonically.

Gets the lower 32 bits of this field element when expressed canonically.

Provided methods

Equivalent to sqrt_ratio(self, one()).

This computes a random element of the field using system randomness.

Writes this element in its normalized, little endian form into a buffer.

Reads a normalized, little endian represented field element from a buffer.

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

Raise this field element to the power T_MINUS1_OVER2. Field implementations may override this to use an efficient addition chain.

Implementors