Struct crypto_bigint::UInt

source ·
pub struct UInt<const LIMBS: usize> { /* private fields */ }
Expand description

Big unsigned integer.

Generic over the given number of LIMBS

Encoding support

This type supports many different types of encodings, either via the Encoding trait or various const fn decoding and encoding functions that can be used with UInt constants.

Optional crate features for encoding (off-by-default):

Implementations§

Computes a + b + carry, returning the result along with the new carry.

Perform saturating addition, returning MAX on overflow.

Perform wrapping addition, discarding overflow.

Computes self + rhs mod p in constant time.

Assumes self and rhs are < p.

Computes bitwise a & b.

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

Perform checked bitwise AND, returning a CtOption which is_some always

Computes bitwise !a.

Computes bitwise a & b.

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

Perform checked bitwise OR, returning a CtOption which is_some always

Computes bitwise a ^ b.

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

Perform checked bitwise XOR, returning a CtOption which is_some always

Calculate the number of bits needed to represent this number.

Computes self / rhs, returns the quotient, remainder if rhs != 0

Computes self % rhs, returns the remainder if rhs != 0

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.

Perform checked division, returning a CtOption which is_some only if the rhs != 0

Wrapped (modular) remainder calculation is just self % rhs. There’s no way wrapping could ever happen. This function exists, so that all operations are accounted for in the wrapping operations.

Perform checked reduction, returning a CtOption which is_some only if the rhs != 0

Create a new UInt from the provided big endian bytes.

Create a new UInt from the provided big endian hex string.

Create a new UInt from the provided little endian bytes.

Create a new UInt from the provided little endian hex string.

Create a UInt from a u8 (const-friendly)

Create a UInt from a u16 (const-friendly)

Create a UInt from a u32 (const-friendly)

Create a UInt from a u64 (const-friendly)

Create a UInt from a u128 (const-friendly)

Create a UInt from an array of the LimbUInt unsigned integer type.

Create an array of LimbUInt unsigned integers from a UInt.

Compute “wide” multiplication, with a product twice the size of the input.

Returns a tuple containing the (lo, hi) components of the product.

Ordering note

Releases of crypto-bigint prior to v0.3 used (hi, lo) ordering instead. This has been changed for better consistency with the rest of the APIs in this crate.

For more info see: https://github.com/RustCrypto/crypto-bigint/issues/4

Perform saturating multiplication, returning MAX on overflow.

Perform wrapping multiplication, discarding overflow.

Square self, returning a “wide” result.

Computes -a mod p in constant time.

Computes self << shift.

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.

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.

Computes √(self) Uses Brent & Zimmermann, Modern Computer Arithmetic, v0.5.9, Algorithm 1.13

Callers can check if self is a square by squaring the result

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.

Perform checked sqrt, returning a CtOption which is_some only if the √(self)² == self

Computes a - (b + borrow), returning the result along with the new borrow.

Perform saturating subtraction, returning ZERO on underflow.

Perform wrapping subtraction, discarding underflow and wrapping around the boundary of the type.

Computes self - rhs mod p in constant time.

Assumes self and rhs are < p.

The value 0.

The value 1.

Maximum value this UInt can express.

Const-friendly UInt constructor.

Borrow the limbs of this UInt.

Convert this UInt into its inner limbs.

Trait Implementations§

Output type.
Compute self + rhs mod p. Read more
Output type.
Compute self + rhs mod p. Read more
Output type.
Compute self + rhs mod p. Read more
Output type.
Compute self + rhs mod p. Read more
Output type.
Compute self + rhs mod p. Read more
Output type.
Compute self + rhs mod p. Read more
Output type.
Compute self + rhs mod p. Read more
Output type.
Compute self + rhs mod p. Read more
Output type.
Compute self + rhs mod p. Read more
Output type.
Compute self + rhs mod p. Read more
Output type.
Compute self + rhs mod p. Read more
Output type.
Compute self + rhs mod p. Read more
Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
The resulting type after applying the & operator.
Performs the & operation. Read more
The resulting type after applying the & operator.
Performs the & operation. Read more
The resulting type after applying the & operator.
Performs the & operation. Read more
The resulting type after applying the & operator.
Performs the & operation. Read more
Performs the &= operation. Read more
Performs the &= operation. Read more
The resulting type after applying the | operator.
Performs the | operation. Read more
The resulting type after applying the | operator.
Performs the | operation. Read more
The resulting type after applying the | operator.
Performs the | operation. Read more
The resulting type after applying the | operator.
Performs the | operation. Read more
Performs the |= operation. Read more
Performs the |= operation. Read more
The resulting type after applying the ^ operator.
Performs the ^ operation. Read more
The resulting type after applying the ^ operator.
Performs the ^ operation. Read more
The resulting type after applying the ^ operator.
Performs the ^ operation. Read more
The resulting type after applying the ^ operator.
Performs the ^ operation. Read more
Performs the ^= operation. Read more
Performs the ^= operation. Read more
Output type.
Perform checked subtraction, returning a CtOption which is_some only if the operation did not overflow. Read more
Output type.
Perform checked multiplication, returning a CtOption which is_some only if the operation did not overflow. Read more
Output type.
Perform checked subtraction, returning a CtOption which is_some only if the operation did not underflow. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Concatenated output: twice the width of Self.
Concate the two values, with self as most significant and rhs as the least significant. Read more
Concatenated output: twice the width of Self.
Concate the two values, with self as most significant and rhs as the least significant. Read more
Concatenated output: twice the width of Self.
Concate the two values, with self as most significant and rhs as the least significant. Read more
Concatenated output: twice the width of Self.
Concate the two values, with self as most significant and rhs as the least significant. Read more
Concatenated output: twice the width of Self.
Concate the two values, with self as most significant and rhs as the least significant. Read more
Concatenated output: twice the width of Self.
Concate the two values, with self as most significant and rhs as the least significant. Read more
Concatenated output: twice the width of Self.
Concate the two values, with self as most significant and rhs as the least significant. Read more
Concatenated output: twice the width of Self.
Concate the two values, with self as most significant and rhs as the least significant. Read more
Concatenated output: twice the width of Self.
Concate the two values, with self as most significant and rhs as the least significant. Read more
Concatenated output: twice the width of Self.
Concate the two values, with self as most significant and rhs as the least significant. Read more
Concatenated output: twice the width of Self.
Concate the two values, with self as most significant and rhs as the least significant. Read more
Concatenated output: twice the width of Self.
Concate the two values, with self as most significant and rhs as the least significant. Read more
Concatenated output: twice the width of Self.
Concate the two values, with self as most significant and rhs as the least significant. Read more
Concatenated output: twice the width of Self.
Concate the two values, with self as most significant and rhs as the least significant. Read more
Concatenated output: twice the width of Self.
Concate the two values, with self as most significant and rhs as the least significant. Read more
Select a or b according to choice. Read more
Conditionally assign other to self, according to choice. Read more
Conditionally swap self and other if choice == 1; otherwise, reassign both unto themselves. Read more
Determine if two items are equal. Read more
Determine whether self > other. Read more
Determine whether self < other. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Formats the value using the given formatter. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
Performs the /= operation. Read more
Performs the /= operation. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
The value 1.
Maximum value this integer can express.
Is this integer value an odd number? Read more
Is this integer value an even number? Read more
Formats the value using the given formatter.
Output type.
Compute -self mod p.
Output type.
Compute -self mod p.
Output type.
Compute -self mod p.
Output type.
Compute -self mod p.
Output type.
Compute -self mod p.
Output type.
Compute -self mod p.
Output type.
Compute -self mod p.
Output type.
Compute -self mod p.
Output type.
Compute -self mod p.
Output type.
Compute -self mod p.
Output type.
Compute -self mod p.
Output type.
Compute -self mod p.
The resulting type after applying the ! operator.
Performs the unary ! operation. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Generate a cryptographically secure random UInt.

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.

