Skip to main content

ct_mod_pow2_mp

Function ct_mod_pow2_mp 

Source
pub fn ct_mod_pow2_mp<RT: MpMutUInt, VT: MpUIntCommon>(
    u_pow2_exp: usize,
    r_out: &mut RT,
    v: &CtMpDivisor<'_, VT>,
) -> Result<(), CtModPow2MpError>
Expand description

Compute the remainder of a power of two divided by a multiprecision integer.

Like ct_div_pow2_mp(), but don’t compute the quotient. The remainder of two to the power of u_pow2_exp divided by the divisor v’s value gets stored in r_out, with any of r_out’s bytes above it cleared. The remainder is less than the divisor.

This is a specialized variant of ct_mod_mp_mp() for power of two dividends, which doesn’t need a buffer for the dividend.

Execution time depends only on u_pow2_exp, on r_out’s length in units of bytes, as well as on the divisor value’s length without any leading zero bytes, which is not considered secret, c.f. CtMpDivisor, and is otherwise constant as far as branching is concerned. The computation cost is O(e · n), where e is u_pow2_exp and n the divisor value’s length.

§Arguments

  • u_pow2_exp - The exponent of the power of two dividend.
  • r_out - Output for the remainder. Its length in units of bytes must be at least the smaller of the divisor value’s length and u_pow2_exp / 8 + 1.
  • v - The divisor.

§Errors

Returns CtModPow2MpError::InsufficientRemainderSpace if r_out’s length doesn’t meet the requirement above. Nothing gets modified in this case.