pub struct UnsignedInteger { /* private fields */ }
Expand description
An unsigned big (arbitrary-size) integer. Unless specified with the leaky
keyword, all functions are designed to be constant-time.
Implementations§
Source§impl UnsignedInteger
impl UnsignedInteger
Sourcepub fn div_rem(
self,
rhs: &UnsignedInteger,
) -> (UnsignedInteger, UnsignedInteger)
pub fn div_rem( self, rhs: &UnsignedInteger, ) -> (UnsignedInteger, UnsignedInteger)
Divides self
by rhs
and returns the quotient and remainder (in that order).
Source§impl UnsignedInteger
impl UnsignedInteger
Sourcepub fn square(&self) -> UnsignedInteger
pub fn square(&self) -> UnsignedInteger
Computes $x^2$, where $x$ is self
. This is typically faster than performing a multiplication.
Source§impl UnsignedInteger
impl UnsignedInteger
Sourcepub fn eq_leaky(&self, other: &Self) -> bool
pub fn eq_leaky(&self, other: &Self) -> bool
Checks if self
equals other
. This function is not constant-time.
Sourcepub fn partial_cmp_leaky(&self, other: &Self) -> Option<Ordering>
pub fn partial_cmp_leaky(&self, other: &Self) -> Option<Ordering>
Compares self
to other
, and returns whether it is less than other
, equal, or greater. This function is not constant-time.
Source§impl UnsignedInteger
impl UnsignedInteger
Sourcepub fn invert(self, modulus: &UnsignedInteger) -> Option<UnsignedInteger>
pub fn invert(self, modulus: &UnsignedInteger) -> Option<UnsignedInteger>
Computes self^-1 mod modulus
, taking ownership of self
. Returns None if no inverse exists. modulus
must be odd.
Sourcepub fn invert_leaky(self, modulus: &UnsignedInteger) -> Option<UnsignedInteger>
pub fn invert_leaky(self, modulus: &UnsignedInteger) -> Option<UnsignedInteger>
Computes self^-1 mod modulus
, taking ownership of self
. Returns None if no inverse exists. modulus
must be odd. This function is not constant-time.
Source§impl UnsignedInteger
impl UnsignedInteger
Sourcepub fn pow_mod(
&self,
exponent: &UnsignedInteger,
modulus: &UnsignedInteger,
) -> UnsignedInteger
pub fn pow_mod( &self, exponent: &UnsignedInteger, modulus: &UnsignedInteger, ) -> UnsignedInteger
Compute self
to the power exponent
modulo an odd modulus
. The computation takes time that scales with the specified size of the exponent
and modulus
.
Source§impl UnsignedInteger
impl UnsignedInteger
Sourcepub fn size_in_bits(&self) -> u32
pub fn size_in_bits(&self) -> u32
The size of the unsiged number expressed in bits. This is a reasonably tight upper bound (it cannot exceed the actual value by more than 64 bits).
Sourcepub fn new(integer: u64, size_in_bits: u32) -> Self
pub fn new(integer: u64, size_in_bits: u32) -> Self
Creates a new UnsignedInteger
that equals integer
with the given size_in_bits
. size_in_bits
must be a tight estimate; it may only exceed the actual number of bits until the next multiple of 64.
Sourcepub fn zero(size_in_bits: u32) -> Self
pub fn zero(size_in_bits: u32) -> Self
Creates a BigInteger with value 0. All arithmetic operations are constant-time with regards to the integer’s size bits
.
Sourcepub fn from_string_leaky(
string: String,
base: i32,
size_in_bits: u32,
) -> UnsignedInteger
pub fn from_string_leaky( string: String, base: i32, size_in_bits: u32, ) -> UnsignedInteger
Creates a BigInteger from a value given as a string
in a certain base
. The size_in_bits
should not be lower than the actual value encoded.
Sourcepub fn random<R: SecureRng>(bits: u32, rng: &mut GeneralRng<R>) -> Self
pub fn random<R: SecureRng>(bits: u32, rng: &mut GeneralRng<R>) -> Self
Generates a random unsigned number with bits
bits. bits
should be a multiple of 8.
Sourcepub fn random_below<R: SecureRng>(
limit: &UnsignedInteger,
rng: &mut GeneralRng<R>,
) -> Self
pub fn random_below<R: SecureRng>( limit: &UnsignedInteger, rng: &mut GeneralRng<R>, ) -> Self
Generates a random unsigned number below limit
.
Sourcepub fn set_bit_leaky(&mut self, bit_index: u32)
pub fn set_bit_leaky(&mut self, bit_index: u32)
Sets the bit at bit_index
to 1. This function is not constant-time.
Sourcepub fn clear_bit_leaky(&mut self, bit_index: u32)
pub fn clear_bit_leaky(&mut self, bit_index: u32)
Sets the bit at bit_index
to 0. This function is not constant-time.
Sourcepub fn mod_u_leaky(&self, modulus: u64) -> u64
pub fn mod_u_leaky(&self, modulus: u64) -> u64
Computes self modulo a u64 number. This function is not constant-time.
Sourcepub fn is_probably_prime_leaky(&self) -> bool
pub fn is_probably_prime_leaky(&self) -> bool
Returns true when this number is prime. This function is not constant-time. Internally it uses Baille-PSW.
Sourcepub fn is_zero_leaky(&self) -> bool
pub fn is_zero_leaky(&self) -> bool
Returns true if self == 0. This can be faster than checking equality.
Sourcepub fn lcm_leaky(&self, other: &UnsignedInteger) -> UnsignedInteger
pub fn lcm_leaky(&self, other: &UnsignedInteger) -> UnsignedInteger
Computes the least common multiple between self and other. This function is not constant-time.
Sourcepub fn factorial_leaky(n: u64) -> Self
pub fn factorial_leaky(n: u64) -> Self
Computes $n!$. This function is not constant-time.
Sourcepub fn reduce_leaky(&mut self)
pub fn reduce_leaky(&mut self)
Reduces self
so that there are no leading zero-limbs. In other words, the representation becomes as small as possible to represent this value. This leaks the actual size of the encoded value.
Trait Implementations§
Source§impl Add<&UnsignedInteger> for UnsignedInteger
impl Add<&UnsignedInteger> for UnsignedInteger
Source§impl Add<u64> for UnsignedInteger
impl Add<u64> for UnsignedInteger
Source§impl AddAssign<&UnsignedInteger> for UnsignedInteger
impl AddAssign<&UnsignedInteger> for UnsignedInteger
Source§fn add_assign(&mut self, rhs: &Self)
fn add_assign(&mut self, rhs: &Self)
+=
operation. Read moreSource§impl AddAssign<u64> for UnsignedInteger
impl AddAssign<u64> for UnsignedInteger
Source§fn add_assign(&mut self, rhs: u64)
fn add_assign(&mut self, rhs: u64)
+=
operation. Read moreSource§impl Clone for UnsignedInteger
impl Clone for UnsignedInteger
Source§impl Debug for UnsignedInteger
impl Debug for UnsignedInteger
Source§impl<'de> Deserialize<'de> for UnsignedInteger
impl<'de> Deserialize<'de> for UnsignedInteger
Source§fn deserialize<D: Deserializer<'de>>(
deserializer: D,
) -> Result<UnsignedInteger, D::Error>
fn deserialize<D: Deserializer<'de>>( deserializer: D, ) -> Result<UnsignedInteger, D::Error>
Source§impl Display for UnsignedInteger
impl Display for UnsignedInteger
Source§impl Div<&UnsignedInteger> for UnsignedInteger
impl Div<&UnsignedInteger> for UnsignedInteger
Source§type Output = UnsignedInteger
type Output = UnsignedInteger
/
operator.Source§fn div(self, rhs: &UnsignedInteger) -> UnsignedInteger
fn div(self, rhs: &UnsignedInteger) -> UnsignedInteger
/
operation. Read moreSource§impl Drop for UnsignedInteger
impl Drop for UnsignedInteger
Source§impl From<Integer> for UnsignedInteger
impl From<Integer> for UnsignedInteger
Source§impl From<u64> for UnsignedInteger
impl From<u64> for UnsignedInteger
Source§impl Hash for UnsignedInteger
impl Hash for UnsignedInteger
Source§impl Mul for &UnsignedInteger
impl Mul for &UnsignedInteger
Source§impl PartialEq for UnsignedInteger
impl PartialEq for UnsignedInteger
Source§impl<'a> Product<&'a UnsignedInteger> for UnsignedInteger
impl<'a> Product<&'a UnsignedInteger> for UnsignedInteger
Source§fn product<I: Iterator<Item = &'a UnsignedInteger>>(iter: I) -> Self
fn product<I: Iterator<Item = &'a UnsignedInteger>>(iter: I) -> Self
Self
from the elements by multiplying
the items.Source§impl Rem<&UnsignedInteger> for UnsignedInteger
impl Rem<&UnsignedInteger> for UnsignedInteger
Source§type Output = UnsignedInteger
type Output = UnsignedInteger
%
operator.Source§impl RemAssign<&UnsignedInteger> for UnsignedInteger
impl RemAssign<&UnsignedInteger> for UnsignedInteger
Source§fn rem_assign(&mut self, rhs: &Self)
fn rem_assign(&mut self, rhs: &Self)
%=
operation. Read moreSource§impl Serialize for UnsignedInteger
impl Serialize for UnsignedInteger
Source§impl Shr<u32> for &UnsignedInteger
impl Shr<u32> for &UnsignedInteger
Source§impl ShrAssign<u32> for UnsignedInteger
impl ShrAssign<u32> for UnsignedInteger
Source§fn shr_assign(&mut self, rhs: u32)
fn shr_assign(&mut self, rhs: u32)
>>=
operation. Read moreSource§impl Sub<&UnsignedInteger> for UnsignedInteger
impl Sub<&UnsignedInteger> for UnsignedInteger
Source§type Output = UnsignedInteger
type Output = UnsignedInteger
-
operator.Source§impl SubAssign<&UnsignedInteger> for UnsignedInteger
impl SubAssign<&UnsignedInteger> for UnsignedInteger
Source§fn sub_assign(&mut self, rhs: &UnsignedInteger)
fn sub_assign(&mut self, rhs: &UnsignedInteger)
-=
operation. Read moreSource§impl SubAssign<u64> for UnsignedInteger
impl SubAssign<u64> for UnsignedInteger
Source§fn sub_assign(&mut self, rhs: u64)
fn sub_assign(&mut self, rhs: u64)
-=
operation. Read moreSource§impl<'a> Sum<&'a UnsignedInteger> for UnsignedInteger
impl<'a> Sum<&'a UnsignedInteger> for UnsignedInteger
Source§fn sum<I: Iterator<Item = &'a UnsignedInteger>>(iter: I) -> Self
fn sum<I: Iterator<Item = &'a UnsignedInteger>>(iter: I) -> Self
Self
from the elements by “summing up”
the items.