mini-gmp mpz_powm incorrect result

Niels Möller nisse at lysator.liu.se
Tue Aug 30 08:45:34 CEST 2022


Paul Zimmermann <Paul.Zimmermann at inria.fr> writes:

> $ diff -u mini-gmp.c.orig mini-gmp.c
> --- mini-gmp.c.orig     2022-08-29 10:28:20.700995412 +0200
> +++ mini-gmp.c  2022-08-29 10:27:36.112191428 +0200
> @@ -3060,6 +3060,7 @@
>    if (en == 0)
>      {
>        mpz_set_ui (r, 1);
> +      mpz_tdiv_r (r, r, m);
>        return;
>      }

Should solve the problem, but maybe a bit overkill to call mpz_tdiv_r. Perhaps

   mpz_set_ui (r, mpz_cmpabs_ui (m, 1) != 0);

or even (mn == 0 check just above this code rules out |m| < 1)

   mpz_set_ui (r, mpz_cmpabs_ui (m, 1));

Regards,
/Niels

-- 
Niels Möller. PGP key CB4962D070D77D7FCB8BA36271D8F1FF368C6677.
Internet email is subject to wholesale government surveillance.


More information about the gmp-bugs mailing list