Struct UnsignedInteger

Source
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

Source

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

Source

pub fn square(&self) -> UnsignedInteger

Computes $x^2$, where $x$ is self. This is typically faster than performing a multiplication.

Source§

impl UnsignedInteger

Source

pub fn eq_leaky(&self, other: &Self) -> bool

Checks if self equals other. This function is not constant-time.

Source

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

Source

pub fn leak(&self) -> LeakyUnsignedInteger<'_>

Outputs a LeakyUnsignedInteger, which supports overloaded operators for equality and comparisons. This makes it explicit that these operations are not constant-time.

Source§

impl UnsignedInteger

Source

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.

Source

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

Source

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

Source

pub fn to_rug(self) -> Integer

Transforms this UnsignedInteger into a rug Integer.

Source§

impl UnsignedInteger

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn random_below<R: SecureRng>( limit: &UnsignedInteger, rng: &mut GeneralRng<R>, ) -> Self

Generates a random unsigned number below limit.

Source

pub fn set_bit_leaky(&mut self, bit_index: u32)

Sets the bit at bit_index to 1. This function is not constant-time.

Source

pub fn clear_bit_leaky(&mut self, bit_index: u32)

Sets the bit at bit_index to 0. This function is not constant-time.

Source

pub fn mod_u_leaky(&self, modulus: u64) -> u64

Computes self modulo a u64 number. This function is not constant-time.

Source

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.

Source

pub fn is_zero_leaky(&self) -> bool

Returns true if self == 0. This can be faster than checking equality.

Source

pub fn lcm_leaky(&self, other: &UnsignedInteger) -> UnsignedInteger

Computes the least common multiple between self and other. This function is not constant-time.

Source

pub fn factorial_leaky(n: u64) -> Self

Computes $n!$. This function is not constant-time.

Source

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

Source§

type Output = UnsignedInteger

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<u64> for UnsignedInteger

Source§

type Output = UnsignedInteger

The resulting type after applying the + operator.
Source§

fn add(self, rhs: u64) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign<&UnsignedInteger> for UnsignedInteger

Source§

fn add_assign(&mut self, rhs: &Self)

Performs the += operation. Read more
Source§

impl AddAssign<u64> for UnsignedInteger

Source§

fn add_assign(&mut self, rhs: u64)

Performs the += operation. Read more
Source§

impl Clone for UnsignedInteger

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UnsignedInteger

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for UnsignedInteger

Source§

fn deserialize<D: Deserializer<'de>>( deserializer: D, ) -> Result<UnsignedInteger, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for UnsignedInteger

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div<&UnsignedInteger> for UnsignedInteger

Source§

type Output = UnsignedInteger

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &UnsignedInteger) -> UnsignedInteger

Performs the / operation. Read more
Source§

impl Drop for UnsignedInteger

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl From<Integer> for UnsignedInteger

Source§

fn from(integer: Integer) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for UnsignedInteger

Source§

fn from(integer: u64) -> Self

Converts to this type from the input type.
Source§

impl Hash for UnsignedInteger

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Mul for &UnsignedInteger

Source§

type Output = UnsignedInteger

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl PartialEq for UnsignedInteger

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Product<&'a UnsignedInteger> for UnsignedInteger

Source§

fn product<I: Iterator<Item = &'a UnsignedInteger>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl Rem<&UnsignedInteger> for UnsignedInteger

Source§

type Output = UnsignedInteger

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: &UnsignedInteger) -> Self::Output

Performs the % operation. Read more
Source§

impl RemAssign<&UnsignedInteger> for UnsignedInteger

Source§

fn rem_assign(&mut self, rhs: &Self)

Performs the %= operation. Read more
Source§

impl Serialize for UnsignedInteger

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl Shr<u32> for &UnsignedInteger

Source§

type Output = UnsignedInteger

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: u32) -> Self::Output

Performs the >> operation. Read more
Source§

impl ShrAssign<u32> for UnsignedInteger

Source§

fn shr_assign(&mut self, rhs: u32)

Performs the >>= operation. Read more
Source§

impl Sub<&UnsignedInteger> for UnsignedInteger

Source§

type Output = UnsignedInteger

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &UnsignedInteger) -> Self::Output

Performs the - operation. Read more
Source§

impl SubAssign<&UnsignedInteger> for UnsignedInteger

Source§

fn sub_assign(&mut self, rhs: &UnsignedInteger)

Performs the -= operation. Read more
Source§

impl SubAssign<u64> for UnsignedInteger

Source§

fn sub_assign(&mut self, rhs: u64)

Performs the -= operation. Read more
Source§

impl<'a> Sum<&'a UnsignedInteger> for UnsignedInteger

Source§

fn sum<I: Iterator<Item = &'a UnsignedInteger>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl Eq for UnsignedInteger

Source§

impl Send for UnsignedInteger

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,