question about cipher/primegen.c

Newton Hammet newton at hammet.net
Tue Dec 16 09:42:12 CET 2003


Hello again everyone,

I may have answered my own question.  The documentation has
a bug. It should say "set high order and low order bits to 1".
That is what the code actually does (both mpi_set_bit and
mpi_set_highbit both set target bits to 1, while mpi_set_highbit
clears bits above the set bit).

Regards,
Newton


>
> Hello Everyone, and any gnupg developers out there.
>
> I am studying primegen.c and other source modules of gnupg, primarly for
> my own edification. And I have a question about primegen.c where a
> random number is selected before testing it for primality. The code
> comment says that the high order bit is set to "1" to insure that key is
> a certain size, and the next to high order bit is set to "0" for a
> similiar reason.  But why in the world would the lo-order bit be set to
> zero?  Isn't the number supposed to be odd to start with prior to
> checking for primality?  Or are mpi numbers represented as one
> less or more than the actual number?  Or is there some other explanation
> lurking the source code that I have not yet discovered?
>
> Hopefully someone has an answer for me that will solve this particular
> puzzle before I eventually solve it myself.
>
> Here is the lines of code in question :::
>
>    /* generate a random number */
>     {   char *p = get_random_bits( nbits, randomlevel, secret );
>         mpi_set_buffer( prime, p, (nbits+7)/8, 0 );
>         m_free(p);
>     }
>
>     /*
>            If we are generating a secret prime we are most probably
> doing that for RSA, to make sure that the modulus does have
> the requested keysize we set the 2 high order bits */
>     mpi_set_highbit( prime, nbits-1 );
>         if (secret)
>           mpi_set_bit (prime, nbits-2);
>     mpi_set_bit( prime, 0 );   /*** code in question ?????? ***/
>
>
>
>
>
> _______________________________________________
> Gnupg-users mailing list
> Gnupg-users at gnupg.org
> http://lists.gnupg.org/mailman/listinfo/gnupg-users






More information about the Gnupg-users mailing list