Skip to main content

BoxedMontyForm

Struct BoxedMontyForm 

Source
pub struct BoxedMontyForm { /* private fields */ }
Available on crate feature alloc only.
Expand description

An integer in Montgomery form represented using heap-allocated limbs.

Implementations§

Source§

impl BoxedMontyForm

Source

pub fn add(&self, rhs: &Self) -> Self

Adds rhs.

Source

pub fn double(&self) -> Self

Double self.

Source§

impl BoxedMontyForm

Source

pub fn invert(&self) -> CtOption<Self>

Computes self^-1 representing the multiplicative inverse of self, i.e. self * self^-1 = 1.

Source

pub fn invert_vartime(&self) -> CtOption<Self>

Computes self^-1 representing the multiplicative inverse of self, i.e. self * self^-1 = 1.

This version is variable-time with respect to the self of self, but constant-time with respect to self’s params.

Source§

impl BoxedMontyForm

Source

pub 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.

All terms must be associated with equivalent MontyParams.

§Panics
  • if products is empty.
Source§

impl BoxedMontyForm

Source

pub fn mul(&self, rhs: &Self) -> Self

Multiplies by rhs.

Source

pub fn square(&self) -> Self

Computes the (reduced) square.

Source§

impl BoxedMontyForm

Source

pub fn neg(&self) -> Self

Negates the number.

Source§

impl BoxedMontyForm

Source

pub fn pow(&self, exponent: &BoxedUint) -> Self

Raises to the exponent power.

Source

pub fn pow_bounded_exp(&self, exponent: &BoxedUint, exponent_bits: u32) -> Self

Raises to the exponent power, with exponent_bits representing the number of (least significant) bits to take into account for the exponent.

NOTE: exponent_bits may be leaked in the time pattern.

Source§

impl BoxedMontyForm

Source

pub fn sub(&self, rhs: &Self) -> Self

Subtracts rhs.

Source§

impl BoxedMontyForm

Source

pub fn new(integer: BoxedUint, params: &BoxedMontyParams) -> Self

Instantiates a new BoxedMontyForm that represents an integer modulo the provided params.

Source

pub fn bits_precision(&self) -> u32

Bits of precision in the modulus.

Source

pub fn retrieve(&self) -> BoxedUint

Retrieves the integer currently encoded in this BoxedMontyForm, guaranteed to be reduced.

Source

pub fn zero(params: &BoxedMontyParams) -> Self

Instantiates a new ConstMontyForm that represents zero.

Source

pub fn one(params: &BoxedMontyParams) -> Self

Instantiates a new ConstMontyForm that represents 1.

Source

pub fn is_zero(&self) -> Choice

Determine if this value is equal to zero.

§Returns

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

Source

pub fn is_nonzero(&self) -> Choice

Determine if this value is not equal to zero.

§Returns

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

Source

pub fn params(&self) -> &BoxedMontyParams

Returns the parameter struct used to initialize this object.

Source

pub fn as_montgomery(&self) -> &BoxedUint

Access the BoxedMontyForm value in Montgomery form.

Source

pub fn as_montgomery_mut(&mut self) -> &mut BoxedUint

Mutably access the BoxedMontyForm value in Montgomery form.

Source

pub fn from_montgomery(integer: BoxedUint, params: &BoxedMontyParams) -> Self

Create a BoxedMontyForm from a value in Montgomery form.

Source

pub fn to_montgomery(&self) -> BoxedUint

Extract the value from the BoxedMontyForm in Montgomery form.

Source

pub fn div_by_2(&self) -> Self

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

Source

pub 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.

Trait Implementations§

Source§

impl Add for BoxedMontyForm

Source§

type Output = BoxedMontyForm

The resulting type after applying the + operator.
Source§

fn add(self, rhs: BoxedMontyForm) -> BoxedMontyForm

Performs the + operation. Read more
Source§

impl Add<&BoxedMontyForm> for &BoxedMontyForm

Source§

type Output = BoxedMontyForm

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &BoxedMontyForm) -> BoxedMontyForm

Performs the + operation. Read more
Source§

impl Add<&BoxedMontyForm> for BoxedMontyForm

Source§

type Output = BoxedMontyForm

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &BoxedMontyForm) -> BoxedMontyForm

Performs the + operation. Read more
Source§

impl Add<BoxedMontyForm> for &BoxedMontyForm

Source§

type Output = BoxedMontyForm

The resulting type after applying the + operator.
Source§

fn add(self, rhs: BoxedMontyForm) -> BoxedMontyForm

Performs the + operation. Read more
Source§

impl AddAssign for BoxedMontyForm

Source§

fn add_assign(&mut self, rhs: BoxedMontyForm)

Performs the += operation. Read more
Source§

impl AddAssign<&BoxedMontyForm> for BoxedMontyForm

Source§

fn add_assign(&mut self, rhs: &BoxedMontyForm)

Performs the += operation. Read more
Source§

impl Clone for BoxedMontyForm

Source§

fn clone(&self) -> BoxedMontyForm

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl CtAssign for BoxedMontyForm

Source§

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

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

impl CtAssignSlice for BoxedMontyForm

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 CtEq for BoxedMontyForm

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 CtEqSlice for BoxedMontyForm

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 CtSelectUsingCtAssign for BoxedMontyForm

Source§

impl Debug for BoxedMontyForm

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for BoxedMontyForm

Source§

impl<const LIMBS: usize, Params> From<&ConstMontyForm<Params, LIMBS>> for BoxedMontyForm
where Params: ConstMontyParams<LIMBS>,

Source§

fn from(input: &ConstMontyForm<Params, LIMBS>) -> Self

Converts to this type from the input type.
Source§

