Skip to content

Conversation

@fjarri
Copy link
Contributor

@fjarri fjarri commented Aug 1, 2024

As mentioned in #511, mul_rem() is currently variable-time in d, which makes mul_mod_special() variable-time in c. This PR makes mul_rem() constant-time with no loss of performance.

Since mul_mod now uses the div_limb functionality, it was moved there.

Also added NonZero::<Limb>::new_unwrap().

@tarcieri
Copy link
Member

tarcieri commented Aug 1, 2024

Whatever happened to a const constructor of NonZero?

#602

@fjarri fjarri force-pushed the div-improvements branch from 36424aa to e49c050 Compare August 2, 2024 00:26
/// Computes `(a * b) % d`.
#[inline(always)]
pub(crate) const fn mul_rem(a: Word, b: Word, d: Word) -> Word {
((a as WideWord * b as WideWord) % (d as WideWord)) as Word
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should enable the clippy::integer_division_remainder_used lint

@tarcieri tarcieri merged commit c9b6124 into RustCrypto:master Aug 2, 2024
@fjarri fjarri deleted the div-improvements branch August 4, 2024 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants