-
Notifications
You must be signed in to change notification settings - Fork 5
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
Constant-time prime generation? #17
Comments
In the other thread, you mentioned that: "Miller-Rabin requires the number of iterations equal to the number of trailing zeros in Regarding leakage, the number of trailing zeros in |
See Miller-Rabin test, "Strong probable primes" section (or the corresponding code in the crate).
Unfortunately, |
Hey, so I did some digging, and I found some sources about how to mitigate some timing side channels. Addressing timing side channels in the MR test: Check out this blog/book. They present a very convincing constant-time algorithm. Addressing timing side channels in the sieve: I found multiple sources that analyze the danger of using sieving, including this one. As a potential countermeasure they suggest using the work by Fouque and Tibouchi. At first glance, Algorithm 2 is promising as a potentially 'constant-time' candidate generation technique that still seems somewhat efficient. What are your thoughts on this? If you would like, I can look into an initial implementation. |
Interesting, I wonder if that's what OpenSSL uses, seeing as how it chooses not to employ Lucas test and instead do 32-64 iterations of MR (although another reason for that might be that it has optimized implementations of MR using vector instructions). Unfortunately I cannot dedicate much time to it at the moment, so if you want to help, that would be great. Even if we can only get rid of constant-timeness in the sieve and MR, this can be exposed as a "constant-time" preset, with the same parameters OpenSSL uses (or the ones from FIPS-186, see also #4). |
It's also interesting that even if OpenSSL's MR is constant-time, the leakage from sieving is quite significant. I agree that offering both variable-time and constant-time methods is a nice idea. I can look into it. |
I had some time to look at the constant-time MR algorithm, and I was hoping there's some smart way to remove the dependency on the number of trailing zeros of |
The nice thing is, given that we only apply the test on random inputs, it is extremely unlikely for there to be e.g. more than ~40 trailing zeros. What do you think about iterating at most 40 times instead of log2(n)? Given that the last bit is always 0, that is a probability of |
The text was updated successfully, but these errors were encountered: