pub struct GenericFieldElement<P: FieldParameters> { /* private fields */ }Expand description
Generic field element with extensible parameters.
This struct provides a generic field element that can work with different moduli and limb configurations through the FieldParameters trait.
Implementations§
Source§impl<P: FieldParameters> GenericFieldElement<P>
impl<P: FieldParameters> GenericFieldElement<P>
Sourcepub fn new(value: BigInt) -> Result<Self, MathError>
pub fn new(value: BigInt) -> Result<Self, MathError>
Create a new field element from a BigInt.
The value is automatically converted to Montgomery form.
Sourcepub unsafe fn from_montgomery_unchecked(value: BigInt) -> Self
pub unsafe fn from_montgomery_unchecked(value: BigInt) -> Self
Create a field element from raw Montgomery representation.
This is unsafe because it doesn’t validate the input.
Sourcepub fn from_montgomery_checked(value: BigInt) -> Result<Self, MathError>
pub fn from_montgomery_checked(value: BigInt) -> Result<Self, MathError>
Create a field element from raw Montgomery representation with validation.
This validates that the input is in the correct range [0, modulus).
Sourcepub fn to_montgomery(&self) -> &BigInt
pub fn to_montgomery(&self) -> &BigInt
Get the Montgomery representation of this field element.
Returns a reference to the internal Montgomery-form value. Note: In this extensible implementation, values are stored directly rather than in full Montgomery form for simplicity.
Sourcepub fn to_regular(&self) -> BigInt
pub fn to_regular(&self) -> BigInt
Convert this field element to regular (non-Montgomery) representation.
Returns the field element value in standard form, not Montgomery form. In this extensible implementation, values are stored directly, so this simply returns a clone of the internal value.
Trait Implementations§
Source§impl<P: Clone + FieldParameters> Clone for GenericFieldElement<P>
impl<P: Clone + FieldParameters> Clone for GenericFieldElement<P>
Source§fn clone(&self) -> GenericFieldElement<P>
fn clone(&self) -> GenericFieldElement<P>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<P: Debug + FieldParameters> Debug for GenericFieldElement<P>
impl<P: Debug + FieldParameters> Debug for GenericFieldElement<P>
Source§impl<P: FieldParameters> GenericFieldOps<P> for GenericFieldElement<P>
impl<P: FieldParameters> GenericFieldOps<P> for GenericFieldElement<P>
Source§fn add(&self, rhs: &GenericFieldElement<P>) -> GenericFieldElement<P>
fn add(&self, rhs: &GenericFieldElement<P>) -> GenericFieldElement<P>
Add two field elements.
Performs modular addition: (self + rhs) mod modulus. If the sum exceeds the modulus, it wraps around by subtracting the modulus once.
Source§fn sub(&self, rhs: &GenericFieldElement<P>) -> GenericFieldElement<P>
fn sub(&self, rhs: &GenericFieldElement<P>) -> GenericFieldElement<P>
Subtract two field elements.
Performs modular subtraction: (self - rhs) mod modulus. If self < rhs, adds the modulus to the difference to ensure a positive result.
Source§fn inv(&self) -> Result<GenericFieldElement<P>, MathError>
fn inv(&self) -> Result<GenericFieldElement<P>, MathError>
Compute the multiplicative inverse using the extended Euclidean algorithm.
Finds x such that (self * x) ≡ 1 mod modulus. Uses the extended Euclidean algorithm to compute the modular inverse. Returns DivisionByZero error if the element is zero or if no inverse exists.
Source§fn square(&self) -> GenericFieldElement<P>
fn square(&self) -> GenericFieldElement<P>
Compute the square of this field element.
Performs modular squaring: (self * self) mod modulus. More efficient than general multiplication for exponentiation algorithms.
Source§fn ct_eq(&self, rhs: &GenericFieldElement<P>) -> bool
fn ct_eq(&self, rhs: &GenericFieldElement<P>) -> bool
Check equality in constant time.
Performs a constant-time comparison of the underlying BigInt values to prevent timing-based side-channel attacks.
Source§fn is_zero(&self) -> bool
fn is_zero(&self) -> bool
Check if this element is the additive identity (zero).
Returns true if this field element represents 0 in the finite field. Converts to regular representation and compares with zero.