stranger
stranger

Reputation: 189

GMP mpz_pow_ui with very large exponent

i have very large exponent, where exponent

e = 26959946667150639794667015087019630673637144422540572481103610249951 

(225 bits)

But, according to mpz_pow_ui template as follows:

void mpz_pow_ui (mpz_t ROP, mpz_t BASE, unsigned long int EXP)

I think e does not fit to that function, is there another way to calculate large exponent using GMP C++?

Upvotes: 2

Views: 2259

Answers (1)

ShadowRanger
ShadowRanger

Reputation: 155403

Don't. If the base value being exponentiated is anything other than -1, 0, or 1, you'll blow main memory (you'll exceed the available virtual address space entirely). If the goal is to do modular exponentiation (where the result can fit in memory because it's reduced mod some number that fits in RAM), you want mpz_powm (or mpz_powm_sec if you're writing "real" crypto code; the _sec variant defends against timing attacks for key recovery).

The reason GMP only accepts an unsigned integer for that function is because arbitrary precision exponents only lead to tears in this case.

Upvotes: 4

Related Questions