GenericFieldElement

Struct GenericFieldElement 

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

Source

pub fn new(value: BigInt) -> Result<Self, MathError>

Create a new field element from a BigInt.

The value is automatically converted to Montgomery form.

Source

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.

Source

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

Source

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.

Source

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.

Source

pub fn modulus() -> BigInt

Get the modulus for this field.

Returns the prime modulus that defines this finite field. This is a static method that delegates to the FieldParameters trait.

Trait Implementations§

Source§

impl<P: Clone + FieldParameters> Clone for GenericFieldElement<P>

Source§

fn clone(&self) -> GenericFieldElement<P>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<P: Debug + FieldParameters> Debug for GenericFieldElement<P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P: FieldParameters> GenericFieldOps<P> for GenericFieldElement<P>

Source§

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>

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>

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>

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

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

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.

Source§

fn mul(&self, rhs: &GenericFieldElement<P>) -> GenericFieldElement<P>

Multiply two field elements. Read more
Source§

impl<P: PartialEq + FieldParameters> PartialEq for GenericFieldElement<P>

Source§

fn eq(&self, other: &GenericFieldElement<P>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<P: Copy + FieldParameters> Copy for GenericFieldElement<P>

Source§

impl<P: Eq + FieldParameters> Eq for GenericFieldElement<P>

Source§

impl<P: FieldParameters> StructuralPartialEq for GenericFieldElement<P>

Auto Trait Implementations§

§

impl<P> Freeze for GenericFieldElement<P>

§

impl<P> RefUnwindSafe for GenericFieldElement<P>
where P: RefUnwindSafe,

§

impl<P> Send for GenericFieldElement<P>
where P: Send,

§

impl<P> Sync for GenericFieldElement<P>
where P: Sync,

§

impl<P> Unpin for GenericFieldElement<P>
where P: Unpin,

§

impl<P> UnwindSafe for GenericFieldElement<P>
where P: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.