pub struct UInt<const LIMBS: usize> { /* fields omitted */ }
Expand description
Big unsigned integer.
Generic over the given number of LIMBS
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):
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
.
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
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
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.
Compute “wide” multiplication, with a product twice the size of the input.
Returns a tuple containing the (lo, hi)
components of the product.
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
.
Maximum value this UInt
can express.
Const-friendly UInt
constructor.
Borrow the limbs of this UInt
.
Convert this UInt
into its inner limbs.
The resulting type after applying the &
operator.
The resulting type after applying the &
operator.
The resulting type after applying the &
operator.
The resulting type after applying the &
operator.
The resulting type after applying the |
operator.
The resulting type after applying the |
operator.
The resulting type after applying the |
operator.
The resulting type after applying the |
operator.
The resulting type after applying the ^
operator.
The resulting type after applying the ^
operator.
The resulting type after applying the ^
operator.
The resulting type after applying the ^
operator.
Perform checked subtraction, returning a CtOption
which is_some
only if the operation did not overflow. Read more
Perform checked multiplication, returning a CtOption
which is_some
only if the operation did not overflow. Read more
Perform checked subtraction, returning a CtOption
which is_some
only if the operation did not underflow. 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
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
Formats the value using the given formatter. Read more
This is supported on crate feature rlp
only.
Decode a value from RLP bytes
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.
The resulting type after applying the /
operator.
The resulting type after applying the /
operator.
The resulting type after applying the /
operator.
This is supported on crate feature rlp
only.
Append a value to the stream
Get rlp-encoded bytes for this instance
impl From<(UInt<{nlimbs!($bits)}>, UInt<{nlimbs!($bits)}>)> for UInt<{ 64 / crate::Limb::BIT_SIZE * 2 }>
impl From<(UInt<{nlimbs!($bits)}>, UInt<{nlimbs!($bits)}>)> for UInt<{ 128 / crate::Limb::BIT_SIZE * 2 }>
impl From<(UInt<{nlimbs!($bits)}>, UInt<{nlimbs!($bits)}>)> for UInt<{ 1536 / crate::Limb::BIT_SIZE * 2 }>
impl From<(UInt<{nlimbs!($bits)}>, UInt<{nlimbs!($bits)}>)> for UInt<{ 1792 / crate::Limb::BIT_SIZE * 2 }>
impl From<(UInt<{nlimbs!($bits)}>, UInt<{nlimbs!($bits)}>)> for UInt<{ 2048 / crate::Limb::BIT_SIZE * 2 }>
impl From<(UInt<{nlimbs!($bits)}>, UInt<{nlimbs!($bits)}>)> for UInt<{ 3072 / crate::Limb::BIT_SIZE * 2 }>
impl From<(UInt<{nlimbs!($bits)}>, UInt<{nlimbs!($bits)}>)> for UInt<{ 4096 / crate::Limb::BIT_SIZE * 2 }>
impl From<(UInt<{nlimbs!($bits)}>, UInt<{nlimbs!($bits)}>)> for UInt<{ 192 / crate::Limb::BIT_SIZE * 2 }>
impl From<(UInt<{nlimbs!($bits)}>, UInt<{nlimbs!($bits)}>)> for UInt<{ 256 / crate::Limb::BIT_SIZE * 2 }>
impl From<(UInt<{nlimbs!($bits)}>, UInt<{nlimbs!($bits)}>)> for UInt<{ 384 / crate::Limb::BIT_SIZE * 2 }>
impl From<(UInt<{nlimbs!($bits)}>, UInt<{nlimbs!($bits)}>)> for UInt<{ 448 / crate::Limb::BIT_SIZE * 2 }>
impl From<(UInt<{nlimbs!($bits)}>, UInt<{nlimbs!($bits)}>)> for UInt<{ 512 / crate::Limb::BIT_SIZE * 2 }>
impl From<(UInt<{nlimbs!($bits)}>, UInt<{nlimbs!($bits)}>)> for UInt<{ 768 / crate::Limb::BIT_SIZE * 2 }>
impl From<(UInt<{nlimbs!($bits)}>, UInt<{nlimbs!($bits)}>)> for UInt<{ 896 / crate::Limb::BIT_SIZE * 2 }>
impl From<(UInt<{nlimbs!($bits)}>, UInt<{nlimbs!($bits)}>)> for UInt<{ 1024 / crate::Limb::BIT_SIZE * 2 }>
impl From<UInt<{nlimbs!($bits)}>> for u64
This is supported on 32-bit only.
impl From<UInt<{nlimbs!($bits)}>> for (UInt<{ 1024 / crate::Limb::BIT_SIZE / 2 }>, UInt<{ 1024 / crate::Limb::BIT_SIZE / 2 }>)
impl From<UInt<{nlimbs!($bits)}>> for (UInt<{ 1536 / crate::Limb::BIT_SIZE / 2 }>, UInt<{ 1536 / crate::Limb::BIT_SIZE / 2 }>)
impl From<UInt<{nlimbs!($bits)}>> for (UInt<{ 1792 / crate::Limb::BIT_SIZE / 2 }>, UInt<{ 1792 / crate::Limb::BIT_SIZE / 2 }>)
impl From<UInt<{nlimbs!($bits)}>> for (UInt<{ 2048 / crate::Limb::BIT_SIZE / 2 }>, UInt<{ 2048 / crate::Limb::BIT_SIZE / 2 }>)
impl From<UInt<{nlimbs!($bits)}>> for (UInt<{ 3072 / crate::Limb::BIT_SIZE / 2 }>, UInt<{ 3072 / crate::Limb::BIT_SIZE / 2 }>)
impl From<UInt<{nlimbs!($bits)}>> for (UInt<{ 3584 / crate::Limb::BIT_SIZE / 2 }>, UInt<{ 3584 / crate::Limb::BIT_SIZE / 2 }>)
impl From<UInt<{nlimbs!($bits)}>> for (UInt<{ 4096 / crate::Limb::BIT_SIZE / 2 }>, UInt<{ 4096 / crate::Limb::BIT_SIZE / 2 }>)
impl From<UInt<{nlimbs!($bits)}>> for (UInt<{ 6144 / crate::Limb::BIT_SIZE / 2 }>, UInt<{ 6144 / crate::Limb::BIT_SIZE / 2 }>)
impl From<UInt<{nlimbs!($bits)}>> for (UInt<{ 8192 / crate::Limb::BIT_SIZE / 2 }>, UInt<{ 8192 / crate::Limb::BIT_SIZE / 2 }>)
impl From<UInt<{nlimbs!($bits)}>> for (UInt<{ 128 / crate::Limb::BIT_SIZE / 2 }>, UInt<{ 128 / crate::Limb::BIT_SIZE / 2 }>)
impl From<UInt<{nlimbs!($bits)}>> for (UInt<{ 192 / crate::Limb::BIT_SIZE / 2 }>, UInt<{ 192 / crate::Limb::BIT_SIZE / 2 }>)
impl From<UInt<{nlimbs!($bits)}>> for (UInt<{ 256 / crate::Limb::BIT_SIZE / 2 }>, UInt<{ 256 / crate::Limb::BIT_SIZE / 2 }>)
impl From<UInt<{nlimbs!($bits)}>> for (UInt<{ 384 / crate::Limb::BIT_SIZE / 2 }>, UInt<{ 384 / crate::Limb::BIT_SIZE / 2 }>)
impl From<UInt<{nlimbs!($bits)}>> for (UInt<{ 448 / crate::Limb::BIT_SIZE / 2 }>, UInt<{ 448 / crate::Limb::BIT_SIZE / 2 }>)
impl From<UInt<{nlimbs!($bits)}>> for (UInt<{ 512 / crate::Limb::BIT_SIZE / 2 }>, UInt<{ 512 / crate::Limb::BIT_SIZE / 2 }>)
impl From<UInt<{nlimbs!($bits)}>> for (UInt<{ 768 / crate::Limb::BIT_SIZE / 2 }>, UInt<{ 768 / crate::Limb::BIT_SIZE / 2 }>)
impl From<UInt<{nlimbs!($bits)}>> for (UInt<{ 896 / crate::Limb::BIT_SIZE / 2 }>, UInt<{ 896 / crate::Limb::BIT_SIZE / 2 }>)
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.
The resulting type after applying the !
operator.
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 !=
.
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
impl<const LIMBS: usize> Random for UInt<LIMBS>
This is supported on crate feature rand_core
only.
Generate a cryptographically secure random UInt
.
This is supported on crate feature rand_core
only.
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.
The resulting type after applying the %
operator.
The resulting type after applying the %
operator.
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
.
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.
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
Formats the value using the given formatter.
Determine if this value is equal to zero. Read more
This is supported on crate feature zeroize
only.
impl<T> Any for T where
T: 'static + ?Sized,
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
impl<T, U> Into<U> for T where
U: From<T>,
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
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.
The type returned in the event of a conversion error.
Zero out this object from memory using Rust intrinsics which ensure the
zeroization operation is not “optimized away” by the compiler. Read more