aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_random.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-06-25 15:37:07 +0000
committerChristian Grothoff <christian@grothoff.org>2010-06-25 15:37:07 +0000
commit94f01bdd2fda575769f01f8072689fa6936af8f4 (patch)
treec2ffd2a36b7babe0b47335f407b3f20e71bb25ba /src/util/crypto_random.c
parent2d4ae427e8d2a4bc305c42100d5cb35a75916879 (diff)
downloadgnunet-94f01bdd2fda575769f01f8072689fa6936af8f4.tar.gz
gnunet-94f01bdd2fda575769f01f8072689fa6936af8f4.zip
cleaning argz mess
Diffstat (limited to 'src/util/crypto_random.c')
-rw-r--r--src/util/crypto_random.c92
1 files changed, 90 insertions, 2 deletions
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c
index 25ba4db2a..0a092cdcc 100644
--- a/src/util/crypto_random.c
+++ b/src/util/crypto_random.c
@@ -27,6 +27,7 @@
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_common.h" 28#include "gnunet_common.h"
29#include "gnunet_crypto_lib.h" 29#include "gnunet_crypto_lib.h"
30#include "gnunet_os_lib.h"
30#include <gcrypt.h> 31#include <gcrypt.h>
31 32
32/** 33/**
@@ -161,12 +162,99 @@ GNUNET_CRYPTO_random_disable_entropy_gathering ()
161 gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); 162 gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
162} 163}
163 164
165
166/**
167 * Process ID of the "find" process that we use for
168 * entropy gathering.
169 */
170static pid_t genproc;
171
164/** 172/**
165 * Initializer 173 * Function called by libgcrypt whenever we are
174 * blocked gathering entropy.
166 */ 175 */
167void __attribute__ ((constructor)) GNUNET_util_random_init () 176static void
177entropy_generator (void *cls,
178 const char *what, int printchar, int current, int total)
179{
180 unsigned long code;
181 enum GNUNET_OS_ProcessStatusType type;
182 int ret;
183
184 if (0 != strcmp (what, "need_entropy"))
185 return;
186 if (current == total)
187 {
188 if (genproc != 0)
189 {
190 if (0 != PLIBC_KILL (genproc, SIGTERM))
191 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "kill");
192 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc));
193 genproc = 0;
194 }
195 return;
196 }
197 if (genproc != 0)
198 {
199 ret = GNUNET_OS_process_status (genproc, &type, &code);
200 if (ret == GNUNET_NO)
201 return; /* still running */
202 if (ret == GNUNET_SYSERR)
203 {
204 GNUNET_break (0);
205 return;
206 }
207 if (0 != PLIBC_KILL (genproc, SIGTERM))
208 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "kill");
209 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc));
210 genproc = 0;
211 }
212 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
213 _("Starting `%s' process to generate entropy\n"), "find");
214 genproc = GNUNET_OS_start_process (NULL, NULL, "sh",
215 "sh",
216 "-c",
217 "exec find / -mount -type f -exec cp {} /dev/null \\; 2>/dev/null",
218 NULL);
219}
220
221
222static void
223killfind ()
224{
225 if (genproc != 0)
226 {
227 PLIBC_KILL (genproc, SIGKILL);
228 genproc = 0;
229 }
230}
231
232
233void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init ()
168{ 234{
169 SRANDOM (time (NULL)); 235 SRANDOM (time (NULL));
236 gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
237 if (!gcry_check_version (GCRYPT_VERSION))
238 {
239 fprintf (stderr,
240 _
241 ("libgcrypt has not the expected version (version %s is required).\n"),
242 GCRYPT_VERSION);
243 abort ();
244 }
245#ifdef gcry_fast_random_poll
246 gcry_fast_random_poll ();
247#endif
248 gcry_set_progress_handler (&entropy_generator, NULL);
249 atexit (&killfind);
170} 250}
171 251
252
253void __attribute__ ((destructor)) GNUNET_CRYPTO_random_fini ()
254{
255 gcry_set_progress_handler (NULL, NULL);
256}
257
258
259
172/* end of crypto_random.c */ 260/* end of crypto_random.c */