W

Struct W 

Source
pub struct W<F>(/* private fields */);
Expand description

Wraps scalar or field element

Field element and scalar, derived by ff, initially are not compatible with [elliptic-curve] crate and cannot be used together. This struct wraps scalar or field element, and implements required traits.

Implementations§

Source§

impl<F> W<F>

Source

pub const fn new(n: F) -> Self

Wraps n

Source§

impl<F: PrimeField> W<F>

Source

pub fn to_be_bytes(&self) -> F::Repr

Converts integer to byte array in big-endian

Source

pub fn to_le_bytes(&self) -> F::Repr

Converts integer to byte array in little-endian

Source

pub fn from_be_bytes(bytes: F::Repr) -> CtOption<Self>

Constructs integer from its bytes representation in big-endian

Returns None if it overflows maximum allowed value

Source

pub fn from_le_bytes(bytes: F::Repr) -> CtOption<Self>

Constructs integer from its bytes representation in little-endian

Returns None if it overflows maximum allowed value

Source

pub fn from_be_bytes_mod_order(bytes: &[u8]) -> Self

Constructs integer from bytes in big-endian

Integer is reduced modulo max allowed value ($p$ if it’s field element, $n$ if it’s a scalar)

Source

pub fn from_le_bytes_mod_order(bytes: &[u8]) -> Self

Constructs integer from bytes in little-endian

Integer is reduced modulo max allowed value ($p$ if it’s field element, $n$ if it’s a scalar)

Source

pub fn from_uint_mod_order(uint: &U256) -> Self

Constructs integer from U256

Integer is reduced modulo max allowed value ($p$ if it’s field element, $n$ if it’s a scalar)

Source§

impl<F: PrimeField> W<F>
where [u8; 32]: From<F::Repr>,

Source

pub fn to_uint(&self) -> U256

Converts integer to U256

Source§

impl W<FieldElementCore>

Source

pub const ZERO: Self

Field element $x = 0$

Source

pub const ONE: Self

Field element $x = 1$

Source§

impl W<ScalarCore>

Source

pub const ZERO: Self

Scalar $x = 0$

Source

pub const ONE: Self

Scalar $x = 1$

Trait Implementations§

Source§

impl<'r, F: Add<&'r F, Output = F>> Add<&'r W<F>> for W<F>

Source§

type Output = W<F>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &'r W<F>) -> Self::Output

Performs the + operation. Read more
Source§

impl<F: Add<Output = F>> Add for W<F>

Source§

type Output = W<F>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<'r, F: AddAssign<&'r F>> AddAssign<&'r W<F>> for W<F>

Source§

fn add_assign(&mut self, rhs: &'r W<F>)

Performs the += operation. Read more
Source§

impl<F: AddAssign> AddAssign for W<F>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<F> AsRef<W<F>> for W<F>

Source§

fn as_ref(&self) -> &W<F>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<F: Clone> Clone for W<F>

Source§

fn clone(&self) -> W<F>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<F: ConditionallySelectable> ConditionallySelectable for W<F>

Source§

fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self

Select a or b according to choice. Read more
Source§

fn conditional_assign(&mut self, other: &Self, choice: Choice)

Conditionally assign other to self, according to choice. Read more
Source§

fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)

Conditionally swap self and other if choice == 1; otherwise, reassign both unto themselves. Read more
Source§

impl<F: ConstantTimeEq> ConstantTimeEq for W<F>

Source§

fn ct_eq(&self, other: &Self) -> Choice

Determine if two items are equal. Read more
Source§

fn ct_ne(&self, other: &Self) -> Choice

Determine if two items are NOT equal. Read more
Source§

impl<F: Debug> Debug for W<F>

Source§

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

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

impl<F: Default> Default for W<F>

Source§

fn default() -> W<F>

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

impl<F> Deref for W<F>

Source§

type Target = F

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<F> DerefMut for W<F>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<F: Field> Field for W<F>

Source§

const ZERO: Self

The zero element of the field, the additive identity.
Source§

const ONE: Self

The one element of the field, the multiplicative identity.
Source§

fn random(rng: impl RngCore) -> Self

Returns an element chosen uniformly at random using a user-provided RNG.
Source§

fn square(&self) -> Self

Squares this element.
Source§

fn double(&self) -> Self

Doubles this element.
Source§

fn invert(&self) -> CtOption<Self>

Computes the multiplicative inverse of this element, failing if the element is zero.
Source§

fn sqrt(&self) -> CtOption<Self>

Returns the square root of the field element, if it is quadratic residue. Read more
Source§

fn sqrt_ratio(num: &Self, div: &Self) -> (Choice, Self)

Computes: Read more
Source§

fn is_zero(&self) -> Choice

