Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make division methods take NonZero-wrapped divisors #419

Merged
merged 6 commits into from
Dec 14, 2023

Conversation

fjarri
Copy link
Contributor

@fjarri fjarri commented Dec 12, 2023

This simplifies the API allowing us to avoid returning CtChoice results, and making some methods redundant. Also that's what BoxedUint is already doing.

  • Simplify Reciprocal API by taking a NonZero<Limb> in Reciprocal::new() which is now const.
  • Reciprocal::ct_new() is removed.
  • Uint::div_rem_limb() and Uint::div_rem_limb_with_reciprocal() take a NonZero<Limb> and are now const.
  • Uint::ct_div_rem_limb() and Uint::ct_div_rem_limb_with_reciprocal() are removed.
  • Uint::div_rem() and Uint::div_rem_vartime() are now const.
  • Uint::const_div_rem() and Uint::const_div_rem_vartime() are removed.
  • Make Uint::rem() and rem_wide() take NonZero rhs and make them const.
  • Make Uint::wrapping_div(_vartime) take NonZero rhs
  • Wrap ResidueParams::MODULUS in NonZero.
  • Residue::new_checked() removed since ResidueParams has already done that check in compile time.
  • Added a const fn NonZero::as_ref() to get access to the inner value in a const context.

@fjarri fjarri force-pushed the div-api branch 3 times, most recently from 8d01f99 to 49d70f9 Compare December 13, 2023 00:48
@fjarri fjarri marked this pull request as ready for review December 13, 2023 00:52
@tarcieri
Copy link
Member

@fjarri if you'd like to get this one merged next, it needs a rebase

Remove `ct_div_rem_limb_with_reciprocal` and `ct_div_rem_limb`,
make `div_rem_limb_with_reciprocal` and `div_rem_limb` `const`.
Remove `const_div_rem()` and `const_div_rem_vartime()`.
@fjarri
Copy link
Contributor Author

fjarri commented Dec 13, 2023

rebased

src/modular/residue.rs Outdated Show resolved Hide resolved
@tarcieri tarcieri merged commit 4314261 into RustCrypto:master Dec 14, 2023
16 checks passed
@fjarri fjarri deleted the div-api branch December 14, 2023 00:29
@tarcieri tarcieri mentioned this pull request Jan 22, 2025
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