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>
impl<'a, VT: MpUIntCommon> CtMpDivisor<'a, VT>
Sourcepub fn new(
v: &'a VT,
v_decrement: Option<LimbType>,
) -> Result<Self, CtMpDivisorError>
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 fromvfor obtaining the divisor’s value. Useful e.g. for dividing byp - 1without allocating a separate buffer for it.
§Errors
Returns CtMpDivisorError::DivisorIsZero if the divisor’s value is
zero or v_decrement exceeds v.