Returns true iff this element is zero.
Source§

fn is_zero_vartime(&self) -> bool

Returns true iff this element is zero. Read more
Source§

fn cube(&self) -> Self

Cubes this element.
Source§

fn sqrt_alt(&self) -> (Choice, Self)

Equivalent to Self::sqrt_ratio(self, one()). Read more
Source§

fn pow<S>(&self, exp: S) -> Self
where S: AsRef<[u64]>,

Exponentiates self by exp, where exp is a little-endian order integer exponent. Read more
Source§

fn pow_vartime<S>(&self, exp: S) -> Self
where S: AsRef<[u64]>,

Exponentiates self by exp, where exp is a little-endian order integer exponent. Read more
Source§

impl From<&W<ScalarCore>> for ScalarPrimitive<StarkCurve>

Source§

fn from(s: &Scalar) -> Self

Converts to this type from the input type.
Source§

impl<F: PrimeField, C: Curve> From<ScalarPrimitive<C>> for W<F>

Source§

fn from(s: ScalarPrimitive<C>) -> Self

Converts to this type from the input type.
Source§

impl<F> From<W<F>> for GenericArray<u8, U32>
where W<F>: PrimeField<Repr = GenericArray<u8, U32>>,

Source§

fn from(s: W<F>) -> Self

Converts to this type from the input type.
Source§

impl<F: PrimeField, const LIMBS: usize> From<W<F>> for Uint<LIMBS>
where Uint<LIMBS>: Encoding, <Uint<LIMBS> as Encoding>::Repr: From<F::Repr>,

Source§

fn from(s: W<F>) -> Self

Converts to this type from the input type.
Source§

impl From<W<ScalarCore>> for ScalarPrimitive<StarkCurve>

Source§

fn from(s: Scalar) -> Self

Converts to this type from the input type.
Source§

impl<F: From<u64>> From<u64> for W<F>

Source§

fn from(n: u64) -> Self

Converts to this type from the input type.
Source§

impl<F: PrimeField> FromUintUnchecked for W<F>

Source§

