pub trait FieldElement:
Add<Output = Self>
+ AddAssign
+ Div<Output = Self>
+ Mul<Output = Self>
+ MulAssign
+ Neg<Output = Self>
+ Sub<Output = Self>
+ SubAssign
+ FromStr<Err = Error>
+ PartialEq
+ Clone
+ Hash
+ Debug
+ From<u64>
+ Display {
Show 14 methods
// Required methods
fn byte_len() -> usize;
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 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 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 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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.