GNUNET_assert (i > 0);
- if (mode == GNUNET_CRYPTO_QUALITY_STRONG)
+ switch (mode)
{
+ case GNUNET_CRYPTO_QUALITY_STRONG:
/* see http://lists.gnupg.org/pipermail/gcrypt-devel/2004-May/000613.html */
#ifdef gcry_fast_random_poll
if ((invokeCount++ % 256) == 0)
}
while (ret >= ul);
return ret % i;
- }
- else
- {
+ case GNUNET_CRYPTO_QUALITY_NONCE:
+ ul = UINT32_MAX - (UINT32_MAX % i);
+ do
+ {
+ gcry_create_nonce(&ret, sizeof(ret));
+ }
+ while (ret >= ul);
+ return ret % i;
+ case GNUNET_CRYPTO_QUALITY_WEAK:
ret = i * weak_random ();
if (ret >= i)
ret = i - 1;
return ret;
+ default:
+ GNUNET_assert (0);
}
+ return 0;
}
uint64_t ul;
GNUNET_assert (max > 0);
- if (mode == GNUNET_CRYPTO_QUALITY_STRONG)
+ switch (mode)
{
+ case GNUNET_CRYPTO_QUALITY_STRONG:
ul = UINT64_MAX - (UINT64_MAX % max);
do
{
}
while (ret >= ul);
return ret % max;
- }
- else
- {
+ case GNUNET_CRYPTO_QUALITY_NONCE:
+ ul = UINT64_MAX - (UINT64_MAX % max);
+ do
+ {
+ gcry_create_nonce(&ret, sizeof(ret));
+ }
+ while (ret >= ul);
+
+ return ret % max;
+ case GNUNET_CRYPTO_QUALITY_WEAK:
ret = max * weak_random ();
if (ret >= max)
ret = max - 1;
return ret;
+ default:
+ GNUNET_assert (0);
}
+ return 0;
}
/**
* Process ID of the "find" process that we use for
* entropy gathering.
*/
-static pid_t genproc;
+static struct GNUNET_OS_Process *genproc;
/**
* Function called by libgcrypt whenever we are
return;
if (current == total)
{
- if (genproc != 0)
+ if (genproc != NULL)
{
- if (0 != PLIBC_KILL (genproc, SIGTERM))
+ if (0 != GNUNET_OS_process_kill (genproc, SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "kill");
GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc));
- genproc = 0;
+ GNUNET_OS_process_close (genproc);
+ genproc = NULL;
}
return;
}
- if (genproc != 0)
+ if (genproc != NULL)
{
ret = GNUNET_OS_process_status (genproc, &type, &code);
if (ret == GNUNET_NO)
GNUNET_break (0);
return;
}
- if (0 != PLIBC_KILL (genproc, SIGTERM))
+ if (0 != GNUNET_OS_process_kill (genproc, SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "kill");
GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc));
- genproc = 0;
+ GNUNET_OS_process_close (genproc);
+ genproc = NULL;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Starting `%s' process to generate entropy\n"), "find");
static void
killfind ()
{
- if (genproc != 0)
+ if (genproc != NULL)
{
- PLIBC_KILL (genproc, SIGKILL);
- genproc = 0;
+ GNUNET_OS_process_kill (genproc, SIGKILL);
+ GNUNET_OS_process_close (genproc);
+ genproc = NULL;
}
}
void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init ()
{
- SRANDOM (time (NULL));
gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
if (!gcry_check_version (GCRYPT_VERSION))
{
#endif
gcry_set_progress_handler (&entropy_generator, NULL);
atexit (&killfind);
+ SRANDOM (time (NULL) ^ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
}
/* end of crypto_random.c */
+