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

More performant computation of the multiplicative inverse mod 2^n #455

Open
AlekseiVambol opened this issue Jun 28, 2024 · 0 comments
Open

Comments

@AlekseiVambol
Copy link
Contributor

The Inverse method of the Modulus class can be optimized to become more performant. The current implementation uses the Euler's theorem, requires O(log^3(M)) time and O(log(M)) space, where the modulus M = 2^B:

constexpr static T Inverse(const BigInt<N>& modulus) {

There are at least 2 methods, which can be used instead:

For large numbers (arbitrary-precision arithmetic) both methods would require O(log^2(M)) time and O(log(M)) space (for the first method it is a well-known result, for the Hurchalla's one I can give my proof sketch). However, the Hurchalla's method is more convenient to implement in this case, and I hypothesize that it can be a bit more time efficient.

PS The Hurchalla's method is extremely efficient for small numbers (no arbitrary-precision arithmetic): requires O(log log M) time, while Euler's/Carmichael theorem-based and Euclidean-based methods require O(log M) time. The space complexity for all these methods in the case of small numbers is O(1).

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

No branches or pull requests

1 participant