Skip to content

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
@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