Skip to main content

MontyForm

Trait MontyForm 

Source
pub trait MontyForm:
    'static
    + Sealed
    + Clone
    + CtEq
    + CtSelect
    + Debug
    + Eq
    + Invert<Output = CtOption<Self>>
    + Sized
    + Send
    + Sync
    + Add<Output = Self>
    + for<'a> Add<&'a Self, Output = Self>
    + AddAssign
    + for<'a> AddAssign<&'a Self>
    + Sub<Output = Self>
    + for<'a> Sub<&'a Self, Output = Self>
    + SubAssign
    + for<'a> SubAssign<&'a Self>
    + Mul<Output = Self>
    + for<'a> Mul<&'a Self, Output = Self>
    + MulAssign
    + for<'a> MulAssign<&'a Self>
    + Neg<Output = Self>
    + PowBoundedExp<Self::Integer>
    + Retrieve<Output = Self::Integer>
    + Square
    + SquareAssign {
    type Integer: UnsignedWithMontyForm<MontyForm = Self>;
    type Multiplier<'a>: Debug + Clone + MontyMultiplier<'a, Monty = Self>;
    type Params: 'static + AsRef<MontyParams<Self::Integer>> + From<MontyParams<Self::Integer>> + Clone + Debug + Eq + Sized + Send + Sync;

Show 15 methods // Required methods fn new_params_vartime(modulus: Odd<Self::Integer>) -> Self::Params; fn new(value: Self::Integer, params: &Self::Params) -> Self; fn zero(params: &Self::Params) -> Self; fn one(params: &Self::Params) -> Self; fn params(&self) -> &Self::Params; fn as_montgomery(&self) -> &Self::Integer; fn copy_montgomery_from(&mut self, other: &Self); fn from_montgomery(integer: Self::Integer, params: &Self::Params) -> Self; fn into_montgomery(self) -> Self::Integer; fn double(&self) -> Self; fn div_by_2(&self) -> Self; fn lincomb_vartime(products: &[(&Self, &Self)]) -> Self; // Provided methods fn is_zero(&self) -> Choice { ... } fn is_one(&self) -> Choice { ... } fn div_by_2_assign(&mut self) { ... }
}
Expand description

A representation of an integer optimized for the performance of modular operations.

Required Associated Types§

Source

type Integer: UnsignedWithMontyForm<MontyForm = Self>

The original integer type.

Source

type Multiplier<'a>: Debug + Clone + MontyMultiplier<'a, Monty = Self>

Prepared Montgomery multiplier for tight loops.

Source

type Params: 'static + AsRef<MontyParams<Self::Integer>> + From<MontyParams<Self::Integer>> + Clone + Debug + Eq + Sized + Send + Sync

The precomputed data needed for this representation.

Required Methods§

Source

fn new_params_vartime(modulus: Odd<Self::Integer>) -> Self::Params

Create the precomputed data for Montgomery representation of integers modulo modulus, variable time in modulus.

Source

fn new(value: Self::Integer, params: &Self::Params) -> Self

Convert the value into the representation using precomputed data.

Source

fn zero(params: &Self::Params) -> Self

Returns zero in this representation.

Source

fn one(params: &Self::Params) -> Self

Returns one in this representation.

Source

fn params(&self) -> &Self::Params

Returns the parameter struct used to initialize this object.

Source

fn as_montgomery(&self) -> &Self::Integer

Access the value in Montgomery form.

Source

fn copy_montgomery_from(&mut self, other: &Self)

Copy the Montgomery representation from other into self. NOTE: the parameters remain unchanged.

Source

fn from_montgomery(integer: Self::Integer, params: &Self::Params) -> Self

Create a new Montgomery representation from an integer in Montgomery form.

Source

fn into_montgomery(self) -> Self::Integer

Move the Montgomery form result out of self and return it.

Source

fn double(&self) -> Self

Performs doubling, returning self + self.

Source

fn div_by_2(&self) -> Self

Performs division by 2, that is returns x such that x + x = self.

Source

fn lincomb_vartime(products: &[(&Self, &Self)]) -> Self

Calculate the sum of products of pairs (a, b) in products.

This method is variable time only with the value of the modulus. For a modulus with leading zeros, this method is more efficient than a naive sum of products.

This method will panic if products is empty. All terms must be associated with equivalent Montgomery parameters.

Provided Methods§

Source

fn is_zero(&self) -> Choice

Determine if this value is equal to zero.

§Returns

If zero, returns Choice(1). Otherwise, returns Choice(0).

Source

fn is_one(&self) -> Choice

Determine if this value is equal to one.

§Returns

If one, returns Choice(1). Otherwise, returns Choice(0).

Source

fn div_by_2_assign(&mut self)

Performs division by 2 inplace, that is finds x such that x + x = self and writes it into self.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<const LIMBS: usize> MontyForm for FixedMontyForm<LIMBS>

Source§

type Integer = Uint<LIMBS>

Source§

type Params = MontyParams<Uint<LIMBS>>

Source§

type Multiplier<'a> = FixedMontyMultiplier<'a, LIMBS>