pub struct UnsignedInteger<const NUM_LIMBS: usize> {
    pub limbs: [u64; NUM_LIMBS],
}
Expand description

A big unsigned integer in base 2^{64} represented as fixed-size array limbs of u64 components. The most significant bit is in the left-most position. That is, the array [a_n, ..., a_0] represents the integer 2^{64 * n} * a_n + … + 2^{64} * a_1 + a_0.

Fields§

§limbs: [u64; NUM_LIMBS]

Implementations§

source§

impl<const NUM_LIMBS: usize> UnsignedInteger<NUM_LIMBS>

source

pub const fn from_limbs(limbs: [u64; NUM_LIMBS]) -> Self

source

pub const fn from_u64(value: u64) -> Self

source

pub const fn from_u128(value: u128) -> Self

source

pub fn from_hex(value: &str) -> Result<Self, CreationError>

Creates an UnsignedInteger from a hexstring. It can contain 0x or not. Returns an CreationError::InvalidHexStringif the value is not a hexstring. Returns a CreationError::EmptyString if the input string is empty. Returns a CreationError::HexStringIsTooBig if the the input hex string is bigger than the maximum amount of characters for this element.

source

pub const fn from_hex_unchecked(value: &str) -> Self

Creates an UnsignedInteger from a hexstring

§Panics

Panics if value is not a hexstring. It can contain 0x or not.

source

pub fn to_hex(&self) -> String

Creates a hexstring from a FieldElement without 0x.

source

pub const fn const_ne( a: &UnsignedInteger<NUM_LIMBS>, b: &UnsignedInteger<NUM_LIMBS>, ) -> bool

source

pub const fn const_le( a: &UnsignedInteger<NUM_LIMBS>, b: &UnsignedInteger<NUM_LIMBS>, ) -> bool

source

pub const fn const_shl(self, times: usize) -> Self

source

pub const fn const_shr(self, times: usize) -> UnsignedInteger<NUM_LIMBS>

source

pub const fn add( a: &UnsignedInteger<NUM_LIMBS>, b: &UnsignedInteger<NUM_LIMBS>, ) -> (UnsignedInteger<NUM_LIMBS>, bool)

source

pub fn double( a: &UnsignedInteger<NUM_LIMBS>, ) -> (UnsignedInteger<NUM_LIMBS>, bool)

source

pub fn double_in_place(&mut self) -> bool

source

pub const fn sub( a: &UnsignedInteger<NUM_LIMBS>, b: &UnsignedInteger<NUM_LIMBS>, ) -> (UnsignedInteger<NUM_LIMBS>, bool)

