-
Notifications
You must be signed in to change notification settings - Fork 56
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
Random (safe) prime generation, how to go about it? #184
Comments
I believe @fjarri already has an implementation of random prime functionality although I don’t think it’s public yet |
Oh that's good to know! I think it's https://github.com/entropyxyz/crypto-primes. Exciting work! |
I am not sure BPSW test can be made constant time, since both of its constituents are data-dependent:
Moreover, is some usable information actually leaked this way? |
It's my understanding that the first test in Baille-PSW is simply a Fermat primality test base 2, but that might be wrong. However, if this is the case, then that part sounds easy to do in constant time. For the Lucas test I was thinking about computing the right element of the Lucas sequence, similar to the Montgomery ladder. I'm curious to hear your thoughts. |
No, the first test is more involved, it's Miller-Rabin test, and it has a variable number of iterations depending on For the Lucas test, yes, the binary step is used to propagate the sequence, and it can be made branch-free - but it only needs to be propagated to such odd I filed entropyxyz/crypto-primes#17 if you want to continue the discussion there. |
I think this can be closed, since all the relevant discussion is in the |
Hi @tarcieri and others. Thanks for all the hard work; I see so many changes since I last checked the repository!
For the scicrypt crate and e.g. the RSA crate it is necessary to generate (safe) primes. I also saw that this feature is on the feature wishlist.
Design considerations
I want to try my hand at implementing it but I would like to hear your opinion about a few design decisions:
I want to elaborate a bit on the last point:
Given a constant-time primality test (or one that only runs in constant time when the number is actually prime), the only way I imagine being free of timing side-channels is to keep generating random potential primes until finding one that passes the test. However, this is very slow. A much faster approach (like in OpenSSL) is to sieve: We would first compute the residues of the potential prime modulo many small primes. If any equals 0, we increase all residues by 2 (or 4 for a safe prime), and try again. In this way we can weed out many composite numbers without having to run the primality test. However, this probably causes timing patterns that one might exploit to learn more about the random prime. I also don't know any papers about this that could help us.
My suggestion
I suggest that I implement:
I am curious to hear your thoughts. I'm happy to help out where possible!
The text was updated successfully, but these errors were encountered: