2

RFC 2313 has this specific callout:

    1.   An RSA private key logically consists of only the
         modulus n and the private exponent d. The presence of the
         values p, q, d mod (p-1), d mod (p-1), and q-1 mod p is
         intended for efficiency, as Quisquater and Couvreur have
         shown [QC82]. A private-key syntax that does not include
         all the extra values can be converted readily to the syntax
         defined here, provided the public key is known, according
         to a result by Miller [Mil76].

Mil76 is G.L. Miller. Riemann's hypothesis and tests for primality. Journal of Computer and Systems Sciences, 13(3):300-307, 1976.

2313 was obsoleted by RFC 2437. 2437 was obsoleted by 3447. 3447 might have been obsoleted by 8017 but does anyone use it?

2437 makes no mention of this caveat, that the other components can be "converted to this format" if the 'n', 'd' and public key (mod and public exp) are known.

Anyone know why? First option is that the Miller reference was wrong, second option is that the RFC editors were misquoting, misreading or misrepresenting Miller's stuff.

I know that conventional (ie, there are StackOverflow questions on this) wisdom is that the modulus and the private exponent are all that is needed to use an RSA private key, assuming the public key components are known.

Is that (when you get really down to it) correct conventional wisdom?

Or is 'n' and 'd' insufficient?

Any reason (other than performance) that the other components (p, q, et al) are necessary for confidence in the key?

tyia.

rip...
  • 123
  • 4

2 Answers2

5

2313 was obsoleted by RFC 2437. 2437 was obsoleted by 3447. 3447 might have been obsoleted by 8017 but does anyone use it?

The version history on PKCS#1 v2.2 reads:

Version 2.2 updates the list of allowed hashing algorithms to align them with FIPS 180-4 [SHS], therefore adding SHA-224, SHA-512/224, and SHA-512/256.

Most developers will happily ignore it for the simple fact that these hash functions are relatively useless and should not have been standardized and haven't been included in all libraries. Of course it is possible to argue that applications are still compliant if they adhere to the obsoleted RFC 3447 or even RFC 2437 so in that sense it is being used.

Anyone know why? First option is that the Miller reference was wrong, second option is that the RFC editors were misquoting, misreading or misrepresenting Miller's stuff.

