问题
I've been working on a project based on RSA key exchange and I have used Crypto++ Library. I followed the guidelines in https://www.cryptopp.com/wiki/Raw_RSA and my project works fine. However, I noticed that the public key is always fixed to 1710 = 1116 and when I looked in the rsa.cpp in Crypto++ that public key is fixed!
Again, my project works fine, but I just want to know why..
回答1:
I noticed that the public key is always fixed to 1710 = 1116 and when I looked in the rsa.cpp in Crypto++ that public key is fixed!
... my project works fine, but I just want to know why..
That's the public exponent, and you can change it. See InvertibleRSAFunction Class Reference.
InvertibleRSAFunction
is an odd name if you are not familiar with the library, but there's a type define for typedef InvertibleRSAFunction PrivateKey
in rsa.h. RSA::PrivateKey
's Initialize
function that takes the RandomNumberGenerator
is the one that creates keys:
void Initialize (RandomNumberGenerator &rng, unsigned int modulusBits, const Integer &e=17)
The only requirement for the public exponent (e
) is it must be co-prime or relatively prime to phi. Phi is Euler's Φ-function, and it's defined as (p-1)*(q-1)
. It ensures there's an inverse (the private exponent, d
).
The public exponent is usually selected for a low-hamming weight to make public key operations faster. A low hamming weight means it has very few 1's, and typical values are 3 (0x3), 17 (0x11) and 65537 (0x10001). Fewer 1's makes the exponentiation fast for the public key operations.
For completeness, the public key is {n,e}
. The private key is {n,e,d}
. Private keys with CRT parameters are {n,e,d,p,q,dp,dp,u}
.
来源:https://stackoverflow.com/questions/36555930/rsa-function-generates-public-key-e-always-to-17