-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Fast modular inversion #172
Conversation
Discussion of chosen algorithmThere are 3 papers on fast inversion in the past 3 years: Bernstein-Yang inversion:
Pornin's inversion:
DiscussionThis PR implements Bernstein-Yang inversion, there is a sketch of Pornin's inversion at:
Correctly and efficiently implementing Pornin's for generic primes is actually tricky:
In particular the inner loop needs to be as streamlined as possible, the lack of cmov and lzcount being platform-dependent makes the inner loop slow in pure Nim/C. |
This implements fast constant-time modular inversion.
Preliminary benchmarks, without Assembly
On BLS12-381, this is almost 8x faster than Niels Möller algorithm (constant-time inversion in GMP) and Fermat's Little Theorem inversion with addition chains.