diff options
Diffstat (limited to 'src/util/crypto_random.c')
-rw-r--r-- | src/util/crypto_random.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c index e66c3c71b..504741200 100644 --- a/src/util/crypto_random.c +++ b/src/util/crypto_random.c | |||
@@ -95,6 +95,47 @@ GNUNET_CRYPTO_seed_weak_random (int32_t seed) | |||
95 | SRANDOM (seed); | 95 | SRANDOM (seed); |
96 | } | 96 | } |
97 | 97 | ||
98 | /** | ||
99 | * @ingroup crypto | ||
100 | * Fill block with a random values. | ||
101 | * | ||
102 | * @param mode desired quality of the random number | ||
103 | * @param buffer the buffer to fill | ||
104 | * @param length buffer length | ||
105 | */ | ||
106 | void | ||
107 | GNUNET_CRYPTO_random_block (enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length) | ||
108 | { | ||
109 | #ifdef gcry_fast_random_poll | ||
110 | static unsigned int invokeCount; | ||
111 | #endif | ||
112 | switch (mode) | ||
113 | { | ||
114 | case GNUNET_CRYPTO_QUALITY_STRONG: | ||
115 | /* see http://lists.gnupg.org/pipermail/gcrypt-devel/2004-May/000613.html */ | ||
116 | #ifdef gcry_fast_random_poll | ||
117 | if ((invokeCount++ % 256) == 0) | ||
118 | gcry_fast_random_poll (); | ||
119 | #endif | ||
120 | gcry_randomize (buffer, length, GCRY_STRONG_RANDOM); | ||
121 | return; | ||
122 | case GNUNET_CRYPTO_QUALITY_NONCE: | ||
123 | gcry_create_nonce (buffer, length); | ||
124 | return; | ||
125 | case GNUNET_CRYPTO_QUALITY_WEAK: | ||
126 | /* see http://lists.gnupg.org/pipermail/gcrypt-devel/2004-May/000613.html */ | ||
127 | #ifdef gcry_fast_random_poll | ||
128 | if ((invokeCount++ % 256) == 0) | ||
129 | gcry_fast_random_poll (); | ||
130 | #endif | ||
131 | gcry_randomize (buffer, length, GCRY_WEAK_RANDOM); | ||
132 | return; | ||
133 | return; | ||
134 | default: | ||
135 | GNUNET_assert (0); | ||
136 | } | ||
137 | } | ||
138 | |||
98 | 139 | ||
99 | /** | 140 | /** |
100 | * Produce a random value. | 141 | * Produce a random value. |