Add a parameter to probable_prime if we look for a safe prime#9309
Add a parameter to probable_prime if we look for a safe prime#9309bernd-edlinger wants to merge 4 commits intoopenssl:masterfrom
Conversation
|
I think this needs to be back-ported to 1.1.1 at least (a cherry-pick does not work). |
|
Is that a security issue for multiprime rsa keys? |
|
No, but it allows fingerprinting of public rsa certificates and possibly targeting weak ones. |
|
I think the current code will never find the safe prime 5. |
|
I'm wondering if we should go for q ≡ 11 (mod 12) instead of q ≡ 3 (mod 4) for safe primes, and then just special case the values 5 and 7. |
|
Yes, correct. Same for 11, and 23. |
|
So do we care that it can't generate some small primes? |
|
not really. |
|
Since the method uses random numbers, I expect the primes to be large. |
|
But then we actually seem to have code for primes that fit in a word ... |
|
yes, that's a strange thing. |
|
And that the top 2 bits are set suggest that the use is for multiplying 2 such numbers, so that you end up with something of the correct bit length... |
|
Yes, RSA depends on that a lot. |
|
example for bad parametes would be |
|
I wonder if the FIPS stuff needs a range of |
|
I could remove the single word special case, without sacrificing any functionality. |
|
removed the single word code. |
|
The last update uses the pre-computed modules from the probable_prime also |
|
The single word code got added in commit 96a4c31, to prevent generating larger keys than what was requested. |
|
Correct, it is still guaranteed that probable_prime is able to find a valid candidate |
See rsa_sp800_56b_check.c rsa_check_prime_factor_range() |
Oh, nice. |
Something that is inside a comment? wow. |
|
... only a faux-pas, maybe just reading glibberish. |
|
You've changed the safe DH generation from generating q, and sieving both p and q to generate p and only sieve p. My guess is that this will slow down the generation of the DH parameters, and I think we should continue to sieve both. probable_prime() should probably also sieve both in case of safe primes. |
|
The whole idea behind this PR is the following: |
|
+1 to CHANGES entry |
8d901b9 to
b632534
Compare
|
Fixed conflicts, added CHANGES entry. |
|
I am not convinced that this PR is well motivated. Neither the ability to fingerprint 3-prime RSA, nor the ability fingerprint OpenSSL as the generator of cracked (due to poor entropy) 2-prime RSA looks compelling to me. On the other hand, there may IIRC be worthwhile benefits to avoiding common small factors (other than 2) between (p-1) and (q-1) (there was some back even talk of avoiding small common factors of (p^2-1) and (q^2-1), don't recall the rationale). Anyway, we should take care, and make changes only for sound number theoretic reasons, not publicity. When we're the most widely used toolkit, we're also the most widely misused toolkit, that's just life, but we should avoid knee-jerk fixes. What is the actual best-practice around generation of 2-prime RSA moduli? |
|
Is this PR consistent with SP186 B.3 for generating RSA key pairs? Perhaps it should be? |
|
What benefits could those be, do you have any references? |
|
Regarding multi-primes RSA modules, we enforce the following limits: In the review of the multi-prime PR, I insisted in checking the first byte of the modulus to be |
|
Quoting from https://www.hyperelliptic.org/tanja/vortraege/facthacks-29C3.pdf, Page 22: " Pollard’s p−1 method This method finds larger factors than the rho method (in the same time) but only works for special primes. Here p−1 = 26·32·52·17·227·491·991·36559·308129·4161791has only small factors Math ahead: Avoiding such p helps against the p−1 method – but does not help against ECM (the elliptic curve method), which works if the number of points on a curve modulo p is smooth. “Strong primes” are obsolete: fail to defend against ECM. " Everybody assumes that this selection was designed as a defense against p-1 because p |
Ah, You mean FIPS186-4 B.3, I believe @slontis has been working on it here: It is not based on BN_generate_prime_ex2 and is therefore not affected by this PR. |
p^2-1 = (p-1)*(p+1) Hmm, sounds like attacking p-1 and p+1 methods at once, right? |
|
As I understand there are 2 popular methods to generate RSA keys:
1) The FIPS method with auxilary primes
2) Generating 2 random primes
How you generate the random primes can be different:
a) Generate a new random number, test that it's prime
b) Start from a random number and increate until it's prime
Then there can also be property's of the random number that are
generated:
I) Top 2 bit are set
II) Generate number in the range 2^bits/sqrt(2) - 2^bits-1
III) Just have the top bit set, test that product has
the correct amount of bits.
And properties of the primes:
A) p-1 can't be divides by a small prime except 2
B) Blum primes
C) Just prime
D) Others
OpenSSL did 2.b.I.A (in non-FIPS mode), I don't know if we intend
to alwyas use the FIPS mode now, or still only in FIPS mode.
As I understand it, the FIPS mode ensures some properties of p-1
and p+1, but the check that we do is not equivalent.
As far as I know, nobody uses safe primes for RSA. But when we
generate primes (not safe primes), we do some check that only
makes sense if we were generating a safe prime. By this, we
eliminate primes we don't need to. (My understanding, about half
of the possible primes are never generated by OpenSSL.)
This really is just about generating primes. If we want the prime
to have different properties other than just being prime or safe
prime, I think the code that wants those properties should either
tell the prime generation about those properties, or check those
properties itself. But at the same time, I'm always concerned when
we change the default properties.
The current change of course has an effect or the RSA generation,
changing it from 2.b.I.A to 2.b.I.C. If that is not what we want,
something else needs to change. But then I suggest we just switch
to the FIPS mode.
We could also change some of the other properties, so that the
possible primes we generate is higher, or avoiding a bias that's
probably not important.
|
b632534 to
7f941d4
Compare
|
Even if avoiding fingerprinting of n-prime RSA may not be enough as a motivation, |
|
Ping? |
Currently probable_prime makes sure that p-1 does not have any prime factors from 3..17863, which is useful for safe primes, but not necessarily for the general case. Issue was initially reported here: MIRONOV, I. Factoring RSA Moduli II. https://windowsontheory.org/2012/05/17/factoring-rsa-moduli-part-ii/
This should avoid half of the trial divisions in probable_prime_dh_safe and avoid bn_probable_prime_dh generating primes with special properties.
BN_generate_prime_ex no longer avoids factors 3..17863 in p-1 when not computing safe primes.
7f941d4 to
d1e0359
Compare
|
fixed the merge conflict in the CHANGES file. |
paulidale
left a comment
There was a problem hiding this comment.
Only a quick scan but it still looks good.
|
Pushed. Thanks! |
Currently probable_prime makes sure that p-1 does not have any prime factors from 3..17863, which is useful for safe primes, but not necessarily for the general case. Issue was initially reported here: MIRONOV, I. Factoring RSA Moduli II. https://windowsontheory.org/2012/05/17/factoring-rsa-moduli-part-ii/ Reviewed-by: Paul Dale <[email protected]> (Merged from #9309)
This should avoid half of the trial divisions in probable_prime_dh_safe and avoid bn_probable_prime_dh generating primes with special properties. Reviewed-by: Paul Dale <[email protected]> (Merged from #9309)
Reviewed-by: Paul Dale <[email protected]> (Merged from #9309)
BN_generate_prime_ex no longer avoids factors 3..17863 in p-1 when not computing safe primes. Reviewed-by: Paul Dale <[email protected]> (Merged from #9309)
Currently probable_prime makes sure that p-1 does not have
any prime factors from 3..17863, which is useful for safe primes,
but not necessarily for the general case.
Issue was initially reported here:
MIRONOV, I. Factoring RSA Moduli II.
https://windowsontheory.org/2012/05/17/factoring-rsa-moduli-part-ii/