Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does a .key file include P,Q,DP,DQ

By loading a pre-created .key file that includes an RSA Private Key only I noticed, that it contains the following numbers:

Modulus     (private modulus)
Exponent    (private exponent)
P           (prime exponent)
Q           (prime exponent)
DP
DQ
InverseQ

I am saving the key file somewhere, where storage is very small (portable). I though of only saving Modulus and Exponent. I understand P,Q and E are necessary to create modulus and exponent, however:

Question:

What is the purpose in saving all this data to a .key file, when PrivateModulus and PrivateExponent are enought to sign and decrypt messages?

like image 231
cvetozaver Avatar asked Sep 30 '22 00:09

cvetozaver


1 Answers

Well, you need the public key Modulus and Exponent for encryption and the private key Modulus and D for decryption and signing.

P and Q are probably just added there for safety, since there is no efficient way to reconstruct them from the other given values. So in case your D gets corrupted, you can reconstruct it or if possibly a special implementation requires them for some Math-tricks to optimize the calculations.

The values of DP, DQ and InverseQ are used by some implementations to calculate RSA using the Chinese Remainder Theorem for speeding up the whole process.

DP       = D mod (P - 1)
DQ       = D mod (Q - 1)
InverseQ = Q^-1 mod (P - 1)

For more information on how that works, best check out this crpypto.stackexchange-question or the Wikipedia-article.

like image 177
i_turo Avatar answered Oct 06 '22 00:10

i_turo