summaryrefslogtreecommitdiff
path: root/plugins/MirOTR/Libgcrypt/random/rndunix.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/MirOTR/Libgcrypt/random/rndunix.c')
-rw-r--r--plugins/MirOTR/Libgcrypt/random/rndunix.c62
1 files changed, 45 insertions, 17 deletions
diff --git a/plugins/MirOTR/Libgcrypt/random/rndunix.c b/plugins/MirOTR/Libgcrypt/random/rndunix.c
index 1faf9abc0e..1b810d72ae 100644
--- a/plugins/MirOTR/Libgcrypt/random/rndunix.c
+++ b/plugins/MirOTR/Libgcrypt/random/rndunix.c
@@ -51,32 +51,32 @@
Subject: Re: LGPL for the windows entropy gatherer
To: wk@gnupg.org
Date: Wed, 22 Aug 2007 03:05:42 +1200
-
+
Hi,
-
+
>As of now libgcrypt is GPL under Windows due to that module and some people
>would really like to see it under LGPL too. Can you do such a license change
>to LGPL version 2? Note that LGPL give the user the option to relicense it
>under GPL, so the change would be pretty easy and backwar compatible.
-
+
Sure. I assumed that since GPG was GPLd, you'd prefer the GPL for the entropy
code as well, but Ian asked for LGPL as an option so as of the next release
I'll have LGPL in there. You can consider it to be retroactive, so your
current version will be LGPLd as well.
-
+
Peter.
==========
From: pgut001 <pgut001@cs.auckland.ac.nz>
Subject: Re: LGPL for the windows entropy gatherer
To: wk@gnupg.org
Date: Wed, 22 Aug 2007 20:50:08 +1200
-
+
>Would you mind to extend this also to the Unix entropy gatherer which is
>still used on systems without /dev/random and when EGD is not installed? That
>would be the last GPLed piece in Libgcrypt.
-
+
Sure, it covers the entire entropy-gathering subsystem.
-
+
Peter.
=========
*/
@@ -207,7 +207,7 @@
* '1024 / SC_0' */
#define SC( weight ) ( 1024 / weight ) /* Scale factor */
-#define SC_0 16384 /* SC( SC_0 ) evalutes to 0 */
+#define SC_0 16384 /* SC( SC_0 ) evaluates to 0 */
static struct RI {
const char *path; /* Path to check for existence of source */
@@ -325,10 +325,10 @@ static struct RI {
/* This is a complex and screwball program. Some systems have things
* like rX_dmn, x = integer, for RAID systems, but the statistics are
* pretty dodgy */
-#ifdef __QNXNTO__
+#ifdef __QNXNTO__
{ "/bin/pidin", "-F%A%B%c%d%E%I%J%K%m%M%n%N%p%P%S%s%T", SC(0.3),
NULL, 0, 0, 0, 0 },
-#endif
+#endif
#if 0
/* The following aren't enabled since they're somewhat slow and not very
* unpredictable, however they give an indication of the sort of sources
@@ -521,7 +521,10 @@ slow_poll(FILE *dbgfp, int dbgall, size_t *nbytes )
int maxFD = 0;
#endif /* OS-specific brokenness */
int bufPos, i, usefulness = 0;
-
+ int last_so_far = 0;
+ int any_need_entropy = 0;
+ int delay;
+ int rc;
/* Fire up each randomness source */
FD_ZERO(&fds);
@@ -548,7 +551,8 @@ slow_poll(FILE *dbgfp, int dbgall, size_t *nbytes )
#else
#error O_NONBLOCK is missing
#endif
-
+ /* FIXME: We need to make sure that the fd is less than
+ FD_SETSIZE. */
FD_SET(dataSources[i].pipeFD, &fds);
dataSources[i].length = 0;
@@ -566,21 +570,40 @@ slow_poll(FILE *dbgfp, int dbgall, size_t *nbytes )
/* Suck all the data we can get from each of the sources */
bufPos = 0;
moreSources = 1;
+ delay = 0; /* Return immediately (well, after 100ms) the first time. */
while (moreSources && bufPos <= gather_buffer_size) {
/* Wait for data to become available from any of the sources, with a
* timeout of 10 seconds. This adds even more randomness since data
* becomes available in a nondeterministic fashion. Kudos to HP's QA
* department for managing to ship a select() which breaks its own
* prototype */
- tv.tv_sec = 10;
- tv.tv_usec = 0;
+ tv.tv_sec = delay;
+ tv.tv_usec = delay? 0 : 100000;
#if defined( __hpux ) && ( OS_VERSION == 9 )
- if (select(maxFD + 1, (int *)&fds, NULL, NULL, &tv) == -1)
+ rc = select(maxFD + 1, (int *)&fds, NULL, NULL, &tv);
#else /* */
- if (select(maxFD + 1, &fds, NULL, NULL, &tv) == -1)
+ rc = select(maxFD + 1, &fds, NULL, NULL, &tv);
#endif /* __hpux */
- break;
+ if (rc == -1)
+ break; /* Ooops; select failed. */
+
+ if (!rc)
+ {
+ /* FIXME: Because we run several tools at once it is
+ unlikely that we will see a block in select at all. */
+ if (!any_need_entropy
+ || last_so_far != (gather_buffer_size - bufPos) )
+ {
+ last_so_far = gather_buffer_size - bufPos;
+ _gcry_random_progress ("need_entropy", 'X',
+ last_so_far,
+ gather_buffer_size);
+ any_need_entropy = 1;
+ }
+ delay = 10; /* Use 10 seconds henceforth. */
+ /* Note that the fd_set is setup again at the end of this loop. */
+ }
/* One of the sources has data available, read it into the buffer */
for (i = 0; dataSources[i].path != NULL; i++) {
@@ -661,6 +684,11 @@ slow_poll(FILE *dbgfp, int dbgall, size_t *nbytes )
}
}
+ if (any_need_entropy)
+ _gcry_random_progress ("need_entropy", 'X',
+ gather_buffer_size,
+ gather_buffer_size);
+
if( dbgfp ) {
fprintf(dbgfp, "Got %d bytes, usefulness = %d\n", bufPos, usefulness);
fflush(dbgfp);