gmp_pow() will not accept a GMP number for exponen

2019-08-28 15:08发布

问题:

I am playing around in PHP with RSA and big numbers. I need to be able to take numbers to the power of an exponent that has ~256 to ~512 bytes using gmp_pow(). Does anyone have any suggestions?

回答1:

You should use gmp_powm() which automatically reduces the intermediate values to be less than the modulus value. This exactly what you want for RSA.

gmp_pow() doesn't accept an exponent large than a long since the intermediate values will be larger than the addressable memory in your computer.