Non-termination in gcry_mpi_invm, behavior of gcry_mpi_powm

Florian Dold dold at
Tue Feb 4 02:36:59 CET 2014


There's a small problem with gcry_mpi_invm and negative numbers.
The following code does not terminate, when it should just set
x to (-1 mod 17) = 16.

gcry_mpi_t x = gcry_mpi_new (0);
gcry_mpi_t p = gcry_mpi_new (0);
if ((NULL == x) || (NULL == p)) abort();
gcry_mpi_set_ui (x, 0);
gcry_mpi_sub_ui (x, x, 1);
gcry_mpi_set_ui (p, 17);
gcry_mpi_invm (x, x, p);

Furthermore, I've noticed that gcry_mpi_powm has no return value.  What
happens, in general, if the result does not exist, e.g. for

- Florian

More information about the Gcrypt-devel mailing list