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

Add BoxedUint::inv_mod #341

Merged
merged 1 commit into from
Nov 28, 2023
Merged

Add BoxedUint::inv_mod #341

merged 1 commit into from
Nov 28, 2023

Conversation

tarcieri
Copy link
Member

Support for computing modular inverses, proptested against the implementation in num-bigint-dig, which this commit also switches to (num-bigint doesn't provide an implementation we can test against).

Uses the same method as Uint::inv_mod, namely an algorithm equivalent to GMP's mpn_sec_invert, with code largely duplicated from the Uint version.

Notably this version is variable time with respect to the modulus, which might be avoidable with alternative implementations, such as Bernstein-Yang.

It would also be nice to deduplicate the implementation, though reuse between const fn use cases and heap-backed use cases is difficult.

This additionally adds the following prerequisites:

  • `BoxedUint::{conditional_assign, conditional_swap, is_one}
  • BoxedUint::conditional_wrapping_* (private)
  • BoxedUint::{trailing_zeros, wrapping_mul, neg}
  • BoxedUint::{shl, shr}

Support for computing modular inverses, proptested against the
implementation in `num-bigint-dig`, which this commit also switches to
(`num-bigint` doesn't provide an implementation we can test against).

Uses the same method as `Uint::inv_mod`, namely an algorithm equivalent
to GMP's `mpn_sec_invert`, with code largely duplicated from the `Uint`
version.

Notably this version is variable time with respect to the modulus,
which might be avoidable with alternative implementations, such as
Bernstein-Yang.

It would also be nice to deduplicate the implementation, though reuse
between `const fn` use cases and heap-backed use cases is difficult.

This additionally adds the following prerequisites:
- `BoxedUint::{conditional_assign, conditional_swap, is_one}
- `BoxedUint::conditional_wrapping_*` (private)
- `BoxedUint::{trailing_zeros, wrapping_mul, neg}`
- `BoxedUint::{shl, shr}`
@tarcieri tarcieri merged commit 266f62e into master Nov 28, 2023
16 checks passed
@tarcieri tarcieri deleted the boxed-uint/inv-mod branch November 28, 2023 04:26
@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.

1 participant