Skip to main content

CtMpDivisor

Struct CtMpDivisor 

Source
pub struct CtMpDivisor<'a, VT: MpUIntCommon> { /* private fields */ }
Expand description

Multiprecision integer divisor.

Wraps a multiprecision integer v, optionally decremented by a LimbType v_decrement, for use as the divisor in ct_div_mp_mp(), ct_mod_mp_mp(), ct_div_pow2_mp(), ct_mod_pow2_mp(), ct_div_lshifted_mp_mp() and ct_mod_lshifted_mp_mp(). The divisor’s value is v minus v_decrement, which gets computed on the fly whenever needed, so that no separate buffer is required for it.

Some values needed by the division algorithm and depending only on the divisor get precomputed upon construction, so that a CtMpDivisor can be used efficiently for multiple divisions.

The length of the divisor’s value without any leading zero bytes is not considered secret: the divisions’ execution time depends on it, c.f. new(). See CtLDivisor for single LimbType divisors.

Implementations§

Source§

impl<'a, VT: MpUIntCommon> CtMpDivisor<'a, VT>

Source

pub fn new( v: &'a VT, v_decrement: Option<LimbType>, ) -> Result<Self, CtMpDivisorError>

Construct a CtMpDivisor.

The divisor’s value is v minus v_decrement, if the latter is given, or v otherwise.

Execution time depends on v’s length in units of bytes and on the divisor value’s length without any leading zero bytes, which is therefore not considered secret, and is otherwise constant as far as branching is concerned.

§Arguments
  • v - The multiprecision integer to wrap. Its length in units of bytes isn’t restricted.
  • v_decrement - Optional value to subtract from v for obtaining the divisor’s value. Useful e.g. for dividing by p - 1 without allocating a separate buffer for it.
§Errors

Returns CtMpDivisorError::DivisorIsZero if the divisor’s value is zero or v_decrement exceeds v.

Auto Trait Implementations§

§

impl<'a, VT> Freeze for CtMpDivisor<'a, VT>
where &'a VT: Freeze,

§

impl<'a, VT> RefUnwindSafe for CtMpDivisor<'a, VT>

§

impl<'a, VT> Send for CtMpDivisor<'a, VT>
where &'a VT: Send,

§

impl<'a, VT> Sync for CtMpDivisor<'a, VT>
where &'a VT: Sync,

§

impl<'a, VT> Unpin for CtMpDivisor<'a, VT>
where &'a VT: Unpin,

§

impl<'a, VT> UnsafeUnpin for CtMpDivisor<'a, VT>

§

impl<'a, VT> UnwindSafe for CtMpDivisor<'a, VT>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.