Multi-precision subtraction. Adapted from Algorithm 14.9 of “Handbook of Applied Cryptography” (https://cacr.uwaterloo.ca/hac/) Returns the results and a flag that is set if the substraction underflowed

source

pub const fn mul( a: &UnsignedInteger<NUM_LIMBS>, b: &UnsignedInteger<NUM_LIMBS>, ) -> (UnsignedInteger<NUM_LIMBS>, UnsignedInteger<NUM_LIMBS>)

Multi-precision multiplication. Adapted from Algorithm 14.12 of “Handbook of Applied Cryptography” (https://cacr.uwaterloo.ca/hac/)

source

pub fn square( a: &UnsignedInteger<NUM_LIMBS>, ) -> (UnsignedInteger<NUM_LIMBS>, UnsignedInteger<NUM_LIMBS>)

source

pub const fn bits(&self) -> u32

Returns the number of bits needed to represent the number (0 for zero). If nonzero, this is equivalent to one plus the floored log2 of the number.

source

pub fn sbb(&self, rhs: &Self, borrow: u64) -> (Self, u64)

Computes a - (b + borrow), returning the result along with the new borrow.

source

pub const fn bits_le(&self) -> usize

Returns the number of bits needed to represent the number as little endian

source

pub fn div_rem(&self, rhs: &Self) -> (Self, Self)

Computes self / rhs, returns the quotient, remainder.

source

pub fn from_dec_str(value: &str) -> Result<Self, CreationError>

Convert from a decimal string.

Trait Implementations§

source§

impl<const NUM_LIMBS: usize> Add<&UnsignedInteger<NUM_LIMBS>> for &UnsignedInteger<NUM_LIMBS>

source§

type Output = UnsignedInteger<NUM_LIMBS>

The resulting type after applying the + operator.
source§

fn add(self, other: &UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>

Performs the + operation. Read more
source§

impl<const NUM_LIMBS: usize> Add<&UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>

source§

type Output = UnsignedInteger<NUM_LIMBS>

The resulting type after applying the + operator.
source§

fn add(self, other: &Self) -> Self

Performs the + operation. Read more
source§

impl<const NUM_LIMBS: usize> Add<UnsignedInteger<NUM_LIMBS>> for &UnsignedInteger<NUM_LIMBS>

source§

type Output = UnsignedInteger<NUM_LIMBS>

The resulting type after applying the + operator.
source§

fn add(self, other: UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>

Performs the + operation. Read more
source§

impl<const NUM_LIMBS: usize> Add for UnsignedInteger<NUM_LIMBS>

source§

type Output = UnsignedInteger<NUM_LIMBS>

The resulting type after applying the + operator.
source§

fn add(self, other: UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>

Performs the + operation. Read more
source§

impl<const NUM_LIMBS: usize> AsBytes for UnsignedInteger<NUM_LIMBS>

source§

fn as_bytes(&self) -> Vec<u8>

Default serialize without args
source§

impl<const NUM_LIMBS: usize> BitAnd for UnsignedInteger<NUM_LIMBS>

Impl BitAnd

source§

type Output = UnsignedInteger<NUM_LIMBS>

The resulting type after applying the & operator.
source§

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

Performs the & operation. Read more
source§

impl<const NUM_LIMBS: usize> BitAndAssign for UnsignedInteger<NUM_LIMBS>

source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
source§

impl<const NUM_LIMBS: usize> BitOr for UnsignedInteger<NUM_LIMBS>

Impl BitOr

source§

type Output = UnsignedInteger<NUM_LIMBS>

The resulting type after applying the | operator.
source§

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

Performs the | operation. Read more
source§

impl<const NUM_LIMBS: usize> BitOrAssign for UnsignedInteger<NUM_LIMBS>

source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
source§

impl<const NUM_LIMBS: usize> BitXor for UnsignedInteger<NUM_LIMBS>

Impl BitXor

source§

type Output = UnsignedInteger<NUM_LIMBS>

The resulting type after applying the ^ operator.
source§

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

Performs the ^ operation. Read more
source§

impl<const NUM_LIMBS: usize> BitXorAssign for UnsignedInteger<NUM_LIMBS>

source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
source§

impl<const NUM_LIMBS: usize> ByteConversion for UnsignedInteger<NUM_LIMBS>

source§

fn to_bytes_be(&self) -> Vec<u8>

Returns the byte representation of the element in big-endian order.}
source§

fn to_bytes_le(&self) -> Vec<u8>

Returns the byte representation of the element in little-endian order.
source§

fn from_bytes_be(bytes: &[u8]) -> Result<Self, ByteConversionError>

Returns the element from its byte representation in big-endian order.
source§

fn from_bytes_le(bytes: &[u8]) -> Result<Self, ByteConversionError>

Returns the element from its byte representation in little-endian order.
source§

impl<const NUM_LIMBS: usize> Clone for UnsignedInteger<NUM_LIMBS>

source§

fn clone(&self) -> UnsignedInteger<NUM_LIMBS>

Returns a copy 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<const NUM_LIMBS: usize> Debug for UnsignedInteger<NUM_LIMBS>

source§

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

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

impl<const NUM_LIMBS: usize> Display for UnsignedInteger<NUM_LIMBS>

source§

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

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

impl<const NUM_LIMBS: usize> From<&str> for UnsignedInteger<NUM_LIMBS>

source§

fn from(hex_str: &str) -> Self

Converts to this type from the input type.
source§

impl<const NUM_LIMBS: usize> From<UnsignedInteger<NUM_LIMBS>> for Vec<u8>

source§

fn from(val: UnsignedInteger<NUM_LIMBS>) -> Self

Converts to this type from the input type.
source§

impl<const NUM_LIMBS: usize> From<UnsignedInteger<NUM_LIMBS>> for u16

source§

fn from(value: UnsignedInteger<NUM_LIMBS>) -> Self

Converts to this type from the input type.
source§

impl<const NUM_LIMBS: usize> From<u128> for UnsignedInteger<NUM_LIMBS>

source§

fn from(value: u128) -> Self

Converts to this type from the input type.
source§

impl<const NUM_LIMBS: usize> From<u16> for UnsignedInteger<NUM_LIMBS>

source§

fn from(value: u16) -> Self

Converts to this type from the input type.
source§

impl<const NUM_LIMBS: usize> From<u64> for UnsignedInteger<NUM_LIMBS>

source§

fn from(value: u64) -> Self

Converts to this type from the input type.
source§

impl<const NUM_LIMBS: usize> Hash for UnsignedInteger<NUM_LIMBS>

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 IsModulus<UnsignedInteger<1>> for MontgomeryConfigBabybear31PrimeField

source§

const MODULUS: U64 = _

source§

impl IsModulus<UnsignedInteger<1>> for MontgomeryConfigMersenne31PrimeField

source§

const MODULUS: U64 = _

source§

impl IsModulus<UnsignedInteger<1>> for MontgomeryConfigU64GoldilocksPrimeField

source§

const MODULUS: U64 = _

source§

impl IsModulus<UnsignedInteger<4>> for BN254FieldModulus

source§

const MODULUS: U256 = BN254_PRIME_FIELD_ORDER

source§

impl IsModulus<UnsignedInteger<4>> for FqConfig

source§

const MODULUS: U256 = BANDERSNATCH_PRIME_FIELD_ORDER

source§

impl IsModulus<UnsignedInteger<4>> for FrConfig

Modulus of bls 12 381 subgroup

source§

impl IsModulus<UnsignedInteger<4>> for FrConfig

Modulus of bn 254 subgroup r = 21888242871839275222246405745257275088548364400416034343698204186575808495617, aka order

source§

impl IsModulus<UnsignedInteger<4>> for FrConfig

Modulus (Order) of Grumpkin Fr

source§

impl IsModulus<UnsignedInteger<4>> for GrumpkinFieldModulus

source§

const MODULUS: U256 = GRUMPKIN_PRIME_FIELD_ORDER

source§

impl IsModulus<UnsignedInteger<4>> for MontgomeryConfigPallas255PrimeField

source§

impl IsModulus<UnsignedInteger<4>> for MontgomeryConfigStark252PrimeField

source§

impl IsModulus<UnsignedInteger<4>> for MontgomeryConfigVesta255PrimeField

source§

impl IsModulus<UnsignedInteger<6>> for BLS12377FieldModulus

source§

const MODULUS: U384 = BLS12377_PRIME_FIELD_ORDER

source§

impl IsModulus<UnsignedInteger<6>> for BLS12381FieldModulus

source§

const MODULUS: U384 = BLS12381_PRIME_FIELD_ORDER

source§

impl IsModulus<UnsignedInteger<6>> for TestCurve2Modulus

source§

const MODULUS: U384 = TEST_CURVE_2_PRIME_FIELD_ORDER

source§

impl<const NUM_LIMBS: usize> Mul<&UnsignedInteger<NUM_LIMBS>> for &UnsignedInteger<NUM_LIMBS>

Multi-precision multiplication. Algorithm 14.12 of “Handbook of Applied Cryptography” (https://cacr.uwaterloo.ca/hac/)

source§

type Output = UnsignedInteger<NUM_LIMBS>

The resulting type after applying the * operator.
source§

fn mul(self, other: &UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>

Performs the * operation. Read more
source§

impl<const NUM_LIMBS: usize> Mul<&UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>

source§

type Output = UnsignedInteger<NUM_LIMBS>

The resulting type after applying the * operator.
source§

fn mul(self, other: &Self) -> Self

Performs the * operation. Read more
source§

impl<const NUM_LIMBS: usize> Mul<UnsignedInteger<NUM_LIMBS>> for &UnsignedInteger<NUM_LIMBS>

source§

type Output = UnsignedInteger<NUM_LIMBS>

The resulting type after applying the * operator.
source§

fn mul(self, other: UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>

Performs the * operation. Read more
source§

impl<const NUM_LIMBS: usize> Mul for UnsignedInteger<NUM_LIMBS>

source§

type Output = UnsignedInteger<NUM_LIMBS>

The resulting type after applying the * operator.
source§

fn mul(self, other: UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>

Performs the * operation. Read more
source§

impl<const NUM_LIMBS: usize> Ord for UnsignedInteger<NUM_LIMBS>

source§

fn cmp(&self, other: &Self) -> 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 + PartialOrd,

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

impl<const NUM_LIMBS: usize> PartialEq for UnsignedInteger<NUM_LIMBS>

source§

fn eq(&self, other: &UnsignedInteger<NUM_LIMBS>) -> 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<const NUM_LIMBS: usize> PartialOrd for UnsignedInteger<NUM_LIMBS>

source§

fn partial_cmp(&self, other: &Self) -> 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<const NUM_LIMBS: usize> Shl<usize> for &UnsignedInteger<NUM_LIMBS>

source§

type Output = UnsignedInteger<NUM_LIMBS>

The resulting type after applying the << operator.
source§

fn shl(self, times: usize) -> UnsignedInteger<NUM_LIMBS>

Performs the << operation. Read more
source§

impl<const NUM_LIMBS: usize> Shl<usize> for UnsignedInteger<NUM_LIMBS>

source§

type Output = UnsignedInteger<NUM_LIMBS>

The resulting type after applying the << operator.
source§

fn shl(self, times: usize) -> UnsignedInteger<NUM_LIMBS>

Performs the << operation. Read more
source§

impl<const NUM_LIMBS: usize> Shr<usize> for &UnsignedInteger<NUM_LIMBS>

source§

type Output = UnsignedInteger<NUM_LIMBS>

The resulting type after applying the >> operator.
source§

fn shr(self, times: usize) -> UnsignedInteger<NUM_LIMBS>

Performs the >> operation. Read more
source§

impl<const NUM_LIMBS: usize> Shr<usize> for UnsignedInteger<NUM_LIMBS>

source§

type Output = UnsignedInteger<NUM_LIMBS>

The resulting type after applying the >> operator.
source§

fn shr(self, times: usize) -> UnsignedInteger<NUM_LIMBS>

Performs the >> operation. Read more
source§

impl<const NUM_LIMBS: usize> ShrAssign<usize> for UnsignedInteger<NUM_LIMBS>

source§

fn shr_assign(&mut self, times: usize)

Performs the >>= operation. Read more
source§

impl<const NUM_LIMBS: usize> Sub<&UnsignedInteger<NUM_LIMBS>> for &UnsignedInteger<NUM_LIMBS>

source§

type Output = UnsignedInteger<NUM_LIMBS>

The resulting type after applying the - operator.
source§

fn sub(self, other: &UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>

Performs the - operation. Read more
source§

impl<const NUM_LIMBS: usize> Sub<&UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>

source§

type Output = UnsignedInteger<NUM_LIMBS>

The resulting type after applying the - operator.
source§

fn sub(self, other: &Self) -> Self

Performs the - operation. Read more
source§

impl<const NUM_LIMBS: usize> Sub<UnsignedInteger<NUM_LIMBS>> for &UnsignedInteger<NUM_LIMBS>

source§

type Output = UnsignedInteger<NUM_LIMBS>

The resulting type after applying the - operator.
source§

fn sub(self, other: UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>

Performs the - operation. Read more
source§

impl<const NUM_LIMBS: usize> Sub for UnsignedInteger<NUM_LIMBS>

source§

type Output = UnsignedInteger<NUM_LIMBS>

The resulting type after applying the - operator.
source§

fn sub(self, other: UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>

Performs the - operation. Read more
source§

impl<const NUM_LIMBS: usize> Copy for UnsignedInteger<NUM_LIMBS>

source§

impl<const NUM_LIMBS: usize> Eq for UnsignedInteger<NUM_LIMBS>

source§

impl<const NUM_LIMBS: usize> IsUnsignedInteger for UnsignedInteger<NUM_LIMBS>

source§

impl<const NUM_LIMBS: usize> StructuralPartialEq for UnsignedInteger<NUM_LIMBS>

Auto Trait Implementations§

§

impl<const NUM_LIMBS: usize> Freeze for UnsignedInteger<NUM_LIMBS>

§

impl<const NUM_LIMBS: usize> RefUnwindSafe for UnsignedInteger<NUM_LIMBS>

§

impl<const NUM_LIMBS: usize> Send for UnsignedInteger<NUM_LIMBS>

§

impl<const NUM_LIMBS: usize> Sync for UnsignedInteger<NUM_LIMBS>

§

impl<const NUM_LIMBS: usize> Unpin for UnsignedInteger<NUM_LIMBS>

§

impl<const NUM_LIMBS: usize> UnwindSafe for UnsignedInteger<NUM_LIMBS>

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<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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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<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
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
source§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.