type Uint = Uint<crypto_bigint::::uint::U256::{constant#0}>

Unsigned integer type (i.e. Curve::Uint)
Source§

fn from_uint_unchecked(uint: Self::Uint) -> Self

Instantiate scalar from an unsigned integer without checking whether the value overflows the field modulus. Read more
Source§

impl<F: Hash> Hash for W<F>

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<F: Field> Invert for W<F>

Source§

type Output = CtOption<W<F>>

Field element type
Source§

fn invert(&self) -> Self::Output

Invert a field element.
Source§

fn invert_vartime(&self) -> Self::Output

Invert a field element in variable time. Read more
Source§

impl<F> IsHigh for W<F>
where F: PrimeField, W<F>: Sub<Output = W<F>>, U256: From<W<F>>,

Source§

fn is_high(&self) -> Choice

Is this scalar greater than or equal to n / 2?
Source§

impl<'r, F: Mul<&'r F, Output = F>> Mul<&'r W<F>> for W<F>

Source§

type Output = W<F>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &'r W<F>) -> Self::Output

Performs the * operation. Read more
Source§

impl<F: Mul<Output = F>> Mul for W<F>

Source§

type Output = W<F>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<'r, F: MulAssign<&'r F>> MulAssign<&'r W<F>> for W<F>

Source§

fn mul_assign(&mut self, rhs: &'r W<F>)

Performs the *= operation. Read more
Source§

impl<F: MulAssign> MulAssign for W<F>

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl<F: Neg<Output = F>> Neg for W<F>

Source§

type Output = W<F>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<F: Ord> Ord for W<F>

Source§

fn cmp(&self, other: &W<F>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<F: PartialEq> PartialEq for W<F>

Source§

fn eq(&self, other: &W<F>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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<F: PartialOrd> PartialOrd for W<F>

Source§

fn partial_cmp(&self, other: &W<F>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<F> PrimeField for W<F>

Source§

const MODULUS: &'static str = F::MODULUS

Modulus of the field written as a string for debugging purposes. Read more
Source§

const NUM_BITS: u32 = F::NUM_BITS

How many bits are needed to represent an element of this field.
Source§

const CAPACITY: u32 = F::CAPACITY

How many bits of information can be reliably stored in the field element. Read more
Source§

const TWO_INV: Self

Inverse of $2$ in the field.
Source§

const MULTIPLICATIVE_GENERATOR: Self

A fixed multiplicative generator of modulus - 1 order. This element must also be a quadratic nonresidue. Read more
Source§

const S: u32 = F::S

An integer s satisfying the equation 2^s * t = modulus - 1 with t odd. Read more
Source§

const ROOT_OF_UNITY: Self

The 2^s root of unity. Read more
Source§

const ROOT_OF_UNITY_INV: Self

Source§

const DELTA: Self

Generator of the t-order multiplicative subgroup. Read more
Source§

type Repr = GenericArray<u8, UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>>

The prime field can be converted back and forth into this binary representation.
Source§

fn from_repr(repr: Self::Repr) -> CtOption<Self>

Attempts to convert a byte representation of a field element into an element of this prime field, failing if the input is not canonical (is not smaller than the field’s modulus). Read more
Source§

fn to_repr(&self) -> Self::Repr

Converts an element of the prime field into the standard byte representation for this field. Read more
Source§

fn is_odd(&self) -> Choice

Returns true iff this element is odd.
Source§

fn from_str_vartime(s: &str) -> Option<Self>

Interpret a string of numbers as a (congruent) prime field element. Does not accept unnecessary leading zeroes or a blank string. Read more
Source§

fn from_u128(v: u128) -> Self

Obtains a field element congruent to the integer v. Read more
Source§

fn from_repr_vartime(repr: Self::Repr) -> Option<Self>

Attempts to convert a byte representation of a field element into an element of this prime field, failing if the input is not canonical (is not smaller than the field’s modulus). Read more
Source§

fn is_even(&self) -> Choice

Returns true iff this element is even.
Source§

impl<'f, F: Product<&'f F>> Product<&'f W<F>> for W<F>

Source§

fn product<I: Iterator<Item = &'f W<F>>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl<F: Product> Product for W<F>

Source§

fn product<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl<F> Reduce<Uint<crypto_bigint::::uint::U256::{constant#0}>> for W<F>
where F: PrimeField, W<F>: PrimeField,

Source§

type Bytes = <W<F> as PrimeField>::Repr

Bytes used as input to Reduce::reduce_bytes.
Source§

fn reduce(n: U256) -> Self

Perform a modular reduction, returning a field element.
Source§

fn reduce_bytes(bytes: &Self::Bytes) -> Self

Interpret the given bytes as an integer and perform a modular reduction.
Source§

impl<F: ShlAssign<usize>> ShlAssign<usize> for W<F>

Source§

fn shl_assign(&mut self, rhs: usize)

Performs the <<= operation. Read more
Source§

impl<F> ShrAssign<usize> for W<F>
where [u8; 32]: From<F::Repr>, F: PrimeField,

Source§

fn shr_assign(&mut self, rhs: usize)

Performs the >>= operation. Read more
Source§

impl<'r, F: Sub<&'r F, Output = F>> Sub<&'r W<F>> for W<F>

Source§

type Output = W<F>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &'r W<F>) -> Self::Output

Performs the - operation. Read more
Source§

impl<F: Sub<Output = F>> Sub for W<F>

Source§

type Output = W<F>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<'r, F: SubAssign<&'r F>> SubAssign<&'r W<F>> for W<F>

Source§

fn sub_assign(&mut self, rhs: &'r W<F>)

Performs the -= operation. Read more
Source§

impl<F: SubAssign> SubAssign for W<F>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<'f, F: Sum<&'f F>> Sum<&'f W<F>> for W<F>

Source§

fn sum<I: Iterator<Item = &'f W<F>>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<F: Sum> Sum for W<F>

Source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<F: Copy> Copy for W<F>

Source§

impl<F: Default + Copy> DefaultIsZeroes for W<F>

Source§

impl<F: Eq> Eq for W<F>

Source§

impl<F> StructuralPartialEq for W<F>

Auto Trait Implementations§

§

impl<F> Freeze for W<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for W<F>
where F: RefUnwindSafe,

§

impl<F> Send for W<F>
where F: Send,

§

impl<F> Sync for W<F>
where F: Sync,

§

impl<F> Unpin for W<F>
where F: Unpin,

§

impl<F> UnwindSafe for W<F>
where F: UnwindSafe,

Blanket Implementations§

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<const N: usize, T> BatchInvert<[T; N]> for T
where T: Invert<Output = CtOption<T>> + Mul<Output = T> + Copy + Default + ConditionallySelectable,

Source§

type Output = [T; N]

The output of batch inversion. A container of field elements.
Source§

fn batch_invert(field_elements: &[T; N]) -> CtOption<[T; N]>

Invert a batch of field elements.
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
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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<Z> Zeroize for Z
where Z: DefaultIsZeroes,

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

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

Source§

impl<T, Rhs, Output> GroupOpsOwned<Rhs, Output> for T
where T: for<'r> GroupOps<&'r Rhs, Output>,

Source§

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

Source§

impl<T, Rhs, Output> ScalarMulOwned<Rhs, Output> for T
where T: for<'r> ScalarMul<&'r Rhs, Output>,