Skip to main content

Fp5Element

Struct Fp5Element 

Source
pub struct Fp5Element(pub [Goldilocks; 5]);
Expand description

Fp5 extension field element.

Represents an element of the quintic extension field GF(p^5) where p is the Goldilocks prime. Each element is represented as a polynomial of degree at most 4 over the base field.

The extension field uses the irreducible polynomial x^5 = w where w = 3.

§Example

use poseidon_hash::{Fp5Element, Goldilocks};

let a = Fp5Element::from_uint64_array([1, 2, 3, 4, 5]);
let b = Fp5Element::one();
let product = a.mul(&b);

Tuple Fields§

§0: [Goldilocks; 5]

Implementations§

Source§

impl Fp5Element

Source

pub fn zero() -> Self

Returns the zero element of the extension field.

Source

pub fn one() -> Self

Returns the multiplicative identity (one) of the extension field.

Source

pub fn is_zero(&self) -> bool

Checks if this element is zero.

Source

pub fn add(&self, other: &Fp5Element) -> Fp5Element

Adds two extension field elements.

Addition is performed component-wise on the polynomial coefficients.

Source

pub fn sub(&self, other: &Fp5Element) -> Fp5Element

Subtracts two extension field elements.

Subtraction is performed component-wise on the polynomial coefficients.

Source

pub fn mul(&self, other: &Fp5Element) -> Fp5Element

Multiplies two extension field elements.

Uses the irreducible polynomial x^5 = w (where w = 3) to reduce the result.

§Example
use poseidon_hash::{Fp5Element, Goldilocks};

let a = Fp5Element::from_uint64_array([1, 0, 0, 0, 0]);
let b = Fp5Element::from_uint64_array([2, 0, 0, 0, 0]);
let product = a.mul(&b);
Source

pub fn inverse(&self) -> Fp5Element

Computes the multiplicative inverse of this element.

Returns zero if this element is zero (which has no inverse).

Source

pub fn inverse_or_zero(&self) -> Fp5Element

Computes the multiplicative inverse, returning zero if the element is zero.

This is a safe version of inverse() that handles zero elements gracefully.

Source

pub fn frobenius(&self) -> Fp5Element

Applies the Frobenius automorphism once.

The Frobenius automorphism raises each coefficient to the p-th power.

Source

pub fn repeated_frobenius(&self, count: usize) -> Fp5Element

Applies the Frobenius automorphism count times.

Since we’re in GF(p^5), applying it 5 times returns the original element.

Source

pub fn scalar_mul(&self, scalar: &Goldilocks) -> Fp5Element

Multiplies this element by a scalar (base field element).

This is more efficient than full extension field multiplication when one operand is in the base field.

Source

pub fn square(&self) -> Fp5Element

Computes the square of this element.

Optimized implementation that uses fewer operations than general multiplication.

Source

pub fn double(&self) -> Fp5Element

Doubles this element (multiplies by 2).

Source

pub fn from_uint64_array(arr: [u64; 5]) -> Fp5Element

Creates an Fp5Element from an array of 5 u64 values.

Each u64 value is interpreted as a Goldilocks field element.

§Example
use poseidon_hash::Fp5Element;

let elem = Fp5Element::from_uint64_array([1, 2, 3, 4, 5]);
Source

pub fn to_bytes_le(&self) -> [u8; 40]

Converts this element to a 40-byte little-endian representation.

Each of the 5 Goldilocks field elements contributes 8 bytes (little-endian).

§Example
use poseidon_hash::Fp5Element;

let elem = Fp5Element::one();
let bytes = elem.to_bytes_le();
assert_eq!(bytes.len(), 40);
Source

pub fn from_bytes_le(bytes: &[u8]) -> Result<Self, String>

Creates an Fp5Element from a 40-byte little-endian representation.

Each of the 5 Goldilocks field elements is read as 8 bytes (little-endian).

§Example
use poseidon_hash::Fp5Element;

let bytes = [0u8; 40];
let elem = Fp5Element::from_bytes_le(&bytes);
Source

pub fn neg(&self) -> Fp5Element

Computes the additive inverse (negation) of this element.

Source

pub fn exp_power_of_2(&self, n: usize) -> Fp5Element

Raises this element to the power of 2^n by repeated squaring.

Equivalent to Go’s ExpPowerOf2 function.

Source

pub fn sgn0(&self) -> bool

Computes the sign function Sgn0(x) for this element.

Returns true if the sign bit (LSB of the first non-zero limb) is 0. Equivalent to Go’s Sgn0 function.

Source

pub fn sqrt(&self) -> Option<Fp5Element>

Computes the square root of this element.

Returns Some(sqrt) if the square root exists, None otherwise. Equivalent to Go’s Sqrt function.

Source

pub fn canonical_sqrt(&self) -> (Fp5Element, bool)

Computes the canonical square root of this element.

Returns (canonical_sqrt, success) where success indicates if the square root exists. The canonical square root is chosen such that Sgn0(sqrt) == false. Equivalent to Go’s CanonicalSqrt function.

Source

pub fn legendre(&self) -> Goldilocks

Computes the Legendre symbol of this element.

Returns a Goldilocks element:

  • 0 if x is zero
  • 1 if x is a quadratic residue (square)
  • -1 (p-1) if x is a quadratic non-residue

Equivalent to Go’s Legendre function.

Source

pub fn equals(&self, other: &Fp5Element) -> bool

Checks if two Fp5Element values are equal.

Trait Implementations§

Source§

impl Clone for Fp5Element

Source§

fn clone(&self) -> Fp5Element

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 Debug for Fp5Element

Source§

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

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

impl PartialEq for Fp5Element

Two Fp5 elements are equal iff all five coefficients are equal as field elements (uses canonical Goldilocks comparison).

Source§

fn eq(&self, other: &Self) -> 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 Zeroize for Fp5Element

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

impl Copy for Fp5Element

Source§

impl Eq for Fp5Element

Auto Trait Implementations§

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.