pub struct Scalar(pub [u64; 5]);Expand description
A scalar in the ECgFp5 curve’s scalar field, stored in non-Montgomery form as five 64-bit little-endian limbs.
Canonical instances (< n) round-trip through every public operation. The
arithmetic primitives add / sub / mul require canonical inputs;
from_le_bytes_reduce handles the wider input range produced by hashing.
Tuple Fields§
§0: [u64; 5]Implementations§
Source§impl Scalar
impl Scalar
Sourcepub const fn from_limbs(limbs: [u64; 5]) -> Self
pub const fn from_limbs(limbs: [u64; 5]) -> Self
Build a scalar from five raw 64-bit limbs without any reduction.
The caller is responsible for ensuring the value is canonical when it
will subsequently feed the modular Add, Sub, Neg or Mul
operators.
Sourcepub fn is_canonical(self) -> bool
pub fn is_canonical(self) -> bool
Test whether this scalar is canonical (self < n).
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).
Sourcepub fn from_le_bytes_reduce(bytes: [u8; 40]) -> Self
pub fn from_le_bytes_reduce(bytes: [u8; 40]) -> Self
Decode 40 little-endian bytes, reducing modulo n if the encoded value
exceeds the canonical range. Mirrors the upstream Lighter helper.
Sourcepub const fn select(c: u64, a0: Self, a1: Self) -> Self
pub const fn select(c: u64, a0: Self, a1: Self) -> Self
Branch-free constant-time select: returns a0 when c == 0 and a1
when c == u64::MAX.
Sourcepub fn sub_inner(self, rhs: Self) -> (Self, u64)
pub fn sub_inner(self, rhs: Self) -> (Self, u64)
Raw 320-bit subtraction with no modular reduction. Returns the
difference and an 0 / u64::MAX mask indicating whether the operation
borrowed beyond the top limb.
Sourcepub fn monty_mul(self, rhs: Self) -> Self
pub fn monty_mul(self, rhs: Self) -> Self
Montgomery multiplication (self * rhs) / 2^320 mod n.
self MUST be canonical. rhs may exceed n provided it fits in 320
bits, mirroring the upstream behaviour used to lift values into
Montgomery form via the R2 constant.
Sourcepub fn from_fp5(e: Fp5) -> Self
pub fn from_fp5(e: Fp5) -> Self
Build a scalar from an Fp5 element via reduction modulo n.
Concatenates the five canonical 64-bit limbs of e into a 320-bit
little-endian integer and reduces, matching the upstream behaviour of
FromGfp5. Used by the Schnorr binding to derive a scalar from a
Poseidon2 digest.
Sourcepub fn split_to_4_bit_limbs(self) -> [u8; 80]
pub fn split_to_4_bit_limbs(self) -> [u8; 80]
Split the canonical scalar value into 80 little-endian 4-bit nibbles.
Iteration order is least-significant nibble first.
Sourcepub fn recode_signed(self, ss: &mut [i32], w: u32)
pub fn recode_signed(self, ss: &mut [i32], w: u32)
Recode the scalar into signed digits for a width-w window.
ss is filled with (2^w + 1)-range signed values (lying in
-(2^(w-1)) ..= 2^(w-1) after carry propagation) so that
sum(ss[i] * 2^(w*i)) == self mod 2^(w * len). When w * len >= 320,
the recoding spans the entire scalar and the top digit is non-negative.
w MUST satisfy 2 <= w <= 10. This helper is variable-time and is
only suitable for non-secret window selection.
Trait Implementations§
Source§impl AddAssign for Scalar
impl AddAssign for Scalar
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreimpl Copy for Scalar
impl Eq for Scalar
Source§impl MulAssign for Scalar
impl MulAssign for Scalar
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreimpl StructuralPartialEq for Scalar
Auto Trait Implementations§
impl Freeze for Scalar
impl RefUnwindSafe for Scalar
impl Send for Scalar
impl Sync for Scalar
impl Unpin for Scalar
impl UnsafeUnpin for Scalar
impl UnwindSafe for Scalar
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