Mailing List Archive

mpi_subm use in elgamal.c:sign
I'm trying to steal code for Pluto, and as a result I've got to
understand it to a modest degree. Something doesn't make sense to me.
Probably it is my misunderstanding, but it would be great to clear
that up.

In gnupg-1.0.0/cipher/elgamal.c:sign, the following sequence occurs:

mpi_subm(t, input, t, p_1 );
while( mpi_is_neg(t) )
mpi_add(t, t, p_1);

When could mpi_is_neg return 1? As I understand it, the mpi_subm
call will make t equal to
(input - t) % p_1
The % (calculated by mpi_fdiv_r) can only yield negative result if p_1
is negative, but it is in fact one less than a large prime (I think).

Hugh Redelmeier
hugh@mimosa.com voice: +1 416 482-8253
Re: mpi_subm use in elgamal.c:sign [ In reply to ]
"D. Hugh Redelmeier" <hugh@mimosa.com> writes:

> In gnupg-1.0.0/cipher/elgamal.c:sign, the following sequence occurs:
>
> mpi_subm(t, input, t, p_1 );
> while( mpi_is_neg(t) )
> mpi_add(t, t, p_1);

I can't rememeber. I checked that it has been in v0.0.0 so it might
left over code from some experiments :-(. ElGamal signatures are not
anymore used very much, but this should not been there - I'll better
throw a bug() here.

The code is out for nearly 2 years and nobody has noticed it - hmmm
... Please go ahead and check more code.


Werner


--
Werner Koch at guug.de www.gnupg.org keyid 621CC013