Any comments on the last release?

Werner Koch wk at gnupg.org
Mon Apr 19 14:47:41 CEST 2004


On Sat, 17 Apr 2004 19:53:30 +0300, Nikos Mavroyanopoulos said:

>> #define GCRY_PRIME_CHECK_AT_GOT_PRIME   1
>> #define GCRY_PRIME_CHECK_AT_MAYBE_PRIME 2
>> if you probably check for mode (which used to be 0 in previous
>> versions), it should not make any difference.
> How can I do that? I currently generate the parameters using
> gcry_pk_genkey() with a sexp of "(genkey(rsa(nbits %d)))".

That is only used for the primegen interface and not for the higher
level public key generation.  IIRC, you requested this interface for
DH use?

Anywat, the old code should have looked like this:


static int 
cb (void *arg, int mode, gcry_mpi_t candidate)
{
   if (!mode)
      return 1;
   return true_if_this prime_is_of_my_taste (candidate)
}


...

      err = gcry_prime_generate (&prime,
				 prime_specs[i].prime_bits,
				 prime_specs[i].factor_bits,
				 cb, cb_arg,
				 GCRY_STRONG_RANDOM,
				 prime_specs[i].flags);

and new code making use of the other mode might look like this:

static int 
cb (void *arg, int mode, gcry_mpi_t candidate)
{
   switch (mode)
   {
   case GCRY_PRIME_CHECK_AT_FINISH /* This has the value 0 */:
     return true_if_this prime_is_of_my_taste (candidate);
   case GCRY_PRIME_CHECK_AT_GOT_PRIME:
     return true_if_prime_should_be_used_for_composition (candidate);
   case GCRY_PRIME_CHECK_AT_MAYBE_PRIME:
     return true_if_prime_check_shall_continue_for (candidate);
   default:
     return 1;
  }
}

Applications might want to check at GCRY_PRIME_CHECK_AT_MAYBE_PRIME
time whether the candidate has the required properties (e.g. high bits
sets) and avoid the expensive Rabin-Miller tests.  Not, sure whether
this is really useful, though.

However it is important to return 1 for unknown values of MODE so that
we can add new mode values.


Salam-Shalom,

   Werner




More information about the Gcrypt-devel mailing list