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 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

source

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

Creates an UnsignedInteger from a hexstring

Panics

Panics if value is not a hexstring. Shouldn’t start with 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 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.

Trait Implementations§

source§

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

§

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>

§

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>

§

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>

§

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> BitAnd<UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>

Impl BitAnd

§

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<UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>

source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
source§

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

Impl BitOr

§

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<UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>

source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
source§

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

Impl BitXor

§

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<UnsignedInteger<NUM_LIMBS>> 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 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<4>> for FrConfig

Modulus of bls 12 381 subgroup

source§

impl IsModulus<UnsignedInteger<4>> for MontgomeryConfigStark252PrimeField

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/)

§

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>

§

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>

§

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>

§

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) -> Selfwhere Self: Sized,

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

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

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

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

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

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

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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<UnsignedInteger<NUM_LIMBS>> 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

This method 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

This method 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

This method 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

This method 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>

§

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>

§

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>

§

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>

§

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>

§

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>

§

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>

§

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>

§

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> StructuralEq for UnsignedInteger<NUM_LIMBS>

source§

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

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.