Skip to main content

MontyParams

Struct MontyParams 

Source
pub struct MontyParams<U: Unsigned> {
    pub(super) modulus: Odd<U>,
    pub(super) one: U,
    pub(super) r2: U,
    pub(super) mod_inv: U64,
    pub(super) mod_leading_zeros: u32,
}
Expand description

Parameters to efficiently go to/from the Montgomery form for an odd modulus provided at runtime.

This version is generic over the underlying unsigned integer type.

Fields§

§modulus: Odd<U>

The constant modulus.

§one: U

1 in Montgomery form (a.k.a. R).

§r2: U

R^2 mod modulus, used to move into Montgomery form.

§mod_inv: U64

The lowest limbs of MODULUS^-1 mod 2**64.

This value is used in Montgomery reduction and modular inversion.

§mod_leading_zeros: u32

Leading zeros in the modulus, used to choose optimized algorithms.

Implementations§

Source§

impl<const LIMBS: usize> MontyParams<Uint<LIMBS>>

Source

const fn inverter(&self) -> SafeGcdInverter<LIMBS>

Create a modular inverter for the modulus of these params.

Source§

impl<U: Unsigned> MontyParams<U>

Source

pub const fn modulus(&self) -> &Odd<U>

Returns the modulus which was used to initialize these parameters.

Source

pub const fn one(&self) -> &U

1 in Montgomery form (a.k.a. R).

Source

pub const fn r2(&self) -> &U

R^2 mod modulus, used to move into Montgomery form.

Source

pub const fn mod_inv(&self) -> &U64

Returns the lowest limbs of MODULUS^-1 mod 2**64.

This value is used in Montgomery reduction and modular inversion.

Source

pub const fn mod_neg_inv(&self) -> Limb

Returns wrapping negation of first limb of mod_inv.

Source

pub const fn mod_leading_zeros(&self) -> u32

Returns leading zeros in the modulus, used to choose optimized algorithms.

Source

pub(crate) fn debug_struct(&self, debug: DebugStruct<'_, '_>) -> Result

Core implementation of the debug impl which lets us customize it for various types/type aliases.

Source§

impl<const LIMBS: usize> MontyParams<Uint<LIMBS>>

Source

pub const fn new(modulus: Odd<Uint<LIMBS>>) -> Self

Instantiates a new set of MontyParams representing the given odd modulus.

Source§

impl<const LIMBS: usize> MontyParams<Uint<LIMBS>>

Source

pub const fn new_vartime(modulus: Odd<Uint<LIMBS>>) -> Self

Instantiates a new set of MontyParams representing the given odd modulus.

Trait Implementations§

Source§

impl AsRef<MontyParams<BoxedUint>> for BoxedMontyParams

Source§

fn as_ref(&self) -> &MontyParams<BoxedUint>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<U: Unsigned> AsRef<MontyParams<U>> for MontyParams<U>

Source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<U: Clone + Unsigned> Clone for MontyParams<U>

Source§

fn clone(&self) -> MontyParams<U>

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<U: Unsigned> CtAssign for MontyParams<U>

Source§

fn ct_assign(&mut self, other: &Self, choice: Choice)

Conditionally assign src to self if choice is Choice::TRUE.
Source§

impl<U: Unsigned> CtAssignSlice for MontyParams<U>

Source§

fn ct_assign_slice(dst: &mut [Self], src: &[Self], choice: Choice)

Conditionally assign src to dst if choice is Choice::TRUE, or leave it unchanged for Choice::FALSE.
Source§

impl<U: Unsigned> CtEq for MontyParams<U>

Source§

fn ct_eq(&self, other: &Self) -> Choice

Determine if self is equal to other in constant-time.
Source§

fn ct_ne(&self, other: &Rhs) -> Choice

Determine if self is NOT equal to other in constant-time.
Source§

impl<U: Unsigned> CtEqSlice for MontyParams<U>

Source§

fn ct_eq_slice(a: &[Self], b: &[Self]) -> Choice

Determine if a is equal to b in constant-time.
Source§

fn ct_ne_slice(a: &[Self], b: &[Self]) -> Choice

Determine if a is NOT equal to b in constant-time.
Source§

impl<const LIMBS: usize> From<&MontyParams<Uint<LIMBS>>> for BoxedMontyParams

Source§

fn from(params: &FixedMontyParams<LIMBS>) -> Self

Converts to this type from the input type.
Source§

impl<'a, const LIMBS: usize> From<&'a MontyParams<Uint<LIMBS>>> for FixedMontyMultiplier<'a, LIMBS>

Source§

fn from(source: &'a FixedMontyParams<LIMBS>) -> Self

Converts to this type from the input type.
Source§

impl From<MontyParams<BoxedUint>> for BoxedMontyParams

Source§

fn from(params: MontyParams<BoxedUint>) -> Self

Converts to this type from the input type.
Source§

impl<const LIMBS: usize> From<MontyParams<Uint<LIMBS>>> for BoxedMontyParams

Source§

fn from(params: FixedMontyParams<LIMBS>) -> Self

Converts to this type from the input type.
Source§

impl<U: PartialEq + Unsigned> PartialEq for MontyParams<U>

Source§

fn eq(&self, other: &MontyParams<U>) -> 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<U: Unsigned + Zeroize> Zeroize for MontyParams<U>

Available on crate feature zeroize only.
Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

impl<U: Copy + Unsigned> Copy for MontyParams<U>

Source§

impl<U: Unsigned> CtSelectUsingCtAssign for MontyParams<U>

Source§

impl<U: Eq + Unsigned> Eq for MontyParams<U>

Source§

impl<U: Unsigned> StructuralPartialEq for MontyParams<U>

Auto Trait Implementations§

§

impl<U> Freeze for MontyParams<U>
where U: Freeze,

§

impl<U> RefUnwindSafe for MontyParams<U>
where U: RefUnwindSafe,

§

impl<U> Send for MontyParams<U>

§

impl<U> Sync for MontyParams<U>

§

impl<U> Unpin for MontyParams<U>
where U: Unpin,

§

impl<U> UnsafeUnpin for MontyParams<U>
where U: UnsafeUnpin,

§

impl<U> UnwindSafe for MontyParams<U>
where U: UnwindSafe,

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> 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<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> CtSelect for T

Source§

fn ct_select(&self, other: &T, choice: Choice) -> T

Select between self and other based on choice, returning a copy of the value. Read more
Source§

fn ct_swap(&mut self, other: &mut Self, choice: Choice)

Conditionally swap self and other if choice is Choice::TRUE.
Source§

impl<T, const N: usize> CtSelectArray<N> for T

Source§

fn ct_select_array(a: &[T; N], b: &[T; N], choice: Choice) -> [T; N]

Select between a and b in constant-time based on choice.
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> 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, 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.