Skip to content

Conversation

andrewwhitehead
Copy link
Contributor

In regards comments on #646, this handles potential overflow in the remainder value.

@tarcieri tarcieri merged commit f5094eb into RustCrypto:master Aug 15, 2024
// If r < b and q*y[-2] > r*x[-1], then set q = q - 1 and r = r + v1
let done = ConstChoice::from_word_nonzero((rem >> Word::BITS) as Word)
.or(ConstChoice::from_wide_word_le(qy, rx));
quo = done.select_word(quo.saturating_sub(1), quo);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rather have wrapping_sub here, I'm not sure if saturating_sub is constant-time

Copy link
Member

Choose a reason for hiding this comment

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

Spot checking it in Godbolt saturating_sub uses cmovae on x86 and csel on aarch64, which (for now, until the optimizer decides differently) seem pretty ideal

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.

3 participants