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 wrapping addition, discarding overflow.
Perform checked addition, returning a CtOption
which is_some
only
if the operation did not 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
Determine if this UInt
is equal to zero.
If zero, return Choice(1)
. Otherwise, return Choice(0)
.
Is this UInt
an odd 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)
This is supported on 64-bit only.
Create a UInt
from a u64
(const-friendly)
Create a UInt
from a u128
(const-friendly)
Compute “wide” multiplication, with a product twice the size of the input.
Perform wrapping multiplication, discarding overflow.
Perform checked multiplication, returning a CtOption
which is_some
only if the operation did not overflow.
Square self, returning a “wide” result.
Computes -a mod p
in constant time.
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 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 wrapping subtraction, discarding underflow and wrapping around
the boundary of the type.
Perform checked subtraction, returning a CtOption
which is_some
only if the operation did not overflow.
Computes self - rhs mod p
in constant time.
Assumes self
and rhs
are < p
.
This is supported on crate feature rand
only.
Generate a cryptographically secure random UInt
.
This is supported on crate feature rand
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.
Maximum value this UInt
can express.
Const-friendly UInt
constructor.
Borrow the limbs of this UInt
.
Convert this UInt
into its inner limbs.
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 64-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?
Is this integer value equal to zero?
Is this integer value an even number?
Formats the value using the given formatter.
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
only.
Generate a cryptographically secure random value.
This is supported on crate feature rand
only.
Generate a cryptographically secure random number which is less than
a given modulus
. 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.
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.
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