pub struct UInt<const LIMBS: usize> { /* private fields */ }Expand description
Big unsigned integer.
Generic over the given number of LIMBS
Implementations§
Source§impl<const LIMBS: usize> UInt<LIMBS>
impl<const LIMBS: usize> UInt<LIMBS>
Sourcepub const fn adc(&self, rhs: &Self, carry: Limb) -> (Self, Limb)
pub const fn adc(&self, rhs: &Self, carry: Limb) -> (Self, Limb)
Computes a + b + carry, returning the result along with the new carry.
Sourcepub const fn wrapping_add(&self, rhs: &Self) -> Self
pub const fn wrapping_add(&self, rhs: &Self) -> Self
Perform wrapping addition, discarding overflow.
Sourcepub fn checked_add(&self, rhs: &Self) -> CtOption<Self>
pub fn checked_add(&self, rhs: &Self) -> CtOption<Self>
Perform checked addition, returning a CtOption which is_some only
if the operation did not overflow.
Source§impl<const LIMBS: usize> UInt<LIMBS>
impl<const LIMBS: usize> UInt<LIMBS>
Sourcepub const fn from_be_slice(bytes: &[u8]) -> Self
pub const fn from_be_slice(bytes: &[u8]) -> Self
Create a new UInt from the provided big endian bytes.
Sourcepub const fn from_be_hex(hex: &str) -> Self
pub const fn from_be_hex(hex: &str) -> Self
Create a new UInt from the provided big endian hex string.
Sourcepub const fn from_le_slice(bytes: &[u8]) -> Self
pub const fn from_le_slice(bytes: &[u8]) -> Self
Create a new UInt from the provided little endian bytes.
Sourcepub const fn from_le_hex(hex: &str) -> Self
pub const fn from_le_hex(hex: &str) -> Self
Create a new UInt from the provided little endian hex string.
Source§impl<const LIMBS: usize> UInt<LIMBS>
impl<const LIMBS: usize> UInt<LIMBS>
Sourcepub const fn from_uint_array(arr: [Inner; LIMBS]) -> Self
pub const fn from_uint_array(arr: [Inner; LIMBS]) -> Self
Create a UInt from an array of the limb::Inner
unsigned integer type.
Sourcepub const fn to_uint_array(self) -> [Inner; LIMBS]
pub const fn to_uint_array(self) -> [Inner; LIMBS]
Create an array of limb::Inner unsigned integer type from a UInt.
Source§impl<const LIMBS: usize> UInt<LIMBS>
impl<const LIMBS: usize> UInt<LIMBS>
Sourcepub const fn mul_wide(&self, rhs: &Self) -> (Self, Self)
pub const fn mul_wide(&self, rhs: &Self) -> (Self, Self)
Compute “wide” multiplication, with a product twice the size of the input.
Sourcepub const fn wrapping_mul(&self, rhs: &Self) -> Self
pub const fn wrapping_mul(&self, rhs: &Self) -> Self
Perform wrapping multiplication, discarding overflow.
Sourcepub fn checked_mul(&self, rhs: &Self) -> CtOption<Self>
pub fn checked_mul(&self, rhs: &Self) -> CtOption<Self>
Perform checked multiplication, returning a CtOption which is_some
only if the operation did not overflow.
Source§impl<const LIMBS: usize> UInt<LIMBS>
impl<const LIMBS: usize> UInt<LIMBS>
Sourcepub const fn shr_vartime(&self, shift: usize) -> Self
pub const fn shr_vartime(&self, shift: usize) -> Self
Computes self >> n.
NOTE: this operation is variable time with respect to n ONLY.
When used with a fixed n, this function is constant-time with respect
to self.
Source§impl<const LIMBS: usize> UInt<LIMBS>
impl<const LIMBS: usize> UInt<LIMBS>
Sourcepub const fn sbb(&self, rhs: &Self, borrow: Limb) -> (Self, Limb)
pub const fn sbb(&self, rhs: &Self, borrow: Limb) -> (Self, Limb)
Computes a - (b + borrow), returning the result along with the new borrow.
Sourcepub const fn wrapping_sub(&self, rhs: &Self) -> Self
pub const fn wrapping_sub(&self, rhs: &Self) -> Self
Perform wrapping subtraction, discarding underflow and wrapping around the boundary of the type.
Sourcepub fn checked_sub(&self, rhs: &Self) -> CtOption<Self>
pub fn checked_sub(&self, rhs: &Self) -> CtOption<Self>
Perform checked subtraction, returning a CtOption which is_some
only if the operation did not overflow.
Source§impl<const LIMBS: usize> UInt<LIMBS>
impl<const LIMBS: usize> UInt<LIMBS>
Sourcepub fn random(rng: impl CryptoRng + RngCore) -> Self
pub fn random(rng: impl CryptoRng + RngCore) -> Self
Generate a cryptographically secure random UInt.
Sourcepub fn random_mod(rng: impl CryptoRng + RngCore, modulus: &Self) -> Self
pub fn random_mod(rng: impl CryptoRng + RngCore, modulus: &Self) -> Self
Generate a cryptographically secure random UInt which is less than
a given modulus.
This function uses rejection sampling, a method which produces an
unbiased distribution of in-range values provided the underlying
CryptoRng is unbiased, but runs in variable-time.
The variable-time nature of the algorithm should not pose a security
issue so long as the underlying random number generator is truly a
CryptoRng, where previous outputs are unrelated to subsequent
outputs and do not reveal information about the RNG’s internal state.
Trait Implementations§
Source§impl<const LIMBS: usize> ConditionallySelectable for UInt<LIMBS>
impl<const LIMBS: usize> ConditionallySelectable for UInt<LIMBS>
Source§fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
Source§fn conditional_assign(&mut self, other: &Self, choice: Choice)
fn conditional_assign(&mut self, other: &Self, choice: Choice)
Source§fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
self and other if choice == 1; otherwise,
reassign both unto themselves. Read more