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
impl Fp5Element
Sourcepub fn add(&self, other: &Fp5Element) -> Fp5Element
pub fn add(&self, other: &Fp5Element) -> Fp5Element
Adds two extension field elements.
Addition is performed component-wise on the polynomial coefficients.
Sourcepub fn sub(&self, other: &Fp5Element) -> Fp5Element
pub fn sub(&self, other: &Fp5Element) -> Fp5Element
Subtracts two extension field elements.
Subtraction is performed component-wise on the polynomial coefficients.
Sourcepub fn mul(&self, other: &Fp5Element) -> Fp5Element
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);Sourcepub fn inverse(&self) -> Fp5Element
pub fn inverse(&self) -> Fp5Element
Computes the multiplicative inverse of this element.
Returns zero if this element is zero (which has no inverse).
Sourcepub fn inverse_or_zero(&self) -> Fp5Element
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.
Sourcepub fn frobenius(&self) -> Fp5Element
pub fn frobenius(&self) -> Fp5Element
Applies the Frobenius automorphism once.
The Frobenius automorphism raises each coefficient to the p-th power.
Sourcepub fn repeated_frobenius(&self, count: usize) -> Fp5Element
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.
Sourcepub fn scalar_mul(&self, scalar: &Goldilocks) -> Fp5Element
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.
Sourcepub fn square(&self) -> Fp5Element
pub fn square(&self) -> Fp5Element
Computes the square of this element.
Optimized implementation that uses fewer operations than general multiplication.
Sourcepub fn double(&self) -> Fp5Element
pub fn double(&self) -> Fp5Element
Doubles this element (multiplies by 2).
Sourcepub fn from_uint64_array(arr: [u64; 5]) -> Fp5Element
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]);Sourcepub fn to_bytes_le(&self) -> [u8; 40]
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);Sourcepub fn from_bytes_le(bytes: &[u8]) -> Result<Self, String>
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);Sourcepub fn neg(&self) -> Fp5Element
pub fn neg(&self) -> Fp5Element
Computes the additive inverse (negation) of this element.
Sourcepub fn exp_power_of_2(&self, n: usize) -> Fp5Element
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.
Sourcepub fn sgn0(&self) -> bool
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.
Sourcepub fn sqrt(&self) -> Option<Fp5Element>
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.
Sourcepub fn canonical_sqrt(&self) -> (Fp5Element, bool)
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.
Sourcepub fn legendre(&self) -> Goldilocks
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.
Sourcepub fn equals(&self, other: &Fp5Element) -> bool
pub fn equals(&self, other: &Fp5Element) -> bool
Checks if two Fp5Element values are equal.
Trait Implementations§
Source§impl Clone for Fp5Element
impl Clone for Fp5Element
Source§fn clone(&self) -> Fp5Element
fn clone(&self) -> Fp5Element
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Fp5Element
impl Debug for Fp5Element
Source§impl PartialEq for Fp5Element
Two Fp5 elements are equal iff all five coefficients are equal as field elements
(uses canonical Goldilocks comparison).
impl PartialEq for Fp5Element
Two Fp5 elements are equal iff all five coefficients are equal as field elements (uses canonical Goldilocks comparison).