summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2003-01-24 10:58:04 +0000
committerWerner Koch <wk@gnupg.org>2003-01-24 10:58:04 +0000
commit8ccfdc7879b49e1e5e7f71133d208659b6177690 (patch)
treec4d73b14e627d80f586b8d283a71d28dff758de8
parente4e83dba64890c5153df575d23481ddf8f1d61c0 (diff)
downloadlibgcrypt-8ccfdc7879b49e1e5e7f71133d208659b6177690.tar.gz
* random.c (_gcry_register_random_progress): New.
(_gcry_random_progress): New. * rndlinux.c (gather_random): Call the random progress function.
-rw-r--r--cipher/ChangeLog7
-rw-r--r--cipher/rand-internal.h4
-rw-r--r--cipher/random.c24
-rw-r--r--cipher/random.h2
-rw-r--r--cipher/rndlinux.c8
5 files changed, 44 insertions, 1 deletions
diff --git a/cipher/ChangeLog b/cipher/ChangeLog
index c6f1fff0..6f7dfa70 100644
--- a/cipher/ChangeLog
+++ b/cipher/ChangeLog
@@ -1,3 +1,10 @@
+2003-01-24 Werner Koch <wk@gnupg.org>
+
+ * random.c (_gcry_register_random_progress): New.
+ (_gcry_random_progress): New.
+
+ * rndlinux.c (gather_random): Call the random progress function.
+
2003-01-23 Werner Koch <wk@gnupg.org>
* rsa.c (generate): New arg USE_E to request a specific public
diff --git a/cipher/rand-internal.h b/cipher/rand-internal.h
index 0590590c..43c6087b 100644
--- a/cipher/rand-internal.h
+++ b/cipher/rand-internal.h
@@ -27,4 +27,8 @@ void rndos2_constructor(void);
void rndatari_constructor(void);
void rndmvs_constructor(void);
+void _gcry_random_progress (const char *what, int printchar,
+ int current, int total);
+
+
#endif /*G10_RAND_INTERNAL_H*/
diff --git a/cipher/random.c b/cipher/random.c
index 923b338d..f7b23787 100644
--- a/cipher/random.c
+++ b/cipher/random.c
@@ -130,6 +130,9 @@ static struct {
ulong naddbytes;
} rndstats;
+static void (*progress_cb) (void *,const char*,int,int, int );
+static void *progress_cb_data;
+
/* Note, we assume that this function is used before any concurrent
access happens */
@@ -153,6 +156,27 @@ initialize(void)
_gcry_cipher_modules_constructor ();
}
+
+/* Used to register a progress callback. */
+void
+_gcry_register_random_progress (void (*cb)(void *,const char*,int,int,int),
+ void *cb_data )
+{
+ progress_cb = cb;
+ progress_cb_data = cb_data;
+}
+
+
+/* This progress function is currently used by the random modules to give hint
+ on how much more entropy is required. */
+void
+_gcry_random_progress (const char *what, int printchar, int current, int total)
+{
+ if (progress_cb)
+ progress_cb (progress_cb_data, what, printchar, current, total);
+}
+
+
/* Initialize this random subsystem. This function memrely calls the
initialzies and does not do anything more. Doing this is not
really required but when running in a threaded environment we might
diff --git a/cipher/random.h b/cipher/random.h
index 41b5f21a..0c7d9e0f 100644
--- a/cipher/random.h
+++ b/cipher/random.h
@@ -26,6 +26,8 @@
#define fast_random_poll() _gcry_fast_random_poll ()
void _gcry_random_initialize (void);
+void _gcry_register_random_progress (void (*cb)(void *,const char*,int,int,int),
+ void *cb_data );
void _gcry_random_dump_stats(void);
void _gcry_secure_random_alloc(void);
int _gcry_quick_random_gen( int onoff );
diff --git a/cipher/rndlinux.c b/cipher/rndlinux.c
index 143c58a2..aa984a8f 100644
--- a/cipher/rndlinux.c
+++ b/cipher/rndlinux.c
@@ -1,5 +1,5 @@
/* rndlinux.c - raw random number for OSes with /dev/random
- * Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 2001, 2002, 2003 Free Software Foundation, Inc.
*
* This file is part of Libgcrypt.
*
@@ -43,6 +43,7 @@
#include "types.h"
#include "g10lib.h"
#include "dynload.h"
+#include "rand-internal.h"
static int open_device( const char *name, int minor );
static int gather_random( void (*add)(const void*, size_t, int), int requester,
@@ -122,9 +123,14 @@ gather_random( void (*add)(const void*, size_t, int), int requester,
if( !(rc=select(fd+1, &rfds, NULL, NULL, &tv)) ) {
if( !warn )
{
+#ifndef IS_MODULE
+ _gcry_random_progress ("need_entropy", 'X', 0, (int)length);
+#else
log_info (_("not enough random bytes available (need %d bytes)\n"),
(int)length);
+
log_info (_("please do some other work to give the OS a chance to collect more entropy\n"));
+#endif
}
warn = 1;
continue;