Skip to main content

Fp5

Struct Fp5 

Source
pub struct Fp5(pub [Fp; 5]);
Expand description

An element of Fp5 = GF(p^5).

Tuple Fields§

§0: [Fp; 5]

Implementations§

Source§

impl Fp5

Source

pub const ZERO: Self

Additive identity.

Source

pub const ONE: Self

Multiplicative identity.

Source

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.

Source

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.

Source

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

Source

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

Canonical 40-byte little-endian encoding (5 x 8-byte limbs, low-to-high degree).

Source

pub fn is_zero(self) -> bool

Test whether the element is zero.

Source

pub fn ct_eq(self, rhs: Self) -> u64

Constant-time equality: returns 0xFFFF_FFFF_FFFF_FFFF on equality, 0 otherwise.

Source

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.

Source

pub fn square(self) -> Self

Squaring in Fp5.

Source

pub fn msquare(self, n: u32) -> Self

Repeated squaring: returns self^(2^n).

Source

pub fn double(self) -> Self

Double in Fp5: returns self + self.

Source

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.

Source

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

Source

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.

Source

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

Source

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.

Source

pub fn pow(self, exp: u64) -> Self

Exponentiation by an unsigned 64-bit integer, via right-to-left square-and-multiply.

Trait Implementations§

Source§

impl Add for Fp5

Source§

type Output = Fp5

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
Source§

impl AddAssign for Fp5

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl Clone for Fp5

Source§

fn clone(&self) -> Fp5

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Fp5

Source§

impl Debug for Fp5

Source§

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

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

impl Default for Fp5

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Fp5

Source§

impl Hash for Fp5

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Mul for Fp5

Source§

type Output = Fp5

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self

Performs the * operation. Read more
Source§

impl MulAssign for Fp5

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl Neg for Fp5

Source§

type Output = Fp5

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl PartialEq for Fp5

Source§

fn eq(&self, other: &Fp5) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 StructuralPartialEq for Fp5

Source§

impl Sub for Fp5

Source§

type Output = Fp5

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
Source§

impl SubAssign for Fp5

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more

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
where T: RefUnwindSafe + Send + Sync,

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
§

impl<T> DynEq for T
where T: Eq + Any,

§

fn dyn_eq(&self, other: &(dyn Any + 'static)) -> bool

§

impl<T> DynHash for T
where T: Hash + Any,

§

fn dyn_hash(&self, state: &mut dyn Hasher)

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, Rhs, Output> GroupOps<Rhs, Output> for T
where T: Add<Rhs, Output = Output> + Sub<Rhs, Output = Output> + AddAssign<Rhs> + SubAssign<Rhs>,

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, Rhs, Output> ScalarMul<Rhs, Output> for T
where T: Mul<Rhs, Output = Output> + MulAssign<Rhs>,

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

impl<T> Ungil for T
where T: Send,

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more