[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r13251 - gnunet/src/util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r13251 - gnunet/src/util |
Date: |
Fri, 8 Oct 2010 19:43:44 +0200 |
Author: grothoff
Date: 2010-10-08 19:43:44 +0200 (Fri, 08 Oct 2010)
New Revision: 13251
Modified:
gnunet/src/util/crypto_random.c
Log:
nonce
Modified: gnunet/src/util/crypto_random.c
===================================================================
--- gnunet/src/util/crypto_random.c 2010-10-08 17:34:16 UTC (rev 13250)
+++ gnunet/src/util/crypto_random.c 2010-10-08 17:43:44 UTC (rev 13251)
@@ -60,8 +60,9 @@
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)
@@ -75,25 +76,23 @@
}
while (ret >= ul);
return ret % i;
- }
- else if (mode == GNUNET_CRYPTO_QUALITY_NONCE)
- {
+ case GNUNET_CRYPTO_QUALITY_NONCE:
ul = UINT32_MAX - (UINT32_MAX % i);
do
{
gcry_create_nonce(&ret, sizeof(ret));
}
while (ret >= ul);
-
return ret % i;
- }
- else
- {
+ case GNUNET_CRYPTO_QUALITY_WEAK:
ret = i * weak_random ();
if (ret >= i)
ret = i - 1;
return ret;
+ default:
+ GNUNET_assert (0);
}
+ return 0;
}
@@ -142,8 +141,9 @@
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
{
@@ -152,9 +152,7 @@
}
while (ret >= ul);
return ret % max;
- }
- else if (mode == GNUNET_CRYPTO_QUALITY_NONCE)
- {
+ case GNUNET_CRYPTO_QUALITY_NONCE:
ul = UINT64_MAX - (UINT64_MAX % max);
do
{
@@ -163,14 +161,15 @@
while (ret >= ul);
return ret % max;
- }
- else
- {
+ case GNUNET_CRYPTO_QUALITY_WEAK:
ret = max * weak_random ();
if (ret >= max)
ret = max - 1;
return ret;
+ default:
+ GNUNET_assert (0);
}
+ return 0;
}
/**
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r13251 - gnunet/src/util,
gnunet <=