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 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
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. Shouldn’t start with 0x
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)
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>)
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>
§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>
§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>
§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> BitAnd<UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> BitAnd<UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>
Impl BitAnd
source§impl<const NUM_LIMBS: usize> BitAndAssign<UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> BitAndAssign<UnsignedInteger<NUM_LIMBS>> 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<UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> BitOr<UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>
Impl BitOr
source§impl<const NUM_LIMBS: usize> BitOrAssign<UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> BitOrAssign<UnsignedInteger<NUM_LIMBS>> 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<UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> BitXor<UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>
Impl BitXor
source§impl<const NUM_LIMBS: usize> BitXorAssign<UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> BitXorAssign<UnsignedInteger<NUM_LIMBS>> 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 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 FrConfig
impl IsModulus<UnsignedInteger<4>> for FrConfig
Modulus of bls 12 381 subgroup
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/)
§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>
§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>
§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<UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> PartialEq<UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>
source§fn eq(&self, other: &UnsignedInteger<NUM_LIMBS>) -> bool
fn eq(&self, other: &UnsignedInteger<NUM_LIMBS>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<const NUM_LIMBS: usize> PartialOrd<UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> PartialOrd<UnsignedInteger<NUM_LIMBS>> for UnsignedInteger<NUM_LIMBS>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<const NUM_LIMBS: usize> Shl<usize> for &UnsignedInteger<NUM_LIMBS>
impl<const NUM_LIMBS: usize> Shl<usize> for &UnsignedInteger<NUM_LIMBS>
§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>
§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>
§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>
§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>
§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>
§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>
§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 more