pub struct Uint { /* private fields */ }
bigint
only.Expand description
Fixed-precision heap-allocated big unsigned integer.
Alternative to the stack-allocated Uint
but with a
fixed precision chosen at runtime instead of compile time.
Unlike many other heap-allocated big integer libraries, this type is not arbitrary precision and will wrap at its fixed-precision rather than automatically growing.
Implementations§
Source§impl BoxedUint
impl BoxedUint
Sourcepub fn adc(&self, rhs: &BoxedUint, carry: Limb) -> (BoxedUint, Limb)
👎Deprecated since 0.7.0: please use carrying_add
instead
pub fn adc(&self, rhs: &BoxedUint, carry: Limb) -> (BoxedUint, Limb)
carrying_add
insteadComputes self + rhs + carry
, returning the result along with the new carry.
Sourcepub fn carrying_add(&self, rhs: &BoxedUint, carry: Limb) -> (BoxedUint, Limb)
pub fn carrying_add(&self, rhs: &BoxedUint, carry: Limb) -> (BoxedUint, Limb)
Computes self + rhs + carry
, returning the result along with the new carry.
Sourcepub fn adc_assign(&mut self, rhs: impl AsRef<[Limb]>, carry: Limb) -> Limb
👎Deprecated since 0.7.0: please use carrying_add_assign
instead
pub fn adc_assign(&mut self, rhs: impl AsRef<[Limb]>, carry: Limb) -> Limb
carrying_add_assign
insteadComputes a + b + carry
in-place, returning the new carry.
Panics if rhs
has a larger precision than self
.
Sourcepub fn carrying_add_assign(
&mut self,
rhs: impl AsRef<[Limb]>,
carry: Limb,
) -> Limb
pub fn carrying_add_assign( &mut self, rhs: impl AsRef<[Limb]>, carry: Limb, ) -> Limb
Computes a + b + carry
in-place, returning the new carry.
Panics if rhs
has a larger precision than self
.
Sourcepub fn wrapping_add(&self, rhs: &BoxedUint) -> BoxedUint
pub fn wrapping_add(&self, rhs: &BoxedUint) -> BoxedUint
Perform wrapping addition, discarding overflow.
Source§impl BoxedUint
impl BoxedUint
Sourcepub fn add_mod(&self, rhs: &BoxedUint, p: &BoxedUint) -> BoxedUint
pub fn add_mod(&self, rhs: &BoxedUint, p: &BoxedUint) -> BoxedUint
Computes self + rhs mod p
.
Assumes self + rhs
as unbounded integer is < 2p
.
Sourcepub fn add_mod_assign(&mut self, rhs: &BoxedUint, p: &BoxedUint)
pub fn add_mod_assign(&mut self, rhs: &BoxedUint, p: &BoxedUint)
Computes self + rhs mod p
and writes the result in self
.
Assumes self + rhs
as unbounded integer is < 2p
.
Sourcepub fn double_mod(&self, p: &BoxedUint) -> BoxedUint
pub fn double_mod(&self, p: &BoxedUint) -> BoxedUint
Computes self + self mod p
.
Assumes self
as unbounded integer is < p
.
Source§impl BoxedUint
impl BoxedUint
Sourcepub fn bitand_limb(&self, rhs: Limb) -> BoxedUint
pub fn bitand_limb(&self, rhs: Limb) -> BoxedUint
Perform bitwise AND
between self
and the given Limb
, performing the AND
operation
on every limb of self
.
Sourcepub fn wrapping_and(&self, rhs: &BoxedUint) -> BoxedUint
pub fn wrapping_and(&self, rhs: &BoxedUint) -> BoxedUint
Perform wrapping bitwise AND
.
There’s no way wrapping could ever happen. This function exists so that all operations are accounted for in the wrapping operations
Source§impl BoxedUint
impl BoxedUint
Sourcepub fn wrapping_or(&self, rhs: &BoxedUint) -> BoxedUint
pub fn wrapping_or(&self, rhs: &BoxedUint) -> BoxedUint
Perform wrapping bitwise OR
.
There’s no way wrapping could ever happen. This function exists so that all operations are accounted for in the wrapping operations
Source§impl BoxedUint
impl BoxedUint
Sourcepub fn wrapping_xor(&self, rhs: &BoxedUint) -> BoxedUint
pub fn wrapping_xor(&self, rhs: &BoxedUint) -> BoxedUint
Perform wrapping bitwise `XOR``.
There’s no way wrapping could ever happen. This function exists so that all operations are accounted for in the wrapping operations
Source§impl BoxedUint
impl BoxedUint
Sourcepub fn bit(&self, index: u32) -> Choice
pub fn bit(&self, index: u32) -> Choice
Get the value of the bit at position index
, as a truthy or falsy Choice
.
Returns the falsy value for indices out of range.
Sourcepub const fn bit_vartime(&self, index: u32) -> bool
pub const fn bit_vartime(&self, index: u32) -> bool
Returns true
if the bit at position index
is set, false
otherwise.
§Remarks
This operation is variable time with respect to index
only.
Sourcepub fn bits(&self) -> u32
pub fn bits(&self) -> u32
Calculate the number of bits needed to represent this number, i.e. the index of the highest set bit.
Use BoxedUint::bits_precision
to get the total capacity of this integer.
Sourcepub fn bits_vartime(&self) -> u32
pub fn bits_vartime(&self) -> u32
Calculate the number of bits needed to represent this number in variable-time with respect
to self
.
Sourcepub const fn leading_zeros(&self) -> u32
pub const fn leading_zeros(&self) -> u32
Calculate the number of leading zeros in the binary representation of this number.
Sourcepub fn bits_precision(&self) -> u32
pub fn bits_precision(&self) -> u32
Get the precision of this BoxedUint
in bits.
Sourcepub fn trailing_zeros(&self) -> u32
pub fn trailing_zeros(&self) -> u32
Calculate the number of trailing zeros in the binary representation of this number.
Sourcepub fn trailing_ones(&self) -> u32
pub fn trailing_ones(&self) -> u32
Calculate the number of trailing ones in the binary representation of this number.
Sourcepub fn trailing_zeros_vartime(&self) -> u32
pub fn trailing_zeros_vartime(&self) -> u32
Calculate the number of trailing zeros in the binary representation of this number in
variable-time with respect to self
.
Sourcepub fn trailing_ones_vartime(&self) -> u32
pub fn trailing_ones_vartime(&self) -> u32
Calculate the number of trailing ones in the binary representation of this number,
variable time in self
.
Source§impl BoxedUint
impl BoxedUint
Sourcepub fn cmp_vartime(&self, rhs: &BoxedUint) -> Ordering
pub fn cmp_vartime(&self, rhs: &BoxedUint) -> Ordering
Returns the Ordering between self
and rhs
in variable time.
Source§impl BoxedUint
impl BoxedUint
Sourcepub fn div_rem_limb_with_reciprocal(
&self,
reciprocal: &Reciprocal,
) -> (BoxedUint, Limb)
pub fn div_rem_limb_with_reciprocal( &self, reciprocal: &Reciprocal, ) -> (BoxedUint, Limb)
Computes self / rhs
using a pre-made reciprocal,
returns the quotient (q) and remainder (r).
Sourcepub fn div_rem_limb(&self, rhs: NonZero<Limb>) -> (BoxedUint, Limb)
pub fn div_rem_limb(&self, rhs: NonZero<Limb>) -> (BoxedUint, Limb)
Computes self / rhs
, returns the quotient (q) and remainder (r).
Sourcepub fn rem_limb_with_reciprocal(&self, reciprocal: &Reciprocal) -> Limb
pub fn rem_limb_with_reciprocal(&self, reciprocal: &Reciprocal) -> Limb
Computes self % rhs
using a pre-made reciprocal.
Sourcepub fn div_rem(&self, rhs: &NonZero<BoxedUint>) -> (BoxedUint, BoxedUint)
pub fn div_rem(&self, rhs: &NonZero<BoxedUint>) -> (BoxedUint, BoxedUint)
Computes self / rhs, returns the quotient, remainder.
Sourcepub fn rem(&self, rhs: &NonZero<BoxedUint>) -> BoxedUint
pub fn rem(&self, rhs: &NonZero<BoxedUint>) -> BoxedUint
Computes self % rhs, returns the remainder.
Sourcepub fn div_rem_vartime(
&self,
rhs: &NonZero<BoxedUint>,
) -> (BoxedUint, BoxedUint)
pub fn div_rem_vartime( &self, rhs: &NonZero<BoxedUint>, ) -> (BoxedUint, BoxedUint)
Computes self / rhs, returns the quotient, remainder.
Variable-time with respect to rhs
Sourcepub fn rem_vartime(&self, rhs: &NonZero<BoxedUint>) -> BoxedUint
pub fn rem_vartime(&self, rhs: &NonZero<BoxedUint>) -> BoxedUint
Computes self % rhs, returns the remainder.
Variable-time with respect to rhs
.
Sourcepub fn wrapping_div(&self, rhs: &NonZero<BoxedUint>) -> BoxedUint
pub fn wrapping_div(&self, rhs: &NonZero<BoxedUint>) -> BoxedUint
Wrapped division is just normal division i.e. self
/ rhs
There’s no way wrapping could ever happen.
This function exists, so that all operations are accounted for in the wrapping operations.
Panics if rhs == 0
.
Sourcepub fn wrapping_div_vartime(&self, rhs: &NonZero<BoxedUint>) -> BoxedUint
pub fn wrapping_div_vartime(&self, rhs: &NonZero<BoxedUint>) -> BoxedUint
Wrapped division is just normal division i.e. self
/ rhs
There’s no way wrapping could ever happen. This function exists, so that all operations are accounted for in the wrapping operations
Source§impl BoxedUint
impl BoxedUint
Sourcepub fn from_be_slice(
bytes: &[u8],
bits_precision: u32,
) -> Result<BoxedUint, DecodeError>
pub fn from_be_slice( bytes: &[u8], bits_precision: u32, ) -> Result<BoxedUint, DecodeError>
Create a new BoxedUint
from the provided big endian bytes.
The bits_precision
argument represents the precision of the resulting integer, which is
fixed as this type is not arbitrary-precision.
The new BoxedUint
will be created with bits_precision
rounded up to a multiple of Limb::BITS
.
If the length of bytes
is larger than bits_precision
(rounded up to a multiple of 8)
this function will return DecodeError::InputSize
.
If the size of the decoded integer is larger than bits_precision
,
this function will return DecodeError::Precision
.
Sourcepub fn from_le_slice(
bytes: &[u8],
bits_precision: u32,
) -> Result<BoxedUint, DecodeError>
pub fn from_le_slice( bytes: &[u8], bits_precision: u32, ) -> Result<BoxedUint, DecodeError>
Create a new BoxedUint
from the provided little endian bytes.
The bits_precision
argument represents the precision of the resulting integer, which is
fixed as this type is not arbitrary-precision.
The new BoxedUint
will be created with bits_precision
rounded up to a multiple of Limb::BITS
.
If the length of bytes
is larger than bits_precision
(rounded up to a multiple of 8)
this function will return DecodeError::InputSize
.
If the size of the decoded integer is larger than bits_precision
,
this function will return DecodeError::Precision
.
Sourcepub fn to_be_bytes(&self) -> Box<[u8]>
pub fn to_be_bytes(&self) -> Box<[u8]>
Serialize this BoxedUint
as big-endian.
Sourcepub fn to_be_bytes_trimmed_vartime(&self) -> Box<[u8]>
pub fn to_be_bytes_trimmed_vartime(&self) -> Box<[u8]>
Serialize this BoxedUint
as big-endian without leading zeroes.
Sourcepub fn to_le_bytes(&self) -> Box<[u8]>
pub fn to_le_bytes(&self) -> Box<[u8]>
Serialize this BoxedUint
as little-endian.
Sourcepub fn to_le_bytes_trimmed_vartime(&self) -> Box<[u8]>
pub fn to_le_bytes_trimmed_vartime(&self) -> Box<[u8]>
Serialize this BoxedUint
as little-endian without trailing zeroes.
Sourcepub fn from_be_hex(hex: &str, bits_precision: u32) -> CtOption<BoxedUint>
pub fn from_be_hex(hex: &str, bits_precision: u32) -> CtOption<BoxedUint>
Create a new BoxedUint
from the provided big endian hex string.
Sourcepub fn from_str_radix_vartime(
src: &str,
radix: u32,
) -> Result<BoxedUint, DecodeError>
pub fn from_str_radix_vartime( src: &str, radix: u32, ) -> Result<BoxedUint, DecodeError>
Create a new BoxedUint
from a big-endian string in a given base.
The string may begin with a +
character, and may use underscore
characters to separate digits.
If the input value contains non-digit characters or digits outside of the range 0..radix
this function will return DecodeError::InvalidDigit
.
Panics if radix
is not in the range from 2 to 36.
Sourcepub fn from_str_radix_with_precision_vartime(
src: &str,
radix: u32,
bits_precision: u32,
) -> Result<BoxedUint, DecodeError>
pub fn from_str_radix_with_precision_vartime( src: &str, radix: u32, bits_precision: u32, ) -> Result<BoxedUint, DecodeError>
Create a new BoxedUint
from a big-endian string in a given base,
with a given precision.
The string may begin with a +
character, and may use underscore
characters to separate digits.
The bits_precision
argument represents the precision of the resulting integer, which is
fixed as this type is not arbitrary-precision.
The new BoxedUint
will be created with bits_precision
rounded up to a multiple
of Limb::BITS
.
If the input value contains non-digit characters or digits outside of the range 0..radix
this function will return DecodeError::InvalidDigit
.
If the length of bytes
is larger than bits_precision
(rounded up to a multiple of 8)
this function will return DecodeError::InputSize
.
If the size of the decoded integer is larger than bits_precision
,
this function will return DecodeError::Precision
.
Panics if radix
is not in the range from 2 to 36.
Sourcepub fn to_string_radix_vartime(&self, radix: u32) -> String
pub fn to_string_radix_vartime(&self, radix: u32) -> String
Format a BoxedUint
as a string in a given base.
Panics if radix
is not in the range from 2 to 36.
Source§impl BoxedUint
impl BoxedUint
Sourcepub fn inv_odd_mod(&self, modulus: &Odd<BoxedUint>) -> CtOption<BoxedUint>
👎Deprecated since 0.7.0: please use invert_odd_mod
instead
pub fn inv_odd_mod(&self, modulus: &Odd<BoxedUint>) -> CtOption<BoxedUint>
invert_odd_mod
insteadComputes the multiplicative inverse of self
mod modulus
, where modulus
is odd.
Sourcepub fn invert_odd_mod(&self, modulus: &Odd<BoxedUint>) -> CtOption<BoxedUint>
pub fn invert_odd_mod(&self, modulus: &Odd<BoxedUint>) -> CtOption<BoxedUint>
Computes the multiplicative inverse of self
mod modulus
, where modulus
is odd.
Sourcepub fn inv_mod2k_vartime(&self, k: u32) -> (BoxedUint, Choice)
👎Deprecated since 0.7.0: please use invert_mod2k_vartime
instead
pub fn inv_mod2k_vartime(&self, k: u32) -> (BoxedUint, Choice)
invert_mod2k_vartime
insteadComputes 1/self
mod 2^k
.
This method is constant-time w.r.t. self
but not k
.
If the inverse does not exist (k > 0
and self
is even),
returns Choice::FALSE
as the second element of the tuple,
otherwise returns Choice::TRUE
.
Sourcepub fn invert_mod2k_vartime(&self, k: u32) -> (BoxedUint, Choice)
pub fn invert_mod2k_vartime(&self, k: u32) -> (BoxedUint, Choice)
Computes 1/self
mod 2^k
.
This method is constant-time w.r.t. self
but not k
.
If the inverse does not exist (k > 0
and self
is even),
returns Choice::FALSE
as the second element of the tuple,
otherwise returns Choice::TRUE
.
Sourcepub fn inv_mod2k(&self, k: u32) -> (BoxedUint, Choice)
👎Deprecated since 0.7.0: please use invert_mod2k
instead
pub fn inv_mod2k(&self, k: u32) -> (BoxedUint, Choice)
invert_mod2k
insteadComputes 1/self
mod 2^k
.
If the inverse does not exist (k > 0
and self
is even),
returns Choice::FALSE
as the second element of the tuple,
otherwise returns Choice::TRUE
.
Sourcepub fn invert_mod2k(&self, k: u32) -> (BoxedUint, Choice)
pub fn invert_mod2k(&self, k: u32) -> (BoxedUint, Choice)
Computes 1/self
mod 2^k
.
If the inverse does not exist (k > 0
and self
is even),
returns Choice::FALSE
as the second element of the tuple,
otherwise returns Choice::TRUE
.
Sourcepub fn inv_mod(&self, modulus: &BoxedUint) -> CtOption<BoxedUint>
👎Deprecated since 0.7.0: please use invert_mod
instead
pub fn inv_mod(&self, modulus: &BoxedUint) -> CtOption<BoxedUint>
invert_mod
insteadComputes the multiplicaitve inverse of self
mod modulus
self
and modulus
must have the same number of limbs, or the function will panic
TODO: maybe some better documentation is needed
Sourcepub fn invert_mod(&self, modulus: &BoxedUint) -> CtOption<BoxedUint>
pub fn invert_mod(&self, modulus: &BoxedUint) -> CtOption<BoxedUint>
Computes the multiplicaitve inverse of self
mod modulus
self
and modulus
must have the same number of limbs, or the function will panic
TODO: maybe some better documentation is needed
Source§impl BoxedUint
impl BoxedUint
Source§impl BoxedUint
impl BoxedUint
Sourcepub fn mul_mod(&self, rhs: &BoxedUint, p: &BoxedUint) -> BoxedUint
pub fn mul_mod(&self, rhs: &BoxedUint, p: &BoxedUint) -> BoxedUint
Computes self * rhs mod p
for odd p
.
Panics if p
is even.
Sourcepub fn mul_mod_special(&self, rhs: &BoxedUint, c: Limb) -> BoxedUint
pub fn mul_mod_special(&self, rhs: &BoxedUint, c: Limb) -> BoxedUint
Computes self * rhs mod p
for the special modulus
p = MAX+1-c
where c
is small enough to fit in a single Limb
.
For the modulus reduction, this function implements Algorithm 14.47 from the “Handbook of Applied Cryptography”, by A. Menezes, P. van Oorschot, and S. Vanstone, CRC Press, 1996.
Source§impl BoxedUint
impl BoxedUint
Sourcepub fn shl(&self, shift: u32) -> BoxedUint
pub fn shl(&self, shift: u32) -> BoxedUint
Computes self << shift
.
Panics if shift >= Self::BITS
.
Sourcepub fn shl_assign(&mut self, shift: u32)
pub fn shl_assign(&mut self, shift: u32)
Computes self <<= shift
.
Panics if shift >= Self::BITS
.
Sourcepub fn overflowing_shl(&self, shift: u32) -> (BoxedUint, Choice)
pub fn overflowing_shl(&self, shift: u32) -> (BoxedUint, Choice)
Computes self << shift
.
Returns a zero and a truthy Choice
if shift >= self.bits_precision()
,
or the result and a falsy Choice
otherwise.
Sourcepub fn overflowing_shl_assign(&mut self, shift: u32) -> Choice
pub fn overflowing_shl_assign(&mut self, shift: u32) -> Choice
Computes self <<= shift
.
Returns a truthy Choice
if shift >= self.bits_precision()
or a falsy Choice
otherwise.
Sourcepub fn wrapping_shl(&self, shift: u32) -> BoxedUint
pub fn wrapping_shl(&self, shift: u32) -> BoxedUint
Computes self << shift
in a panic-free manner, masking off bits of shift
which would cause the shift to
exceed the type’s width.
Sourcepub fn wrapping_shl_vartime(&self, shift: u32) -> BoxedUint
pub fn wrapping_shl_vartime(&self, shift: u32) -> BoxedUint
Computes self << shift
in variable-time in a panic-free manner, masking off bits of shift
which would cause
the shift to exceed the type’s width.
Sourcepub fn shl_vartime(&self, shift: u32) -> Option<BoxedUint>
pub fn shl_vartime(&self, shift: u32) -> Option<BoxedUint>
Computes self << shift
.
Returns None
if shift >= self.bits_precision()
.
NOTE: this operation is variable time with respect to shift
ONLY.
When used with a fixed shift
, this function is constant-time with respect to self
.
Source§impl BoxedUint
impl BoxedUint
Sourcepub fn shr(&self, shift: u32) -> BoxedUint
pub fn shr(&self, shift: u32) -> BoxedUint
Computes self >> shift
.
Panics if shift >= Self::BITS
.
Sourcepub fn shr_assign(&mut self, shift: u32)
pub fn shr_assign(&mut self, shift: u32)
Computes self >>= shift
.
Panics if shift >= Self::BITS
.
Sourcepub fn overflowing_shr(&self, shift: u32) -> (BoxedUint, Choice)
pub fn overflowing_shr(&self, shift: u32) -> (BoxedUint, Choice)
Computes self >> shift
.
Returns a zero and a truthy Choice
if shift >= self.bits_precision()
,
or the result and a falsy Choice
otherwise.
Sourcepub fn overflowing_shr_assign(&mut self, shift: u32) -> Choice
pub fn overflowing_shr_assign(&mut self, shift: u32) -> Choice
Computes self >>= shift
.
Returns a truthy Choice
if shift >= self.bits_precision()
or a falsy Choice
otherwise.
Sourcepub fn wrapping_shr(&self, shift: u32) -> BoxedUint
pub fn wrapping_shr(&self, shift: u32) -> BoxedUint
Computes self >> shift
in a panic-free manner, masking off bits of shift
which would cause the shift to
exceed the type’s width.
Sourcepub fn wrapping_shr_vartime(&self, shift: u32) -> BoxedUint
pub fn wrapping_shr_vartime(&self, shift: u32) -> BoxedUint
Computes self >> shift
in variable-time in a panic-free manner, masking off bits of shift
which would cause
the shift to exceed the type’s width.
Sourcepub fn shr_vartime(&self, shift: u32) -> Option<BoxedUint>
pub fn shr_vartime(&self, shift: u32) -> Option<BoxedUint>
Computes self >> shift
.
Returns None
if shift >= self.bits_precision()
.
NOTE: this operation is variable time with respect to shift
ONLY.
When used with a fixed shift
, this function is constant-time with respect to self
.
Source§impl BoxedUint
impl BoxedUint
Sourcepub fn sqrt(&self) -> BoxedUint
pub fn sqrt(&self) -> BoxedUint
Computes √(self
) in constant time.
Callers can check if self
is a square by squaring the result
Sourcepub fn sqrt_vartime(&self) -> BoxedUint
pub fn sqrt_vartime(&self) -> BoxedUint
Computes √(self
)
Callers can check if self
is a square by squaring the result
Sourcepub fn wrapping_sqrt(&self) -> BoxedUint
pub fn wrapping_sqrt(&self) -> BoxedUint
Wrapped sqrt is just normal √(self
)
There’s no way wrapping could ever happen.
This function exists so that all operations are accounted for in the wrapping operations.
Sourcepub fn wrapping_sqrt_vartime(&self) -> BoxedUint
pub fn wrapping_sqrt_vartime(&self) -> BoxedUint
Wrapped sqrt is just normal √(self
)
There’s no way wrapping could ever happen.
This function exists so that all operations are accounted for in the wrapping operations.
Sourcepub fn checked_sqrt(&self) -> CtOption<BoxedUint>
pub fn checked_sqrt(&self) -> CtOption<BoxedUint>
Perform checked sqrt, returning a CtOption
which is_some
only if the √(self
)² == self
Sourcepub fn checked_sqrt_vartime(&self) -> CtOption<BoxedUint>
pub fn checked_sqrt_vartime(&self) -> CtOption<BoxedUint>
Perform checked sqrt, returning a CtOption
which is_some
only if the √(self
)² == self
Source§impl BoxedUint
impl BoxedUint
Sourcepub fn sbb(&self, rhs: &BoxedUint, borrow: Limb) -> (BoxedUint, Limb)
👎Deprecated since 0.7.0: please use borrowing_sub
instead
pub fn sbb(&self, rhs: &BoxedUint, borrow: Limb) -> (BoxedUint, Limb)
borrowing_sub
insteadComputes self - (rhs + borrow)
, returning the result along with the new borrow.
Sourcepub fn borrowing_sub(&self, rhs: &BoxedUint, borrow: Limb) -> (BoxedUint, Limb)
pub fn borrowing_sub(&self, rhs: &BoxedUint, borrow: Limb) -> (BoxedUint, Limb)
Computes self - (rhs + borrow)
, returning the result along with the new borrow.
Sourcepub fn sbb_assign(&mut self, rhs: impl AsRef<[Limb]>, borrow: Limb) -> Limb
👎Deprecated since 0.7.0: please use borrowing_sub_assign
instead
pub fn sbb_assign(&mut self, rhs: impl AsRef<[Limb]>, borrow: Limb) -> Limb
borrowing_sub_assign
insteadComputes a - (b + borrow)
in-place, returning the new borrow.
Panics if rhs
has a larger precision than self
.
Sourcepub fn borrowing_sub_assign(
&mut self,
rhs: impl AsRef<[Limb]>,
borrow: Limb,
) -> Limb
pub fn borrowing_sub_assign( &mut self, rhs: impl AsRef<[Limb]>, borrow: Limb, ) -> Limb
Computes a - (b + borrow)
in-place, returning the new borrow.
Panics if rhs
has a larger precision than self
.
Sourcepub fn wrapping_sub(&self, rhs: &BoxedUint) -> BoxedUint
pub fn wrapping_sub(&self, rhs: &BoxedUint) -> BoxedUint
Perform wrapping subtraction, discarding overflow.
Source§impl BoxedUint
impl BoxedUint
Source§impl BoxedUint
impl BoxedUint
Sourcepub fn zero_with_precision(at_least_bits_precision: u32) -> BoxedUint
pub fn zero_with_precision(at_least_bits_precision: u32) -> BoxedUint
Get the value 0
with the given number of bits of precision.
at_least_bits_precision
is rounded up to a multiple of Limb::BITS
.
Sourcepub fn one_with_precision(at_least_bits_precision: u32) -> BoxedUint
pub fn one_with_precision(at_least_bits_precision: u32) -> BoxedUint
Get the value 1
with the given number of bits of precision.
at_least_bits_precision
is rounded up to a multiple of Limb::BITS
.
Sourcepub fn is_nonzero(&self) -> Choice
pub fn is_nonzero(&self) -> Choice
Is this BoxedUint
NOT equal to zero?
Sourcepub fn max(at_least_bits_precision: u32) -> BoxedUint
pub fn max(at_least_bits_precision: u32) -> BoxedUint
Get the maximum value for a BoxedUint
created with at_least_bits_precision
precision bits requested.
That is, returns the value 2^self.bits_precision() - 1
.
Sourcepub fn from_words(words: impl IntoIterator<Item = u64>) -> BoxedUint
pub fn from_words(words: impl IntoIterator<Item = u64>) -> BoxedUint
Sourcepub fn as_mut_words(&mut self) -> &mut [u64]
pub fn as_mut_words(&mut self) -> &mut [u64]
Borrow the inner limbs as a mutable slice of Word
s.
Sourcepub fn as_words_mut(&mut self) -> &mut [u64]
👎Deprecated since 0.7.0: please use as_mut_words
instead
pub fn as_words_mut(&mut self) -> &mut [u64]
as_mut_words
insteadBorrow the inner limbs as a mutable slice of Word
s.
Sourcepub fn as_mut_limbs(&mut self) -> &mut [Limb]
pub fn as_mut_limbs(&mut self) -> &mut [Limb]
Borrow the limbs of this BoxedUint
mutably.
Sourcepub fn as_limbs_mut(&mut self) -> &mut [Limb]
👎Deprecated since 0.7.0: please use as_mut_limbs
instead
pub fn as_limbs_mut(&mut self) -> &mut [Limb]
as_mut_limbs
insteadBorrow the limbs of this BoxedUint
mutably.
Sourcepub fn into_limbs(self) -> Box<[Limb]>
pub fn into_limbs(self) -> Box<[Limb]>
Convert this BoxedUint
into its inner limbs.
Trait Implementations§
Source§impl AddAssign<&BoxedUint> for BoxedUint
impl AddAssign<&BoxedUint> for BoxedUint
Source§fn add_assign(&mut self, rhs: &BoxedUint)
fn add_assign(&mut self, rhs: &BoxedUint)
+=
operation. Read moreSource§impl<const LIMBS: usize> AddAssign<&Uint<LIMBS>> for BoxedUint
impl<const LIMBS: usize> AddAssign<&Uint<LIMBS>> for BoxedUint
Source§fn add_assign(&mut self, rhs: &Uint<LIMBS>)
fn add_assign(&mut self, rhs: &Uint<LIMBS>)
+=
operation. Read moreSource§impl<const LIMBS: usize> AddAssign<Uint<LIMBS>> for BoxedUint
impl<const LIMBS: usize> AddAssign<Uint<LIMBS>> for BoxedUint
Source§fn add_assign(&mut self, rhs: Uint<LIMBS>)
fn add_assign(&mut self, rhs: Uint<LIMBS>)
+=
operation. Read moreSource§impl AddAssign<u128> for BoxedUint
impl AddAssign<u128> for BoxedUint
Source§fn add_assign(&mut self, rhs: u128)
fn add_assign(&mut self, rhs: u128)
+=
operation. Read moreSource§impl AddAssign<u16> for BoxedUint
impl AddAssign<u16> for BoxedUint
Source§fn add_assign(&mut self, rhs: u16)
fn add_assign(&mut self, rhs: u16)
+=
operation. Read moreSource§impl AddAssign<u32> for BoxedUint
impl AddAssign<u32> for BoxedUint
Source§fn add_assign(&mut self, rhs: u32)
fn add_assign(&mut self, rhs: u32)
+=
operation. Read moreSource§impl AddAssign<u64> for BoxedUint
impl AddAssign<u64> for BoxedUint
Source§fn add_assign(&mut self, rhs: u64)
fn add_assign(&mut self, rhs: u64)
+=
operation. Read moreSource§impl AddAssign<u8> for BoxedUint
impl AddAssign<u8> for BoxedUint
Source§fn add_assign(&mut self, rhs: u8)
fn add_assign(&mut self, rhs: u8)
+=
operation. Read moreSource§impl AddAssign for BoxedUint
impl AddAssign for BoxedUint
Source§fn add_assign(&mut self, rhs: BoxedUint)
fn add_assign(&mut self, rhs: BoxedUint)
+=
operation. Read moreSource§impl BitAndAssign<&BoxedUint> for BoxedUint
impl BitAndAssign<&BoxedUint> for BoxedUint
Source§fn bitand_assign(&mut self, other: &BoxedUint)
fn bitand_assign(&mut self, other: &BoxedUint)
&=
operation. Read moreSource§impl BitAndAssign for BoxedUint
impl BitAndAssign for BoxedUint
Source§fn bitand_assign(&mut self, other: BoxedUint)
fn bitand_assign(&mut self, other: BoxedUint)
&=
operation. Read moreSource§impl BitOps for BoxedUint
impl BitOps for BoxedUint
Source§fn bits_precision(&self) -> u32
fn bits_precision(&self) -> u32
Source§fn bytes_precision(&self) -> usize
fn bytes_precision(&self) -> usize
Source§fn leading_zeros(&self) -> u32
fn leading_zeros(&self) -> u32
Source§fn bit(&self, index: u32) -> Choice
fn bit(&self, index: u32) -> Choice
index
, as a truthy or falsy Choice
.
Returns the falsy value for indices out of range.Source§fn set_bit(&mut self, index: u32, bit_value: Choice)
fn set_bit(&mut self, index: u32, bit_value: Choice)
index
to 0 or 1 depending on the value of bit_value
.Source§fn trailing_zeros(&self) -> u32
fn trailing_zeros(&self) -> u32
Source§fn trailing_ones(&self) -> u32
fn trailing_ones(&self) -> u32
Source§fn bit_vartime(&self, index: u32) -> bool
fn bit_vartime(&self, index: u32) -> bool
Source§fn bits_vartime(&self) -> u32
fn bits_vartime(&self) -> u32
self
.Source§fn set_bit_vartime(&mut self, index: u32, bit_value: bool)
fn set_bit_vartime(&mut self, index: u32, bit_value: bool)
index
to 0 or 1 depending on the value of bit_value
,
variable time in self
.Source§fn trailing_zeros_vartime(&self) -> u32
fn trailing_zeros_vartime(&self) -> u32
self
.Source§fn trailing_ones_vartime(&self) -> u32
fn trailing_ones_vartime(&self) -> u32
self
.Source§fn leading_zeros_vartime(&self) -> u32
fn leading_zeros_vartime(&self) -> u32
Source§impl BitOrAssign<&BoxedUint> for BoxedUint
impl BitOrAssign<&BoxedUint> for BoxedUint
Source§fn bitor_assign(&mut self, other: &BoxedUint)
fn bitor_assign(&mut self, other: &BoxedUint)
|=
operation. Read moreSource§impl BitOrAssign for BoxedUint
impl BitOrAssign for BoxedUint
Source§fn bitor_assign(&mut self, other: BoxedUint)
fn bitor_assign(&mut self, other: BoxedUint)
|=
operation. Read moreSource§impl BitXorAssign<&BoxedUint> for BoxedUint
impl BitXorAssign<&BoxedUint> for BoxedUint
Source§fn bitxor_assign(&mut self, other: &BoxedUint)
fn bitxor_assign(&mut self, other: &BoxedUint)
^=
operation. Read moreSource§impl BitXorAssign for BoxedUint
impl BitXorAssign for BoxedUint
Source§fn bitxor_assign(&mut self, other: BoxedUint)
fn bitxor_assign(&mut self, other: BoxedUint)
^=
operation. Read moreSource§impl CheckedAdd for BoxedUint
impl CheckedAdd for BoxedUint
Source§impl CheckedDiv for BoxedUint
impl CheckedDiv for BoxedUint
Source§impl CheckedMul for BoxedUint
impl CheckedMul for BoxedUint
Source§impl CheckedSub for BoxedUint
impl CheckedSub for BoxedUint
Source§impl ConcatenatingMul<&BoxedUint> for BoxedUint
impl ConcatenatingMul<&BoxedUint> for BoxedUint
Source§impl ConcatenatingMul for BoxedUint
impl ConcatenatingMul for BoxedUint
Source§impl ConditionallyNegatable for BoxedUint
impl ConditionallyNegatable for BoxedUint
Source§fn conditional_negate(&mut self, choice: Choice)
fn conditional_negate(&mut self, choice: Choice)
Source§impl ConstantTimeEq for BoxedUint
impl ConstantTimeEq for BoxedUint
Source§impl ConstantTimeGreater for BoxedUint
impl ConstantTimeGreater for BoxedUint
Source§impl ConstantTimeLess for BoxedUint
impl ConstantTimeLess for BoxedUint
Source§impl ConstantTimeSelect for BoxedUint
NOTE: can’t impl subtle
’s ConditionallySelectable
trait due to its Copy
bound
impl ConstantTimeSelect for BoxedUint
NOTE: can’t impl subtle
’s ConditionallySelectable
trait due to its Copy
bound
Source§impl DivRemLimb for BoxedUint
impl DivRemLimb for BoxedUint
Source§fn div_rem_limb_with_reciprocal(
&self,
reciprocal: &Reciprocal,
) -> (BoxedUint, Limb)
fn div_rem_limb_with_reciprocal( &self, reciprocal: &Reciprocal, ) -> (BoxedUint, Limb)
self / rhs
, returns the quotient (q) and remainder (r).Source§impl DivVartime for BoxedUint
impl DivVartime for BoxedUint
Source§impl Gcd<BoxedUint> for Odd<BoxedUint>
impl Gcd<BoxedUint> for Odd<BoxedUint>
Source§impl Gcd for BoxedUint
impl Gcd for BoxedUint
Source§impl Integer for BoxedUint
impl Integer for BoxedUint
Source§type Monty = BoxedMontyForm
type Monty = BoxedMontyForm
Source§impl MulAssign<&BoxedUint> for BoxedUint
impl MulAssign<&BoxedUint> for BoxedUint
Source§fn mul_assign(&mut self, rhs: &BoxedUint)
fn mul_assign(&mut self, rhs: &BoxedUint)
*=
operation. Read moreSource§impl MulAssign for BoxedUint
impl MulAssign for BoxedUint
Source§fn mul_assign(&mut self, rhs: BoxedUint)
fn mul_assign(&mut self, rhs: BoxedUint)
*=
operation. Read moreSource§impl Ord for BoxedUint
impl Ord for BoxedUint
Source§impl PartialOrd<Odd<BoxedUint>> for BoxedUint
impl PartialOrd<Odd<BoxedUint>> for BoxedUint
Source§impl PartialOrd for BoxedUint
impl PartialOrd for BoxedUint
Source§impl Resize for &BoxedUint
impl Resize for &BoxedUint
Source§fn resize_unchecked(
self,
at_least_bits_precision: u32,
) -> <&BoxedUint as Resize>::Output
fn resize_unchecked( self, at_least_bits_precision: u32, ) -> <&BoxedUint as Resize>::Output
at_least_bits_precision
without checking if the bit size of self
is larger than at_least_bits_precision
. Read moreSource§impl Resize for BoxedUint
impl Resize for BoxedUint
Source§fn resize_unchecked(
self,
at_least_bits_precision: u32,
) -> <BoxedUint as Resize>::Output
fn resize_unchecked( self, at_least_bits_precision: u32, ) -> <BoxedUint as Resize>::Output
at_least_bits_precision
without checking if the bit size of self
is larger than at_least_bits_precision
. Read moreSource§impl ShlAssign<i32> for BoxedUint
impl ShlAssign<i32> for BoxedUint
Source§fn shl_assign(&mut self, shift: i32)
fn shl_assign(&mut self, shift: i32)
<<=
operation. Read moreSource§impl ShlAssign<u32> for BoxedUint
impl ShlAssign<u32> for BoxedUint
Source§fn shl_assign(&mut self, shift: u32)
fn shl_assign(&mut self, shift: u32)
<<=
operation. Read moreSource§impl ShlAssign<usize> for BoxedUint
impl ShlAssign<usize> for BoxedUint
Source§fn shl_assign(&mut self, shift: usize)
fn shl_assign(&mut self, shift: usize)
<<=
operation. Read moreSource§impl ShlVartime for BoxedUint
impl ShlVartime for BoxedUint
Source§impl ShrAssign<i32> for BoxedUint
impl ShrAssign<i32> for BoxedUint
Source§fn shr_assign(&mut self, shift: i32)
fn shr_assign(&mut self, shift: i32)
>>=
operation. Read moreSource§impl ShrAssign<u32> for BoxedUint
impl ShrAssign<u32> for BoxedUint
Source§fn shr_assign(&mut self, shift: u32)
fn shr_assign(&mut self, shift: u32)
>>=
operation. Read moreSource§impl ShrAssign<usize> for BoxedUint
impl ShrAssign<usize> for BoxedUint
Source§fn shr_assign(&mut self, shift: usize)
fn shr_assign(&mut self, shift: usize)
>>=
operation. Read moreSource§impl ShrVartime for BoxedUint
impl ShrVartime for BoxedUint
Source§impl SquareRoot for BoxedUint
impl SquareRoot for BoxedUint
Source§impl SubAssign<&BoxedUint> for BoxedUint
impl SubAssign<&BoxedUint> for BoxedUint
Source§fn sub_assign(&mut self, rhs: &BoxedUint)
fn sub_assign(&mut self, rhs: &BoxedUint)
-=
operation. Read moreSource§impl<const LIMBS: usize> SubAssign<&Uint<LIMBS>> for BoxedUint
impl<const LIMBS: usize> SubAssign<&Uint<LIMBS>> for BoxedUint
Source§fn sub_assign(&mut self, rhs: &Uint<LIMBS>)
fn sub_assign(&mut self, rhs: &Uint<LIMBS>)
-=
operation. Read moreSource§impl<const LIMBS: usize> SubAssign<Uint<LIMBS>> for BoxedUint
impl<const LIMBS: usize> SubAssign<Uint<LIMBS>> for BoxedUint
Source§fn sub_assign(&mut self, rhs: Uint<LIMBS>)
fn sub_assign(&mut self, rhs: Uint<LIMBS>)
-=
operation. Read moreSource§impl SubAssign<u128> for BoxedUint
impl SubAssign<u128> for BoxedUint
Source§fn sub_assign(&mut self, rhs: u128)
fn sub_assign(&mut self, rhs: u128)
-=
operation. Read moreSource§impl SubAssign<u16> for BoxedUint
impl SubAssign<u16> for BoxedUint
Source§fn sub_assign(&mut self, rhs: u16)
fn sub_assign(&mut self, rhs: u16)
-=
operation. Read moreSource§impl SubAssign<u32> for BoxedUint
impl SubAssign<u32> for BoxedUint
Source§fn sub_assign(&mut self, rhs: u32)
fn sub_assign(&mut self, rhs: u32)
-=
operation. Read moreSource§impl SubAssign<u64> for BoxedUint
impl SubAssign<u64> for BoxedUint
Source§fn sub_assign(&mut self, rhs: u64)
fn sub_assign(&mut self, rhs: u64)
-=
operation. Read moreSource§impl SubAssign<u8> for BoxedUint
impl SubAssign<u8> for BoxedUint
Source§fn sub_assign(&mut self, rhs: u8)
fn sub_assign(&mut self, rhs: u8)
-=
operation. Read moreSource§impl SubAssign for BoxedUint
impl SubAssign for BoxedUint
Source§fn sub_assign(&mut self, rhs: BoxedUint)
fn sub_assign(&mut self, rhs: BoxedUint)
-=
operation. Read moreSource§impl WrappingAdd for BoxedUint
impl WrappingAdd for BoxedUint
Source§fn wrapping_add(&self, v: &BoxedUint) -> BoxedUint
fn wrapping_add(&self, v: &BoxedUint) -> BoxedUint
self + other
, wrapping around at the boundary of
the type.Source§impl WrappingMul for BoxedUint
impl WrappingMul for BoxedUint
Source§fn wrapping_mul(&self, v: &BoxedUint) -> BoxedUint
fn wrapping_mul(&self, v: &BoxedUint) -> BoxedUint
self * other
, wrapping around at the boundary
of the type.Source§impl WrappingNeg for BoxedUint
impl WrappingNeg for BoxedUint
Source§fn wrapping_neg(&self) -> BoxedUint
fn wrapping_neg(&self) -> BoxedUint
-self
,
wrapping around at the boundary of the type. Read moreSource§impl WrappingShl for BoxedUint
impl WrappingShl for BoxedUint
Source§impl WrappingShr for BoxedUint
impl WrappingShr for BoxedUint
Source§impl WrappingSub for BoxedUint
impl WrappingSub for BoxedUint
Source§fn wrapping_sub(&self, v: &BoxedUint) -> BoxedUint
fn wrapping_sub(&self, v: &BoxedUint) -> BoxedUint
self - other
, wrapping around at the boundary
of the type.impl Eq for BoxedUint
Auto Trait Implementations§
impl Freeze for BoxedUint
impl RefUnwindSafe for BoxedUint
impl Send for BoxedUint
impl Sync for BoxedUint
impl Unpin for BoxedUint
impl UnwindSafe for BoxedUint
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§impl<T, Rhs> WideningMul<Rhs> for Twhere
T: ConcatenatingMul<Rhs>,
impl<T, Rhs> WideningMul<Rhs> for Twhere
T: ConcatenatingMul<Rhs>,
Source§type Output = <T as ConcatenatingMul<Rhs>>::Output
type Output = <T as ConcatenatingMul<Rhs>>::Output
ConcatenatingMul
insteadSource§fn widening_mul(&self, rhs: Rhs) -> <T as WideningMul<Rhs>>::Output
fn widening_mul(&self, rhs: Rhs) -> <T as WideningMul<Rhs>>::Output
ConcatenatingMul
instead