Skip to main content

Scalar

Struct Scalar 

Source
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

Source

pub const ZERO: Self

Additive identity.

Source

pub const ONE: Self

Multiplicative identity.

Source

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.

Source

pub const fn to_limbs(self) -> [u64; 5]

Return the underlying limbs in little-endian order.

Source

pub fn is_canonical(self) -> bool

Test whether this scalar is canonical (self < n).

Source

pub const fn is_zero(self) -> bool

Test whether the scalar is zero.

Source

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

Canonical 40-byte little-endian encoding (5 x 8-byte limbs).

Source

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.

Source

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.

Source

pub fn add_inner(self, rhs: Self) -> Self

Raw 320-bit addition with no modular reduction.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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 Add for Scalar

Source§

type Output = Scalar

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl AddAssign for Scalar

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl Clone for Scalar

Source§

fn clone(&self) -> Scalar

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 Scalar

Source§

impl Debug for Scalar

Source§

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

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

impl Default for Scalar

Source§

fn default() -> Self

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

impl Eq for Scalar

Source§

impl Hash for Scalar

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 Scalar

Source§

type Output = Scalar

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Point> for Scalar

Source§

type Output = Point

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Scalar> for Point

Source§

type Output = Point

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl MulAssign for Scalar

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl Neg for Scalar

Source§

type Output = Scalar

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl PartialEq for Scalar

Source§

fn eq(&self, other: &Scalar) -> 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 Scalar

Source§

impl Sub for Scalar

Source§

type Output = Scalar

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign for Scalar

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more

Auto Trait Implementations§

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