impl<const LIMBS: usize> From<&FixedMontyForm<LIMBS>> for BoxedMontyForm

Source§

fn from(input: &FixedMontyForm<LIMBS>) -> Self

Converts to this type from the input type.
Source§

impl<const LIMBS: usize, Params> From<ConstMontyForm<Params, LIMBS>> for BoxedMontyForm
where Params: ConstMontyParams<LIMBS>,

Source§

fn from(input: ConstMontyForm<Params, LIMBS>) -> Self

Converts to this type from the input type.
Source§

impl<const LIMBS: usize> From<FixedMontyForm<LIMBS>> for BoxedMontyForm

Source§

fn from(input: FixedMontyForm<LIMBS>) -> Self

Converts to this type from the input type.
Source§

impl Invert for BoxedMontyForm

Source§

type Output = CtOption<BoxedMontyForm>

Output of the inversion.
Source§

fn invert(&self) -> Self::Output

Computes the inverse.
Source§

fn invert_vartime(&self) -> Self::Output

Computes the inverse in variable-time.
Source§

impl MontyForm for BoxedMontyForm

Source§

type Integer = BoxedUint

The original integer type.
Source§

type Params = BoxedMontyParams

The precomputed data needed for this representation.
Source§

type Multiplier<'a> = BoxedMontyMultiplier<'a>

Prepared Montgomery multiplier for tight loops.
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 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.
Source§

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

Calculate the sum of products of pairs (a, b) in products. Read more
Source§

fn is_zero(&self) -> Choice

Determine if this value is equal to zero. Read more
Source§

fn is_one(&self) -> Choice

Determine if this value is equal to one. Read more
Source§

impl Mul for BoxedMontyForm

Source§

type Output = BoxedMontyForm

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: BoxedMontyForm) -> BoxedMontyForm

Performs the * operation. Read more
Source§

impl Mul<&BoxedMontyForm> for &BoxedMontyForm

Source§

type Output = BoxedMontyForm

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &BoxedMontyForm) -> BoxedMontyForm

Performs the * operation. Read more
Source§

impl Mul<&BoxedMontyForm> for BoxedMontyForm

Source§

type Output = BoxedMontyForm

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &BoxedMontyForm) -> BoxedMontyForm

Performs the * operation. Read more
Source§

impl Mul<BoxedMontyForm> for &BoxedMontyForm

Source§

type Output = BoxedMontyForm

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: BoxedMontyForm) -> BoxedMontyForm

Performs the * operation. Read more
Source§

impl MulAssign for BoxedMontyForm

Source§

fn mul_assign(&mut self, rhs: BoxedMontyForm)

Performs the *= operation. Read more
Source§

impl MulAssign<&BoxedMontyForm> for BoxedMontyForm

Source§

fn mul_assign(&mut self, rhs: &BoxedMontyForm)

Performs the *= operation. Read more
Source§

impl Neg for BoxedMontyForm

Source§

type Output = BoxedMontyForm

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl Neg for &BoxedMontyForm

Source§

type Output = BoxedMontyForm

The resulting type after applying the - operator.
Source§

fn neg(self) -> BoxedMontyForm

Performs the unary - operation. Read more
Source§

impl PartialEq for BoxedMontyForm

Source§

fn eq(&self, other: &BoxedMontyForm) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PowBoundedExp<BoxedUint> for BoxedMontyForm

Source§

fn pow_bounded_exp(&self, exponent: &BoxedUint, exponent_bits: u32) -> Self

Raises to the exponent power, with exponent_bits representing the number of (least significant) bits to take into account for the exponent. Read more
Source§

impl Retrieve for BoxedMontyForm

Source§

type Output = BoxedUint

The original type.
Source§

fn retrieve(&self) -> BoxedUint

Convert the number back from the optimized representation.
Source§

impl Square for BoxedMontyForm

Source§

fn square(&self) -> Self

Computes the same as self * self, but may be more efficient.
Source§

impl SquareAssign for BoxedMontyForm

Source§

fn square_assign(&mut self)

Computes the same as self * self, but may be more efficient. Writes the result in self.
Source§

impl StructuralPartialEq for BoxedMontyForm

Source§

impl Sub for BoxedMontyForm

Source§

type Output = BoxedMontyForm

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: BoxedMontyForm) -> BoxedMontyForm

Performs the - operation. Read more
Source§

impl Sub<&BoxedMontyForm> for &BoxedMontyForm

Source§

type Output = BoxedMontyForm

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &BoxedMontyForm) -> BoxedMontyForm

Performs the - operation. Read more
Source§

impl Sub<&BoxedMontyForm> for BoxedMontyForm

Source§

type Output = BoxedMontyForm

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &BoxedMontyForm) -> BoxedMontyForm

Performs the - operation. Read more
Source§

impl Sub<BoxedMontyForm> for &BoxedMontyForm

Source§

type Output = BoxedMontyForm

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: BoxedMontyForm) -> BoxedMontyForm

Performs the - operation. Read more
Source§

impl SubAssign for BoxedMontyForm

Source§

fn sub_assign(&mut self, rhs: BoxedMontyForm)

Performs the -= operation. Read more
Source§

impl SubAssign<&BoxedMontyForm> for BoxedMontyForm

Source§

fn sub_assign(&mut self, rhs: &BoxedMontyForm)

Performs the -= operation. Read more
Source§

impl Zeroize for BoxedMontyForm

Available on crate feature zeroize only.

NOTE: This zeroizes the value, but not the associated parameters!

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.

Auto Trait Implementations§

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, Exponent> Pow<Exponent> for T
where T: PowBoundedExp<Exponent>, Exponent: Unsigned,

Source§

fn pow(&self, exponent: &Exponent) -> T

Raises to the exponent power.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.