Modular multiplication

bodrato at mail.dm.unipi.it bodrato at mail.dm.unipi.it
Mon May 14 08:19:09 CEST 2012


Ciao,

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:
http://gmplib.org/manual/Integer-Exponentiation.html

You should read also other parts of the manual:
http://gmplib.org/manual/Integer-Division.html#index-mpz_005fmod-329

Buon divertimento,
Marco

-- 
http://bodrato.it/papers/



More information about the gmp-discuss mailing list