Modular add/sub/mul incorrect result if result and modulus pointer are equal

Jussi Kivilinna jussi.kivilinna at iki.fi
Fri Jun 2 18:43:26 CEST 2023


On 2.6.2023 12.27, Werner Koch via Gcrypt-devel wrote:
> On Fri,  2 Jun 2023 03:20, Guido Vranken said:
>> In the following program, the results of addm, subm or mulm are all zero,
>> but should be 6, 5 and 1, respectively.
> 
> I modified the included mpicalc program (patch against 1.10 attached) to
> allow for addm and subm but can't replicate your findings.:
> 
> $ mpicalc
> 2
> 4
> 7
> M+pc
> 06
> 2
> 4
> 7
> M-pc
> 05
> 2
> 4
> 7
> mpc
> 01
> 
> I have not checked your code, though.

Below is code for mpi_addm. If W and M are the same (as is in Guido's example),
then it looks that W and M gets replaced by mpi_add result. After that mpi_mod
gives zero as result (have not tested, just inspecting code).

   void
   _gcry_mpi_addm( gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m)
   {
     mpi_add (w, u, v);
     mpi_mod (w, w, m);
   }

-Jussi

> 
> 
> Shalom-Salam,
> 
>     Werner
> 
> 
> _______________________________________________
> Gcrypt-devel mailing list
> Gcrypt-devel at gnupg.org
> https://lists.gnupg.org/mailman/listinfo/gcrypt-devel




More information about the Gcrypt-devel mailing list