pub trait FieldElement:
Add<Output = Self>
+ AddAssign
+ Div<Output = Self>
+ Mul<Output = Self>
+ MulAssign
+ Neg<Output = Self>
+ Sub<Output = Self>
+ SubAssign
+ FromStr
+ PartialEq
+ Clone
+ Hash
+ Debug
+ From<u64>
+ Display {
Show 17 methods
// Required methods
fn byte_len() -> usize;
fn serialize(&self) -> String;
fn deserialize(str: &str) -> Self;
fn name_str() -> &'static str;
fn from_bytes_le(bytes: &[u8]) -> Self;
fn to_bytes_le(&self) -> Vec<u8>;
// Provided methods
fn zero() -> Self { ... }
fn one() -> Self { ... }
fn sample_rand<R>(src: &mut R) -> Self
where R: Rng { ... }
fn prime() -> BigUint { ... }
fn from_usize(value: usize) -> Self { ... }
fn to_biguint(&self) -> BigUint { ... }
fn from_biguint(v: &BigUint) -> Self { ... }
fn lower60_string(&self) -> String { ... }
fn log_floor(&self, b: Self) -> u32 { ... }
fn legendre(&self) -> i32 { ... }
fn sqrt(&self) -> Self { ... }
}Expand description
A generic representation of a scalar finite field element. For use in internal module logic. Supports field operations using builtin operators (*-+/) and other convenience traits. Handles serialization and deserialization to a reasonable string representation.
Required Methods§
sourcefn deserialize(str: &str) -> Self
fn deserialize(str: &str) -> Self
Parse an element from a supposedly valid string representation.
sourcefn from_bytes_le(bytes: &[u8]) -> Self
fn from_bytes_le(bytes: &[u8]) -> Self
Parse an element from a byte representation. Panics if the byte representation is too long. e.g. if the bytes represent a value > Self::prime().
sourcefn to_bytes_le(&self) -> Vec<u8>
fn to_bytes_le(&self) -> Vec<u8>
Convert a field element to a byte representation.
The number of bytes may be variable, but is guaranteed
to be accepted by from_bytes_le for the same curve.
Provided Methods§
sourcefn sample_rand<R>(src: &mut R) -> Selfwhere
R: Rng,
fn sample_rand<R>(src: &mut R) -> Selfwhere
R: Rng,
Sample a random element from the field using a supplied
source of randomness. Requires the random feature to be enabled.
sourcefn from_usize(value: usize) -> Self
fn from_usize(value: usize) -> Self
Parse an element from a usize throws if the field size is smaller than the usize on the machine.
sourcefn to_biguint(&self) -> BigUint
fn to_biguint(&self) -> BigUint
Get a num_bigint::BigUint representation for arbitrary
precision operations.
sourcefn from_biguint(v: &BigUint) -> Self
fn from_biguint(v: &BigUint) -> Self
Convert a num_bigint::BigUint into a field element
precision operations. Numbers will be converted % self.prime()
sourcefn lower60_string(&self) -> String
fn lower60_string(&self) -> String
A string representation of a field element using only the lower 60 bits of the element. A normal decimal representation will be given if it’s shorter than the lower 60 bit representation. This is a lossy representation.
sourcefn log_floor(&self, b: Self) -> u32
fn log_floor(&self, b: Self) -> u32
Take a logarithm using a custom base and return the
floored value. O(logb(n)) time complexity where n
is the size of the element.
sourcefn legendre(&self) -> i32
fn legendre(&self) -> i32
Calculate the legendre symbol for a field element. Used to determine if the element is a quadratic residue.