pub trait Field:
'static
+ Debug
+ Default
+ Sized
+ Send
+ Sync
+ Copy
+ Clone
+ Eq
+ Ord
+ ConstantTimeEq
+ ConstantTimeGreater
+ ConstantTimeLess
+ ConditionallySelectable
+ Add<Output = Self>
+ for<'a> Add<&'a Self, Output = Self>
+ AddAssign<Self>
+ for<'a> AddAssign<&'a Self>
+ Neg<Output = Self>
+ Sub<Output = Self>
+ for<'a> Sub<&'a Self, Output = Self>
+ SubAssign<Self>
+ for<'a> SubAssign<&'a Self>
+ Mul<Output = Self>
+ for<'a> Mul<&'a Self, Output = Self>
+ MulAssign<Self>
+ for<'a> MulAssign<&'a Self>
+ Div<Output = Self>
+ for<'a> Div<&'a Self, Output = Self>
+ DivAssign<Self>
+ for<'a> DivAssign<&'a Self>
+ Sum
+ Product
+ Display
+ Binary
+ Octal
+ LowerHex
+ UpperHex
+ FromStr
+ From<u8>
+ From<u16>
+ TryFrom<usize, Error: Debug> {
const LEN: usize;
const ZERO: Self;
const ONE: Self;
const MAX: Self;
const NUM_BITS: usize = _;
const BITS: usize = Self::NUM_BITS;
Show 30 methods
// Required methods
fn is_odd(&self) -> Choice;
fn try_random<R: TryCryptoRng>(rng: &mut R) -> Result<Self, R::Error>;
fn random<R: CryptoRng>(rng: &mut R) -> Self;
fn random_default() -> Self;
fn invert(&self) -> CtOption<Self>;
fn invert_vartime(&self) -> Option<Self>;
fn pow(self, exp: Self) -> Self;
fn pow_vartime(self, exp: Self) -> Self;
fn div_int(&self, rhs: &Self) -> (Self, Self);
fn try_from_le_bytes(bytes: &[u8]) -> CtOption<Self>;
fn try_from_be_bytes(bytes: &[u8]) -> CtOption<Self>;
fn from_str_radix(s: &str, radix: usize) -> Result<Self, Error>;
fn to_str_radix(
&self,
radix: usize,
pad_to: usize,
upper_case: bool,
) -> String;
fn try_to_u8(&self) -> Option<u8>;
fn try_to_u16(&self) -> Option<u16>;
// Provided methods
fn zero() -> Self { ... }
fn one() -> Self { ... }
fn is_zero(&self) -> Choice { ... }
fn is_even(&self) -> Choice { ... }
fn double(&self) -> Self { ... }
fn square(&self) -> Self { ... }
fn cube(&self) -> Self { ... }
fn invert_unwrap(&self) -> Self { ... }
fn invert_or_zero(&self) -> Self { ... }
fn pow_small(self, exp: usize) -> Self { ... }
fn pow_small_vartime(self, exp: usize) -> Self { ... }
fn pow_u32(self, exp: u32) -> Self { ... }
fn pow_u32_vartime(self, exp: u32) -> Self { ... }
fn pow_u64(self, exp: u64) -> Self { ... }
fn pow_u64_vartime(self, exp: u64) -> Self { ... }
}Expand description
A finite field.
NOTE: this is assumed to be a numeric finite field, ie. a range of the integers from 0
inclusive to N exclusive, with N being the cardinality of the field. For this reason this trait
inherits several traits that are not necessarily part of algebraic fields, such as Ord for
total ordering and several std::fmt::* traits for formatting numbers.
Required Associated Constants§
Provided Associated Constants§
Sourceconst BITS: usize = Self::NUM_BITS
const BITS: usize = Self::NUM_BITS
Same as Self::NUM_BITS. Provided for consistency with native Rust types.
Required Methods§
Sourcefn try_random<R: TryCryptoRng>(rng: &mut R) -> Result<Self, R::Error>
fn try_random<R: TryCryptoRng>(rng: &mut R) -> Result<Self, R::Error>
Picks a uniformly distributed random scalar securely from the provided fallible CSPRNG.
Sourcefn random<R: CryptoRng>(rng: &mut R) -> Self
fn random<R: CryptoRng>(rng: &mut R) -> Self
Picks a uniformly distributed random scalar securely from the provided infallible CSPRNG.
Sourcefn random_default() -> Self
fn random_default() -> Self
Picks a uniformly distributed random scalar securely from the system’s default CSPRNG.
Sourcefn invert(&self) -> CtOption<Self>
fn invert(&self) -> CtOption<Self>
Returns the modular inverse of self, or Noneifself` is zero.
Sourcefn invert_vartime(&self) -> Option<Self>
fn invert_vartime(&self) -> Option<Self>
Returns the modular inverse of self, or Noneifself` is zero.
Sourcefn pow(self, exp: Self) -> Self
fn pow(self, exp: Self) -> Self
Raises this value to exp, running exactly Self::NUM_BITS squares and multiplications
so that a time observer cannot infer the exponent.
Sourcefn pow_vartime(self, exp: Self) -> Self
fn pow_vartime(self, exp: Self) -> Self
Raises this value to exp.
Sourcefn div_int(&self, rhs: &Self) -> (Self, Self)
fn div_int(&self, rhs: &Self) -> (Self, Self)
Performs integer division by rhs and returns a (quotient, remainder) pair. Panics if rhs
is zero.
Sourcefn try_from_le_bytes(bytes: &[u8]) -> CtOption<Self>
fn try_from_le_bytes(bytes: &[u8]) -> CtOption<Self>
Constructs a scalar from the little-endian byte representation of an integer.
The provided slice must have exactly Self::LEN bytes.
The function returns None if the integer lies outside the field range.
Sourcefn try_from_be_bytes(bytes: &[u8]) -> CtOption<Self>
fn try_from_be_bytes(bytes: &[u8]) -> CtOption<Self>
Constructs a scalar from the big-endian byte representation of an integer.
The provided slice must have exactly Self::LEN bytes.
The function returns None if the integer lies outside the field range.
Sourcefn from_str_radix(s: &str, radix: usize) -> Result<Self, Error>
fn from_str_radix(s: &str, radix: usize) -> Result<Self, Error>
Parses a scalar from its text representation in the given radix.
Returns an error on invalid format or overflow. Panics if radix is less than 2 or greater
than 36.
Sourcefn to_str_radix(&self, radix: usize, pad_to: usize, upper_case: bool) -> String
fn to_str_radix(&self, radix: usize, pad_to: usize, upper_case: bool) -> String
Converts a scalar to its textual representation in the given radix.
The returned string will have at least pad_to characters, and will be padded with zeros if
necessary.
When radix is greater than 10, the representation will start using alphabetic characters
from A to Z for digits greater than 9, e.g. character A to F for hexadecimal numbers. The
upper_case flag specifies whether those characters must be lower case or upper case.
This function panics if radix is less than 2 or greater than 36.
Sourcefn try_to_u8(&self) -> Option<u8>
fn try_to_u8(&self) -> Option<u8>
Returns this scalar as a u8, or None if the value exceeds the 8-bit range.
Sourcefn try_to_u16(&self) -> Option<u16>
fn try_to_u16(&self) -> Option<u16>
Returns this scalar as a u16, or None if the value exceeds the 16-bit range.
Provided Methods§
Sourcefn invert_unwrap(&self) -> Self
fn invert_unwrap(&self) -> Self
Returns the modular inverse of self, assuming self is not zero and panicking otherwise.
Sourcefn invert_or_zero(&self) -> Self
fn invert_or_zero(&self) -> Self
Returns the modular inverse of self, or zero if self is zero.
Sourcefn pow_small(self, exp: usize) -> Self
fn pow_small(self, exp: usize) -> Self
Raises this value to exp, running exactly usize::BITS squares and multiplications so
that a time observer cannot infer the exponent.
Unlike Field::pow, exp is a usize. That makes the algorithm significantly faster
because the square-and-multiply loop runs only usize::BITS times rather than
Field::BITS times, and bitwise operations on the exponent are native.
Sourcefn pow_small_vartime(self, exp: usize) -> Self
fn pow_small_vartime(self, exp: usize) -> Self
Raises this value to exp.
Unlike Field::pow, exp is a usize. That makes the algorithm significantly faster
because bitwise operations on the exponent are native.
Sourcefn pow_u32(self, exp: u32) -> Self
fn pow_u32(self, exp: u32) -> Self
Raises this value to exp, running exactly u32::BITS squares and multiplications so
that an observer cannot infer the exponent.
Unlike Field::pow, exp is a u32. That makes the algorithm significantly faster
because the square-and-multiply loop runs only 32 times rather than Field::BITS times,
and bitwise operations on the exponent are native.
Sourcefn pow_u32_vartime(self, exp: u32) -> Self
fn pow_u32_vartime(self, exp: u32) -> Self
Raises this value to exp.
Unlike Field::pow_vartime, exp is a u32. That makes the algorithm significantly
faster because bitwise operations on the exponent are native.
Sourcefn pow_u64(self, exp: u64) -> Self
fn pow_u64(self, exp: u64) -> Self
Raises this value to exp, running exactly u64::BITS squares and multiplications so
that an observer cannot infer the exponent.
Unlike Field::pow, exp is a u64. That makes the algorithm significantly faster
because the square-and-multiply loop runs only 64 times rather than Field::BITS times,
and bitwise operations on the exponent are native.
Sourcefn pow_u64_vartime(self, exp: u64) -> Self
fn pow_u64_vartime(self, exp: u64) -> Self
Raises this value to exp.
Unlike Field::pow_vartime, exp is a u64. That makes the algorithm significantly
faster because bitwise operations on the exponent are native.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".