"efficient" is a big word here. It takes quite a few of computations and it is a relatively complex algorithm to implement (I've done so). It is more likely that it has been removed because it is not very practical even though it is mathematically correct.

I know that conventional (ie, there are StackOverflow questions on this) wisdom is that the modulus and the private exponent are all that is needed to use an RSA private key, assuming the public key components are known.

That is correct, a "plain" RSA implementation is - besides the padding and "plumbing" - just modular exponentiation, and that is perfectly fine to calculate given the modulus and exponent, as anybody that implemented this algorithm in any cryptography class can attest to.

Is that (when you get really down to it) correct conventional wisdom?

Absolutely. CRT is mainly there for the ~4 x speedup of private key operations.

Any reason (other than performance) that the other components (p, q, et al) are necessary for confidence in the key?

The only thing that might be interesting is that I've seen plain RSA implementations that were vulnerable against side channels while the CRT implementations were not.

This is also a big reason not to include the knowledge about generating the CRT parameters in the field. It would be tricky to ensure they are not vulnerable against side channels attacks. It doesn't make much sense to calculate the CRT parameters for each private key calculation either - the calculations are simply not that efficient.

So what we have here is a small oddball piece of knowledge that might be interesting if you ever receive an RSA key that doesn't include the parameters. Now if you really want then you can in that case re-generate them. But it is perfectly possible to perform the RSA private key operation anyway.

So given that a system normally manages its own private keys - they aren't relayed at all - then this trick is not needed. If the system needed CRT parameters then it would probably have been designed to keep them - it is mostly standard way of generating key pairs anyway. And if not it is usually possible and probably more secure to simply generate a new key pair and use that instead of mucking about with the existing one.

This is especially true if the private key (i.e. the private exponent) is stored securely in hardware. It may not be directly available to software in the first place.

If you really want to minimize storage then storing $p$ and $q$ is likely more efficient (or storing a 128 bit seed if you don't mind the inefficiency of finding primes and all the other issues associated with deterministically performing these calculations).


To be honest, I've never actually used my implementation and would not be able to find it. But sure, there will probably have been another implementation that has performed the necessary calculations and it might have gotten some engineers out of a tight spot where they really really needed the CRT parameters. The world is large, and this might well have happened.

Maarten Bodewes
  • 96,351
  • 14
  • 169
  • 323
4

There are probabilistic algorithms to factor $n$ into $p$ and $q$ from $n$, $e$, $d$. It's then easy to rebuild the full private key $(n,e,d,p,q,d_p,d_q,q_\text{inv})$. One such algorithm is there. A similar one is in OpenSSL key import, and other libraries. The time it takes in practice is acceptable (comparable to key generation). Doing that with side-channel resistance would be hard (and unstudied AFAIK), but not an issue in many contexts.

the modulus $n$ and the private exponent $d$ are all that is needed to use an RSA private key

Yes that's sufficient to evaluate the RSA private key transformation $x\mapsto y=x^d\bmod n$. But if you care about making that operation three times faster or so, you want to use the Chinese Remainder Theorem method, which disregards $d$ and use $n$, $p$, $q$, $d_p=e^{-1}\bmod(p-1)$, $d_q=e^{-1}\bmod(q-1)$, $q_\text{inv}=q^{-1}\bmod p$ to compute the same $y\,$; and you want $e$ for reasons detailed later.

Or is $n$ and $d$ insufficient?

Yes, for performance in particular, see above. $n$ and $d$ are not sufficient to reconstruct the full form of the private key (for arbitrary odd unknown large $e$ as allowed by PKCS#1 and FIPS 186-5). The RFC 2313 quote is correct in including "provided the public key is known" because $e$ is in the public key, not included in the $(n,d)$ format of the private key, and necessary together with $d$ to factor $n$ if $p$ and $q$ are unavailable. And it is is correct in making reference to the Miller article that lays the basis for the methods actually used.

That's part of RSA folklore. I have no idea why it was removed, and if it's still in some modern documents.

Update: On the other hand, RSA usually uses a small $e$, and small values can be guessed and checked. If $r^{e\,d}\bmod n=r$ for small prime $r$ (e.g. $r=2$) then most likely a guess of $e$ is right. It's worth trying the usual values of $e$: 65537, 3, 5, 17, 257 which are the Fermat primes $F_i=2^{(2^i)}+1$, 37 which is also common. And we can find small $e$ systematically: compute $g_1=2^d\bmod n$, then $g_2={g_1}^2\bmod n$, then $g_e=g_2\,g_{e-2}\bmod n$ for successive odd $e$, until we find one $g_e=2$. Most likely, that gets us $e$. We can then check $r^{e\,d}\bmod n=r$ for a few odd primes $r$ to be sure. And further: by using methods similar to baby-step/giant-step or collision search, we can find medium $e$ with in the order of $2\sqrt{e_\max}$ modular multiplications.

Any reason (other than performance) that the other components ($p$, $q$, et al) are necessary for confidence in the key?

It is important to have $e$ in the private key for at least two reasons beyond performance:

  • $e$ allows masking to resist side channel attacks: to compute $y=x^d\bmod n$, we can draw a random $r$, compute $s=r^e\bmod n$, then $t=x\,s\bmod n$, then $u=t^d\bmod n$, then $y=(r^{-1}\bmod n)\,u\bmod n$. Because $t$ and $u$ are different and random-like from one execution to the other, some attacks are thwarted.
  • $e$ allows checking the result to resist fault attacks: we check that $y^e\bmod n=x$. Many errors induced in the calculation, or in the storage of $n$ or $d$, are caught by this check.

The other components $p$, $q$, $d_p$, $d_q$, $q_\text{inv}$ are only useful for performance reasons.

Update: occasionally, with HSMs or crypto-accelerators, the hardware for modular exponentiation may have a width limitation that makes it unusable for computation modulo $n$, but usable modulo $p$ and $q$. If this is the case, not having $p$ and $q$ has a huge performance hit, or could even make use of $(n,d)$ impossible for lack of an implementation.

fgrieu
  • 149,326
  • 13
  • 324
  • 622