Struct lambdaworks_math::unsigned_integer::element::UnsignedInteger
source · 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>
impl<const NUM_LIMBS: usize> UnsignedInteger<NUM_LIMBS>
pub const fn from_limbs(limbs: [u64; NUM_LIMBS]) -> Self
pub const fn from_u64(value: u64) -> Self
pub const fn from_u128(value: u128) -> Self
sourcepub fn from_hex(value: &str) -> Result<Self, CreationError>
pub fn from_hex(value: &str) -> Result<Self, CreationError>
Creates an UnsignedInteger
from a hexstring. It can contain 0x
or not.
Returns an CreationError::InvalidHexString
if 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.
sourcepub const fn from_hex_unchecked(value: &str) -> Self
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.
pub const fn const_ne( a: &UnsignedInteger<NUM_LIMBS>, b: &UnsignedInteger<NUM_LIMBS>, ) -> bool
pub const fn const_le( a: &UnsignedInteger<NUM_LIMBS>, b: &UnsignedInteger<NUM_LIMBS>, ) -> bool
pub const fn const_shl(self, times: usize) -> Self
pub const fn const_shr(self, times: usize) -> UnsignedInteger<NUM_LIMBS>
pub const fn add( a: &UnsignedInteger<NUM_LIMBS>, b: &UnsignedInteger<NUM_LIMBS>, ) -> (UnsignedInteger<NUM_LIMBS>, bool)
pub fn double( a: &UnsignedInteger<NUM_LIMBS>, ) -> (UnsignedInteger<NUM_LIMBS>, bool)
pub fn double_in_place(&mut self) -> bool
sourcepub const fn sub(
a: &UnsignedInteger<NUM_LIMBS>,
b: &UnsignedInteger<NUM_LIMBS>,
) -> (UnsignedInteger<NUM_LIMBS>, bool)
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
sourcepub const fn mul(
a: &UnsignedInteger<NUM_LIMBS>,
b: &UnsignedInteger<NUM_LIMBS>,
) -> (UnsignedInteger<NUM_LIMBS>, UnsignedInteger<NUM_LIMBS>)
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/)
pub fn square( a: &UnsignedInteger<NUM_LIMBS>, ) -> (UnsignedInteger<NUM_LIMBS>, UnsignedInteger<NUM_LIMBS>)
sourcepub const fn bits(&self) -> u32
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.
sourcepub fn sbb(&self, rhs: &Self, borrow: u64) -> (Self, u64)
pub fn sbb(&self, rhs: &Self, borrow: u64) -> (Self, u64)
Computes a - (b + borrow)
, returning the result along with the new borrow.
sourcepub const fn bits_le(&self) -> usize
pub const fn bits_le(&self) -> usize
Returns the number of bits needed to represent the number as little endian
sourcepub fn div_rem(&self, rhs: &Self) -> (Self, Self)
pub fn div_rem(&self, rhs: &Self) -> (Self, Self)
Computes self / rhs, returns the quotient, remainder.
sourcepub fn from_dec_str(value: &str) -> Result<Self, CreationError>
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>
impl<const NUM_LIMBS: usize> Add<&UnsignedInteger<NUM_LIMBS>> for &UnsignedInteger<NUM_LIMBS>
source§type Output = UnsignedInteger<NUM_LIMBS>
type Output = UnsignedInteger<NUM_LIMBS>
+
operator.source§fn add(self, other: &UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>
fn add(self, other: &UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>
+
operation. Read moresource§impl<const NUM_LIMBS: usize> Add<&UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Add<&UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>
source§impl<const NUM_LIMBS: usize> Add<UnsignedInteger<NUM_LIMBS>> for &UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Add<UnsignedInteger<NUM_LIMBS>> for &UnsignedInteger<NUM_LIMBS>
source§type Output = UnsignedInteger<NUM_LIMBS>
type Output = UnsignedInteger<NUM_LIMBS>
+
operator.source§fn add(self, other: UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>
fn add(self, other: UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>
+
operation. Read moresource§impl<const NUM_LIMBS: usize> Add for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Add for UnsignedInteger<NUM_LIMBS>
source§type Output = UnsignedInteger<NUM_LIMBS>
type Output = UnsignedInteger<NUM_LIMBS>
+
operator.source§fn add(self, other: UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>
fn add(self, other: UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>
+
operation. Read moresource§impl<const NUM_LIMBS: usize> AsBytes for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> AsBytes for UnsignedInteger<NUM_LIMBS>
source§impl<const NUM_LIMBS: usize> BitAnd for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> BitAnd for UnsignedInteger<NUM_LIMBS>
Impl BitAnd
source§impl<const NUM_LIMBS: usize> BitAndAssign for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> BitAndAssign for UnsignedInteger<NUM_LIMBS>
source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&=
operation. Read moresource§impl<const NUM_LIMBS: usize> BitOr for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> BitOr for UnsignedInteger<NUM_LIMBS>
Impl BitOr
source§impl<const NUM_LIMBS: usize> BitOrAssign for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> BitOrAssign for UnsignedInteger<NUM_LIMBS>
source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|=
operation. Read moresource§impl<const NUM_LIMBS: usize> BitXor for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> BitXor for UnsignedInteger<NUM_LIMBS>
Impl BitXor
source§impl<const NUM_LIMBS: usize> BitXorAssign for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> BitXorAssign for UnsignedInteger<NUM_LIMBS>
source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^=
operation. Read moresource§impl<const NUM_LIMBS: usize> ByteConversion for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> ByteConversion for UnsignedInteger<NUM_LIMBS>
source§fn to_bytes_be(&self) -> Vec<u8>
fn to_bytes_be(&self) -> Vec<u8>
source§fn to_bytes_le(&self) -> Vec<u8>
fn to_bytes_le(&self) -> Vec<u8>
source§fn from_bytes_be(bytes: &[u8]) -> Result<Self, ByteConversionError>
fn from_bytes_be(bytes: &[u8]) -> Result<Self, ByteConversionError>
source§fn from_bytes_le(bytes: &[u8]) -> Result<Self, ByteConversionError>
fn from_bytes_le(bytes: &[u8]) -> Result<Self, ByteConversionError>
source§impl<const NUM_LIMBS: usize> Clone for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Clone for UnsignedInteger<NUM_LIMBS>
source§fn clone(&self) -> UnsignedInteger<NUM_LIMBS>
fn clone(&self) -> UnsignedInteger<NUM_LIMBS>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<const NUM_LIMBS: usize> Debug for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Debug for UnsignedInteger<NUM_LIMBS>
source§impl<const NUM_LIMBS: usize> Display for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Display for UnsignedInteger<NUM_LIMBS>
source§impl<const NUM_LIMBS: usize> From<UnsignedInteger<NUM_LIMBS>> for Vec<u8>
impl<const NUM_LIMBS: usize> From<UnsignedInteger<NUM_LIMBS>> for Vec<u8>
source§fn from(val: UnsignedInteger<NUM_LIMBS>) -> Self
fn from(val: UnsignedInteger<NUM_LIMBS>) -> Self
source§impl<const NUM_LIMBS: usize> From<UnsignedInteger<NUM_LIMBS>> for u16
impl<const NUM_LIMBS: usize> From<UnsignedInteger<NUM_LIMBS>> for u16
source§fn from(value: UnsignedInteger<NUM_LIMBS>) -> Self
fn from(value: UnsignedInteger<NUM_LIMBS>) -> Self
source§impl<const NUM_LIMBS: usize> Hash for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Hash for UnsignedInteger<NUM_LIMBS>
source§impl IsModulus<UnsignedInteger<4>> for BN254FieldModulus
impl IsModulus<UnsignedInteger<4>> for BN254FieldModulus
source§impl IsModulus<UnsignedInteger<4>> for FqConfig
impl IsModulus<UnsignedInteger<4>> for FqConfig
source§impl IsModulus<UnsignedInteger<4>> for FrConfig
impl IsModulus<UnsignedInteger<4>> for FrConfig
Modulus of bls 12 381 subgroup
source§impl IsModulus<UnsignedInteger<4>> for FrConfig
impl IsModulus<UnsignedInteger<4>> for FrConfig
Modulus of bn 254 subgroup r = 21888242871839275222246405745257275088548364400416034343698204186575808495617, aka order
source§impl IsModulus<UnsignedInteger<4>> for FrConfig
impl IsModulus<UnsignedInteger<4>> for FrConfig
Modulus (Order) of Grumpkin Fr
source§impl IsModulus<UnsignedInteger<4>> for GrumpkinFieldModulus
impl IsModulus<UnsignedInteger<4>> for GrumpkinFieldModulus
source§impl IsModulus<UnsignedInteger<6>> for BLS12377FieldModulus
impl IsModulus<UnsignedInteger<6>> for BLS12377FieldModulus
source§impl IsModulus<UnsignedInteger<6>> for BLS12381FieldModulus
impl IsModulus<UnsignedInteger<6>> for BLS12381FieldModulus
source§impl IsModulus<UnsignedInteger<6>> for TestCurve2Modulus
impl IsModulus<UnsignedInteger<6>> for TestCurve2Modulus
source§impl<const NUM_LIMBS: usize> Mul<&UnsignedInteger<NUM_LIMBS>> for &UnsignedInteger<NUM_LIMBS>
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>
type Output = UnsignedInteger<NUM_LIMBS>
*
operator.source§fn mul(self, other: &UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>
fn mul(self, other: &UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>
*
operation. Read moresource§impl<const NUM_LIMBS: usize> Mul<&UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Mul<&UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>
source§impl<const NUM_LIMBS: usize> Mul<UnsignedInteger<NUM_LIMBS>> for &UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Mul<UnsignedInteger<NUM_LIMBS>> for &UnsignedInteger<NUM_LIMBS>
source§type Output = UnsignedInteger<NUM_LIMBS>
type Output = UnsignedInteger<NUM_LIMBS>
*
operator.source§fn mul(self, other: UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>
fn mul(self, other: UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>
*
operation. Read moresource§impl<const NUM_LIMBS: usize> Mul for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Mul for UnsignedInteger<NUM_LIMBS>
source§type Output = UnsignedInteger<NUM_LIMBS>
type Output = UnsignedInteger<NUM_LIMBS>
*
operator.source§fn mul(self, other: UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>
fn mul(self, other: UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>
*
operation. Read moresource§impl<const NUM_LIMBS: usize> Ord for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Ord for UnsignedInteger<NUM_LIMBS>
source§impl<const NUM_LIMBS: usize> PartialEq for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> PartialEq for UnsignedInteger<NUM_LIMBS>
source§impl<const NUM_LIMBS: usize> PartialOrd for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> PartialOrd for UnsignedInteger<NUM_LIMBS>
source§impl<const NUM_LIMBS: usize> Shl<usize> for &UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Shl<usize> for &UnsignedInteger<NUM_LIMBS>
source§type Output = UnsignedInteger<NUM_LIMBS>
type Output = UnsignedInteger<NUM_LIMBS>
<<
operator.source§impl<const NUM_LIMBS: usize> Shl<usize> for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Shl<usize> for UnsignedInteger<NUM_LIMBS>
source§type Output = UnsignedInteger<NUM_LIMBS>
type Output = UnsignedInteger<NUM_LIMBS>
<<
operator.source§impl<const NUM_LIMBS: usize> Shr<usize> for &UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Shr<usize> for &UnsignedInteger<NUM_LIMBS>
source§type Output = UnsignedInteger<NUM_LIMBS>
type Output = UnsignedInteger<NUM_LIMBS>
>>
operator.source§impl<const NUM_LIMBS: usize> Shr<usize> for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Shr<usize> for UnsignedInteger<NUM_LIMBS>
source§type Output = UnsignedInteger<NUM_LIMBS>
type Output = UnsignedInteger<NUM_LIMBS>
>>
operator.source§impl<const NUM_LIMBS: usize> ShrAssign<usize> for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> ShrAssign<usize> for UnsignedInteger<NUM_LIMBS>
source§fn shr_assign(&mut self, times: usize)
fn shr_assign(&mut self, times: usize)
>>=
operation. Read moresource§impl<const NUM_LIMBS: usize> Sub<&UnsignedInteger<NUM_LIMBS>> for &UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Sub<&UnsignedInteger<NUM_LIMBS>> for &UnsignedInteger<NUM_LIMBS>
source§type Output = UnsignedInteger<NUM_LIMBS>
type Output = UnsignedInteger<NUM_LIMBS>
-
operator.source§fn sub(self, other: &UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>
fn sub(self, other: &UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>
-
operation. Read moresource§impl<const NUM_LIMBS: usize> Sub<&UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Sub<&UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>
source§impl<const NUM_LIMBS: usize> Sub<UnsignedInteger<NUM_LIMBS>> for &UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Sub<UnsignedInteger<NUM_LIMBS>> for &UnsignedInteger<NUM_LIMBS>
source§type Output = UnsignedInteger<NUM_LIMBS>
type Output = UnsignedInteger<NUM_LIMBS>
-
operator.source§fn sub(self, other: UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>
fn sub(self, other: UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>
-
operation. Read moresource§impl<const NUM_LIMBS: usize> Sub for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Sub for UnsignedInteger<NUM_LIMBS>
source§type Output = UnsignedInteger<NUM_LIMBS>
type Output = UnsignedInteger<NUM_LIMBS>
-
operator.source§fn sub(self, other: UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>
fn sub(self, other: UnsignedInteger<NUM_LIMBS>) -> UnsignedInteger<NUM_LIMBS>
-
operation. Read moreimpl<const NUM_LIMBS: usize> Copy for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Eq for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> IsUnsignedInteger for UnsignedInteger<NUM_LIMBS>
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> 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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