pub struct Fp(/* private fields */);Expand description
An element of the Goldilocks field Fp = GF(p).
The wrapped u64 holds the value in Montgomery form (x * 2^64 mod p),
always reduced into 0..p-1. Two Fp instances are equal iff their
Montgomery limbs are equal, so PartialEq is correct and constant-time.
Implementations§
Source§impl Fp
impl Fp
Sourcepub const fn from_u64_reduce(v: u64) -> Self
pub const fn from_u64_reduce(v: u64) -> Self
Build an element from a u64, reducing modulo p.
Sourcepub fn from_u64_canonical(v: u64) -> Option<Self>
pub fn from_u64_canonical(v: u64) -> Option<Self>
Build an element from an already-canonical u64 (v < p); returns None otherwise.
Sourcepub fn try_from_le_bytes(bytes: [u8; 8]) -> Option<Self>
pub fn try_from_le_bytes(bytes: [u8; 8]) -> Option<Self>
Decode an element from 8 little-endian bytes.
Returns None if the encoded integer is not in canonical range (>= p).
Sourcepub fn to_le_bytes(self) -> [u8; 8]
pub fn to_le_bytes(self) -> [u8; 8]
Canonical 8-byte little-endian encoding.
Sourcepub const fn ct_eq(self, rhs: Self) -> u64
pub const fn ct_eq(self, rhs: Self) -> u64
Constant-time equality: returns 0xFFFF_FFFF_FFFF_FFFF on equality, 0 otherwise.
Sourcepub const fn ct_select(mask: u64, a: Self, b: Self) -> Self
pub const fn ct_select(mask: u64, a: Self, b: Self) -> Self
Branch-free select: returns a when mask == 0 and b when
mask == u64::MAX. Behaviour for any other mask value is unspecified;
the secret-scalar curve primitives only ever pass full-bit masks.
Sourcepub fn invert(self) -> Self
pub fn invert(self) -> Self
Multiplicative inverse via Fermat’s little theorem: x^(p-2).
Returns Fp::ZERO when called on zero (no panic), matching the
“inverse-or-zero” convention used by the upstream reference impls.
Sourcepub fn pow(self, exp: u64) -> Self
pub fn pow(self, exp: u64) -> Self
Exponentiation by an unsigned 64-bit integer, via right-to-left square-and-multiply.
Sourcepub fn sqrt(self) -> Option<Self>
pub fn sqrt(self) -> Option<Self>
Square root in Fp.
Returns Some(s) such that s^2 == self when one exists (with the zero
element returning Some(Self::ZERO)); returns None for non-squares.
Picks one of the two roots: callers wanting a fixed sign must apply
their own normalization on top.
Implementation is Tonelli-Shanks specialized to the Goldilocks
p - 1 = 2^32 * (2^32 - 1) factorization, with the precomputed
2^32-th root-of-unity generator POWER_OF_TWO_GENERATOR standing in
for z.
Trait Implementations§
Source§impl AddAssign for Fp
impl AddAssign for Fp
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreimpl Copy for Fp
impl Eq for Fp
Source§impl MulAssign for Fp
impl MulAssign for Fp
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreimpl StructuralPartialEq for Fp
Auto Trait Implementations§
impl Freeze for Fp
impl RefUnwindSafe for Fp
impl Send for Fp
impl Sync for Fp
impl Unpin for Fp
impl UnsafeUnpin for Fp
impl UnwindSafe for Fp
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