pub struct Fp5(pub [Fp; 5]);Expand description
An element of Fp5 = GF(p^5).
Tuple Fields§
§0: [Fp; 5]Implementations§
Source§impl Fp5
impl Fp5
Sourcepub const fn from_u64s_reduce(c: [u64; 5]) -> Self
pub const fn from_u64s_reduce(c: [u64; 5]) -> Self
Build an element from five u64 coefficients (low-to-high degree), each reduced mod p.
Sourcepub fn from_u64s_canonical(c: [u64; 5]) -> Option<Self>
pub fn from_u64s_canonical(c: [u64; 5]) -> Option<Self>
Build an element from five canonical u64 coefficients; returns None
if any coefficient is >= p.
Sourcepub fn try_from_le_bytes(bytes: [u8; 40]) -> Option<Self>
pub fn try_from_le_bytes(bytes: [u8; 40]) -> Option<Self>
Decode an element from 40 little-endian bytes (5 x 8-byte canonical limbs).
Returns None if any limb is non-canonical (>= p).
Sourcepub fn to_le_bytes(self) -> [u8; 40]
pub fn to_le_bytes(self) -> [u8; 40]
Canonical 40-byte little-endian encoding (5 x 8-byte limbs, low-to-high degree).
Sourcepub fn ct_eq(self, rhs: Self) -> u64
pub fn ct_eq(self, rhs: Self) -> u64
Constant-time equality: returns 0xFFFF_FFFF_FFFF_FFFF on equality, 0 otherwise.
Sourcepub fn ct_select(mask: u64, a: Self, b: Self) -> Self
pub fn ct_select(mask: u64, a: Self, b: Self) -> Self
Branch-free select: returns a when mask == 0 and b when
mask == u64::MAX. Composed coefficient-wise from Fp::ct_select;
the secret-scalar curve primitives only ever pass full-bit masks.
Sourcepub fn sgn0(self) -> bool
pub fn sgn0(self) -> bool
Sign indicator following the elliottech Go reference convention. Used
by Self::canonical_sqrt to fix the sign of square roots.
The latch sign = sign || (zero && sign_i) with sign_i = (limb is even) reproduces the upstream behaviour bit-for-bit, including a
known wrinkle: an element whose first non-zero coefficient is preceded
by zero coefficients (e.g. [0, 1, 0, 0, 0]) reports true because a
leading zero satisfies sign_i. This wrinkle has no observable effect
on super::super::curve’s Point::decode: a flipped r swaps
x1/x2 contents, the subsequent Legendre check then re-selects the
same non-square root, and the resulting x is identical. Phase E
Layer 2 oracle tests against the Lighter Python SDK gate any
divergence from the closed-source mainnet signer.
Sourcepub fn legendre(self) -> Fp
pub fn legendre(self) -> Fp
Legendre symbol of self in Fp5, returned as a base-field element.
Returns Fp::ZERO for the zero element, Fp::ONE for non-zero squares,
and Fp::MINUS_ONE for non-squares. Uses the Itoh-Tsujii descent into
Fp followed by Euler’s criterion split as x^(2^63) / x^(2^31).
Sourcepub fn sqrt(self) -> Option<Self>
pub fn sqrt(self) -> Option<Self>
Square root in Fp5 via descent to Fp.
Returns Some(s) such that s^2 == self when one exists (Some(ZERO)
for the zero input); returns None for non-squares. The chosen root is
arbitrary within the two square roots; use Self::canonical_sqrt for
a deterministic sign.
Sourcepub fn canonical_sqrt(self) -> Option<Self>
pub fn canonical_sqrt(self) -> Option<Self>
Canonical-sign square root: same as Self::sqrt, with the result
negated whenever its first non-zero coefficient is even (per Self::sgn0).
Sourcepub fn invert(self) -> Self
pub fn invert(self) -> Self
Multiplicative inverse via Itoh-Tsujii. Returns Fp5::ZERO on input zero.
With r = 1 + p + p^2 + p^3 + p^4, the value x^r lands in the base
field Fp, so we compute x^(r-1) cheaply via Frobenius, recover
x^r = x_0 * x^(r-1)|_0 inside Fp, and divide. The branch-free
shape preserves the module’s constant-time contract: a zero input
flows through the Frobenius cascade as zero and Fp::invert(0) = 0
folds back into a zero result without an early return.
Trait Implementations§
Source§impl AddAssign for Fp5
impl AddAssign for Fp5
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreimpl Copy for Fp5
impl Eq for Fp5
Source§impl MulAssign for Fp5
impl MulAssign for Fp5
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreimpl StructuralPartialEq for Fp5
Auto Trait Implementations§
impl Freeze for Fp5
impl RefUnwindSafe for Fp5
impl Send for Fp5
impl Sync for Fp5
impl Unpin for Fp5
impl UnsafeUnpin for Fp5
impl UnwindSafe for Fp5
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
impl<T, Rhs, Output> GroupOps<Rhs, Output> for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more