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
const ROOT_OF_UNITY: Self
const ROOT_OF_UNITY: Self
Generator of the $2^S$ multiplicative subgroup
const ROOT_OF_UNITY_INV: Self
const ROOT_OF_UNITY_INV: Self
Inverse of ROOT_OF_UNITY
const T_MINUS1_OVER2: [u64; 4]
const T_MINUS1_OVER2: [u64; 4]
The value $(T-1)/2$ such that $2^S \cdot T = p - 1$ with $T$ odd.
const RESCUE_ALPHA: u64
const RESCUE_ALPHA: u64
Ideally the smallest prime $\alpha$ such that gcd($p - 1$, $\alpha$) = $1$
const RESCUE_INVALPHA: [u64; 4]
const RESCUE_INVALPHA: [u64; 4]
$RESCUE_INVALPHA \cdot RESCUE_ALPHA = 1 \mod p - 1$ such that
(a^RESCUE_ALPHA)^RESCUE_INVALPHA = a
.
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.
Converts this field element to its normalized, little endian byte representation.
Attempts to obtain a field element from its normalized, little endian byte representation.
fn from_bytes_wide(bytes: &[u8; 64]) -> Self
fn from_bytes_wide(bytes: &[u8; 64]) -> Self
Obtains a field element that is congruent to the provided little endian byte representation of an integer.
fn get_lower_128(&self) -> u128
fn get_lower_128(&self) -> u128
Gets the lower 128 bits of this field element when expressed canonically.
fn get_lower_32(&self) -> u32
fn get_lower_32(&self) -> u32
Gets the lower 32 bits of this field element when expressed canonically.
Provided methods
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.
fn pow_by_t_minus1_over2(&self) -> Self
fn pow_by_t_minus1_over2(&self) -> Self
Raise this field element to the power T_MINUS1_OVER2. Field implementations may override this to use an efficient addition chain.