The resulting type after applying the % operator.
Performs the % operation. Read more
The resulting type after applying the % operator.
Performs the % operation. Read more
The resulting type after applying the % operator.
Performs the % operation. Read more
The resulting type after applying the % operator.
Performs the % operation. Read more
Performs the %= operation. Read more
Performs the %= operation. Read more

NOTE: this operation is variable time with respect to rhs ONLY.

When used with a fixed rhs, this function is constant-time with respect to self.

The resulting type after applying the << operator.

NOTE: this operation is variable time with respect to rhs ONLY.

When used with a fixed rhs, this function is constant-time with respect to self.

The resulting type after applying the << operator.

NOTE: this operation is variable time with respect to rhs ONLY.

When used with a fixed rhs, this function is constant-time with respect to self.

NOTE: this operation is variable time with respect to rhs ONLY.

When used with a fixed rhs, this function is constant-time with respect to self.

The resulting type after applying the >> operator.

NOTE: this operation is variable time with respect to rhs ONLY.

When used with a fixed rhs, this function is constant-time with respect to self.

The resulting type after applying the >> operator.
Performs the >>= operation. Read more
Split output: high/low components of the value.
Split this number in half, returning its high and low components respectively. Read more
Split output: high/low components of the value.
Split this number in half, returning its high and low components respectively. Read more
Split output: high/low components of the value.
Split this number in half, returning its high and low components respectively. Read more
Split output: high/low components of the value.
Split this number in half, returning its high and low components respectively. Read more
Split output: high/low components of the value.
Split this number in half, returning its high and low components respectively. Read more
Split output: high/low components of the value.
Split this number in half, returning its high and low components respectively. Read more
Split output: high/low components of the value.
Split this number in half, returning its high and low components respectively. Read more
Split output: high/low components of the value.
Split this number in half, returning its high and low components respectively. Read more
Split output: high/low components of the value.
Split this number in half, returning its high and low components respectively. Read more
Split output: high/low components of the value.
Split this number in half, returning its high and low components respectively. Read more
Split output: high/low components of the value.
Split this number in half, returning its high and low components respectively. Read more
Split output: high/low components of the value.
Split this number in half, returning its high and low components respectively. Read more
Split output: high/low components of the value.
Split this number in half, returning its high and low components respectively. Read more
Split output: high/low components of the value.
Split this number in half, returning its high and low components respectively. Read more
Split output: high/low components of the value.
Split this number in half, returning its high and low components respectively. Read more
Split output: high/low components of the value.
Split this number in half, returning its high and low components respectively. Read more
Split output: high/low components of the value.
Split this number in half, returning its high and low components respectively. Read more
Output type.
Compute self - rhs mod p. Read more
Output type.
Compute self - rhs mod p. Read more
Output type.
Compute self - rhs mod p. Read more
Output type.
Compute self - rhs mod p. Read more
Output type.
Compute self - rhs mod p. Read more
Output type.
Compute self - rhs mod p. Read more
Output type.
Compute self - rhs mod p. Read more
Output type.
Compute self - rhs mod p. Read more
Output type.
Compute self - rhs mod p. Read more
Output type.
Compute self - rhs mod p. Read more
Output type.
Compute self - rhs mod p. Read more
Output type.
Compute self - rhs mod p. Read more
Formats the value using the given formatter.
The value 0.
Determine if this value is equal to zero. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler. Read more