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

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

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 new_with_arc(integer: BoxedUint, params: Arc<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 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.

Trait Implementations§

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 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 AddAssign<&BoxedMontyForm> for BoxedMontyForm

Source§

fn add_assign(&mut self, rhs: &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 Clone for BoxedMontyForm

Source§

fn clone(&self) -> BoxedMontyForm

Returns a copy 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 Debug for BoxedMontyForm

Source§

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

Formats the value using the given formatter. Read more
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 Monty for BoxedMontyForm

Source§

type Integer = BoxedUint

The original integer type.
Source§

type Params = BoxedMontyParams

The precomputed data needed for this representation.
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 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. 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 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 MulAssign<&BoxedMontyForm> for BoxedMontyForm

Source§

fn mul_assign(&mut self, rhs: &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 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 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 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 · 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 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 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 SubAssign<&BoxedMontyForm> for BoxedMontyForm

Source§

fn sub_assign(&mut self, rhs: &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 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.
Source§

impl Eq for BoxedMontyForm

Source§

impl StructuralPartialEq for BoxedMontyForm

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
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: Bounded,

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.