Trait FieldElement

Source
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§

Source

fn byte_len() -> usize

Minimum number of bytes needed to represent an element.

Source

fn name_str() -> &'static str

A short string identifier for the field.

Source

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().

Source

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§

Source

fn zero() -> Self

Get the zero element.

Source

fn one() -> Self

Get the one element.

Source

fn prime() -> BigUint

The prime modulus of the field as an arbitrary precision integer.

Source

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.

Source

fn to_biguint(&self) -> BigUint

Get a num_bigint::BigUint representation for arbitrary precision operations.

Source

fn from_biguint(v: &BigUint) -> Self

Convert a num_bigint::BigUint into a field element precision operations. Numbers will be converted % self.prime()

Source

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.

Source

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.

Source

fn legendre(&self) -> i32

Calculate the legendre symbol for a field element. Used to determine if the element is a quadratic residue.

Source

fn sqrt(&self) -> Self

Kumar 08 prime field square root implementation. Always returns the smaller root e.g. the positive root.

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.

Implementors§