pub struct Odd<T: ?Sized>(/* private fields */);Expand description
Wrapper type for odd integers.
These are frequently used in cryptography, e.g. as a modulus.
Implementations§
Source§impl<const LIMBS: usize> Odd<Int<LIMBS>>
impl<const LIMBS: usize> Odd<Int<LIMBS>>
Sourcepub const fn gcd_unsigned(&self, rhs: &Uint<LIMBS>) -> Odd<Uint<LIMBS>>
pub const fn gcd_unsigned(&self, rhs: &Uint<LIMBS>) -> Odd<Uint<LIMBS>>
Compute the greatest common divisor of self and rhs.
Sourcepub const fn gcd_unsigned_vartime(&self, rhs: &Uint<LIMBS>) -> OddUint<LIMBS>
pub const fn gcd_unsigned_vartime(&self, rhs: &Uint<LIMBS>) -> OddUint<LIMBS>
Compute the greatest common divisor of self and rhs.
Executes in variable time w.r.t. all input parameters.
Source§impl<const LIMBS: usize> Odd<Uint<LIMBS>>
impl<const LIMBS: usize> Odd<Uint<LIMBS>>
Sourcepub const fn from_be_hex(hex: &str) -> Self
pub const fn from_be_hex(hex: &str) -> Self
Sourcepub const fn from_le_hex(hex: &str) -> Self
pub const fn from_le_hex(hex: &str) -> Self
Create a new Odd<Uint<LIMBS>> from the provided little endian hex string.
§Panics
- if the hex is malformed or not zero-padded accordingly for the size.
- if the value is even.
Sourcepub const fn as_uint_ref(&self) -> &OddUintRef
pub const fn as_uint_ref(&self) -> &OddUintRef
Borrow this OddUint as a &OddUintRef.
Source§impl Odd<UintRef>
impl Odd<UintRef>
Sourcepub const fn to_uint_resize<const T: usize>(&self) -> Odd<Uint<T>>
pub const fn to_uint_resize<const T: usize>(&self) -> Odd<Uint<T>>
Construct an Odd<Uint<T>> from the unsigned integer value,
truncating the upper bits if the value is too large to be
represented.
Source§impl Odd<BoxedUint>
impl Odd<BoxedUint>
Sourcepub const fn as_uint_ref(&self) -> &OddUintRef
Available on crate feature alloc only.
pub const fn as_uint_ref(&self) -> &OddUintRef
alloc only.Borrow this OddBoxedUint as a &OddUintRef.
Source§impl<const LIMBS: usize> Odd<Uint<LIMBS>>
impl<const LIMBS: usize> Odd<Uint<LIMBS>>
Sourcepub const fn gcd_unsigned(&self, rhs: &Uint<LIMBS>) -> Self
pub const fn gcd_unsigned(&self, rhs: &Uint<LIMBS>) -> Self
Compute the greatest common divisor of self and rhs.
Sourcepub const fn gcd_unsigned_vartime(&self, rhs: &Uint<LIMBS>) -> Self
pub const fn gcd_unsigned_vartime(&self, rhs: &Uint<LIMBS>) -> Self
Compute the greatest common divisor of self and rhs.
Executes in variable time w.r.t. all input parameters.
Source§impl Odd<UintRef>
impl Odd<UintRef>
Sourcepub const fn invert_mod_u64(&self) -> u64
pub const fn invert_mod_u64(&self) -> u64
Returns the multiplicative inverse of the argument modulo 2^64. The implementation is based on the Hurchalla’s method for computing the multiplicative inverse modulo a power of two.
For better understanding the implementation, the following paper is recommended: J. Hurchalla, “An Improved Integer Multiplicative Inverse (modulo 2^w)”, https://arxiv.org/pdf/2204.limbs4342.pdf
Variable time with respect to the number of words in value, however that number will be
fixed for a given integer size.
Trait Implementations§
Source§impl AsRef<Odd<UintRef>> for OddBoxedUint
Available on crate feature alloc only.
impl AsRef<Odd<UintRef>> for OddBoxedUint
alloc only.Source§fn as_ref(&self) -> &OddUintRef
fn as_ref(&self) -> &OddUintRef
Source§impl<const LIMBS: usize> AsRef<Odd<UintRef>> for OddUint<LIMBS>
impl<const LIMBS: usize> AsRef<Odd<UintRef>> for OddUint<LIMBS>
Source§fn as_ref(&self) -> &OddUintRef
fn as_ref(&self) -> &OddUintRef
Source§impl<T> ConditionallySelectable for Odd<T>
Available on crate feature subtle only.
impl<T> ConditionallySelectable for Odd<T>
subtle only.Source§fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
Source§fn conditional_assign(&mut self, other: &Self, choice: Choice)
fn conditional_assign(&mut self, other: &Self, choice: Choice)
Source§fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
self and other if choice == 1; otherwise,
reassign both unto themselves. Read moreSource§impl<T> ConstantTimeEq for Odd<T>
Available on crate feature subtle only.
impl<T> ConstantTimeEq for Odd<T>
subtle only.Source§impl<T> CtAssign for Odd<T>where
T: CtAssign,
impl<T> CtAssign for Odd<T>where
T: CtAssign,
Source§impl<T> CtAssignSlice for Odd<T>where
T: CtAssignSlice,
impl<T> CtAssignSlice for Odd<T>where
T: CtAssignSlice,
Source§fn ct_assign_slice(dst: &mut [Self], src: &[Self], choice: Choice)
fn ct_assign_slice(dst: &mut [Self], src: &[Self], choice: Choice)
Source§impl<T> CtEqSlice for Odd<T>where
T: CtEq,
impl<T> CtEqSlice for Odd<T>where
T: CtEq,
Source§fn ct_eq_slice(a: &[Self], b: &[Self]) -> Choice
fn ct_eq_slice(a: &[Self], b: &[Self]) -> Choice
a is equal to b in constant-time.Source§fn ct_ne_slice(a: &[Self], b: &[Self]) -> Choice
fn ct_ne_slice(a: &[Self], b: &[Self]) -> Choice
a is NOT equal to b in constant-time.Source§impl<'de, T: Deserialize<'de> + Integer + Zero> Deserialize<'de> for Odd<T>
Available on crate feature serde only.
impl<'de, T: Deserialize<'de> + Integer + Zero> Deserialize<'de> for Odd<T>
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<const LIMBS: usize> From<&Odd<Uint<LIMBS>>> for BoxedUint
Available on crate feature alloc only.
impl<const LIMBS: usize> From<&Odd<Uint<LIMBS>>> for BoxedUint
alloc only.Source§impl<const LIMBS: usize> From<&Odd<Uint<LIMBS>>> for Odd<BoxedUint>
Available on crate feature alloc only.
impl<const LIMBS: usize> From<&Odd<Uint<LIMBS>>> for Odd<BoxedUint>
alloc only.Source§impl<const LIMBS: usize> From<Odd<Uint<LIMBS>>> for BoxedUint
Available on crate feature alloc only.
impl<const LIMBS: usize> From<Odd<Uint<LIMBS>>> for BoxedUint
alloc only.Source§impl<const LIMBS: usize> From<Odd<Uint<LIMBS>>> for Odd<BoxedUint>
Available on crate feature alloc only.
impl<const LIMBS: usize> From<Odd<Uint<LIMBS>>> for Odd<BoxedUint>
alloc only.Source§impl<T> Mul for Odd<T>where
T: Mul<T, Output = T>,
Any odd integer multiplied by another odd integer is definitionally odd.
impl<T> Mul for Odd<T>where
T: Mul<T, Output = T>,
Any odd integer multiplied by another odd integer is definitionally odd.
Source§impl<T: Ord + ?Sized> Ord for Odd<T>
impl<T: Ord + ?Sized> Ord for Odd<T>
Source§impl PartialOrd<Odd<BoxedUint>> for BoxedUint
Available on crate feature alloc only.
impl PartialOrd<Odd<BoxedUint>> for BoxedUint
alloc only.Source§impl<const LIMBS: usize> PartialOrd<Odd<Uint<LIMBS>>> for Uint<LIMBS>
impl<const LIMBS: usize> PartialOrd<Odd<Uint<LIMBS>>> for Uint<LIMBS>
Source§impl<T: PartialOrd + ?Sized> PartialOrd for Odd<T>
impl<T: PartialOrd + ?Sized> PartialOrd for Odd<T>
Source§impl<const LIMBS: usize> Random for Odd<Uint<LIMBS>>
Available on crate feature rand_core only.
impl<const LIMBS: usize> Random for Odd<Uint<LIMBS>>
rand_core only.Source§fn try_random_from_rng<R: TryRng + ?Sized>(
rng: &mut R,
) -> Result<Self, R::Error>
fn try_random_from_rng<R: TryRng + ?Sized>( rng: &mut R, ) -> Result<Self, R::Error>
Generate a random Odd<Uint<T>>.