Modular multiplication

bodrato at bodrato at
Mon May 14 08:19:09 CEST 2012


Il Dom, 13 Maggio 2012 5:10 pm, Di Maria Giovanni ha scritto:
> Can I do a Modular Multiplication in GMP, as fast possible (a*b MOD c) ?
> Is there a specific function?

You can easily obtain a single modular multiplication with
mpz_mul (r, a, b);
mpz_mod (r, r, c);

If you need to concatenate many modular operations, there are different
strategies (and representations) to obtain better performance than the
naive sequence, op;mod;op;mod;...
Unfortunately, AFAIK, the best strategy depends on the operations you
need, no "specific function" could cover them all.

You may need modular exponentiation:

You should read also other parts of the manual:

Buon divertimento,


More information about the gmp-discuss mailing list