aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_random.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-11-01 20:47:52 +0000
committerChristian Grothoff <christian@grothoff.org>2009-11-01 20:47:52 +0000
commit652e89b59ed2207c2c12172fdabcd6e659995c81 (patch)
treef054c819d483c1056e18c1099afd4c7fcd2582a0 /src/util/crypto_random.c
parent5e4113e83368849500792e57946c3d8dd9e548d8 (diff)
downloadgnunet-652e89b59ed2207c2c12172fdabcd6e659995c81.tar.gz
gnunet-652e89b59ed2207c2c12172fdabcd6e659995c81.zip
fixing bio testcase and a bug in bio.c, also indenting
Diffstat (limited to 'src/util/crypto_random.c')
-rw-r--r--src/util/crypto_random.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c
index 50af9f251..5d85d1daa 100644
--- a/src/util/crypto_random.c
+++ b/src/util/crypto_random.c
@@ -37,8 +37,7 @@
37 * @return a random value in the interval [0,i[. 37 * @return a random value in the interval [0,i[.
38 */ 38 */
39uint32_t 39uint32_t
40GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, 40GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i)
41 uint32_t i)
42{ 41{
43#ifdef gcry_fast_random_poll 42#ifdef gcry_fast_random_poll
44 static unsigned int invokeCount; 43 static unsigned int invokeCount;
@@ -55,8 +54,7 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode,
55 gcry_fast_random_poll (); 54 gcry_fast_random_poll ();
56#endif 55#endif
57 gcry_randomize ((unsigned char *) &ret, 56 gcry_randomize ((unsigned char *) &ret,
58 sizeof (uint32_t), 57 sizeof (uint32_t), GCRY_STRONG_RANDOM);
59 GCRY_STRONG_RANDOM);
60 return ret % i; 58 return ret % i;
61 } 59 }
62 else 60 else
@@ -108,8 +106,7 @@ GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n)
108 * @return random 64-bit number 106 * @return random 64-bit number
109 */ 107 */
110uint64_t 108uint64_t
111GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, 109GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max)
112 uint64_t max)
113{ 110{
114 uint64_t ret; 111 uint64_t ret;
115 112
@@ -117,8 +114,7 @@ GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode,
117 if (mode == GNUNET_CRYPTO_QUALITY_STRONG) 114 if (mode == GNUNET_CRYPTO_QUALITY_STRONG)
118 { 115 {
119 gcry_randomize ((unsigned char *) &ret, 116 gcry_randomize ((unsigned char *) &ret,
120 sizeof (uint64_t), 117 sizeof (uint64_t), GCRY_STRONG_RANDOM);
121 GCRY_STRONG_RANDOM);
122 return ret % max; 118 return ret % max;
123 } 119 }
124 else 120 else
@@ -144,8 +140,7 @@ GNUNET_CRYPTO_random_disable_entropy_gathering ()
144/** 140/**
145 * Initializer 141 * Initializer
146 */ 142 */
147void __attribute__ ((constructor)) 143void __attribute__ ((constructor)) GNUNET_util_random_init ()
148GNUNET_util_random_init()
149{ 144{
150 SRANDOM (time (NULL)); 145 SRANDOM (time (NULL));
151} 146}