gen_uuid.c (get_random_bytes): Always xor in a stream of bytes
	from the system PRNG (i.e., random/srandom, seeded from
	the time, pid, and uid) in case /dev/random isn't doing
	the right thing on a particular system.  It doesn't hurt,
	and it can help, in the case of a buggy /dev/random.

diff --git a/lib/uuid/ChangeLog b/lib/uuid/ChangeLog
index 7a0ec9b..fca6088 100644
--- a/lib/uuid/ChangeLog
+++ b/lib/uuid/ChangeLog
@@ -1,3 +1,11 @@
+2003-04-03  Theodore Ts'o  <tytso@mit.edu>
+
+	* gen_uuid.c (get_random_bytes): Always xor in a stream of bytes
+		from the system PRNG (i.e., random/srandom, seeded from
+		the time, pid, and uid) in case /dev/random isn't doing
+		the right thing on a particular system.  It doesn't hurt,
+		and it can help, in the case of a buggy /dev/random.
+
 2003-03-14  Theodore Ts'o  <tytso@mit.edu>
 
 	* Makefile.in: Add support for Apple Darwin
diff --git a/lib/uuid/gen_uuid.c b/lib/uuid/gen_uuid.c
index 5ebc673..158b6bd 100644
--- a/lib/uuid/gen_uuid.c
+++ b/lib/uuid/gen_uuid.c
@@ -74,27 +74,30 @@
  */
 static void get_random_bytes(void *buf, int nbytes)
 {
-	int i, fd = get_random_fd();
+	int i, n = nbytes, fd = get_random_fd();
 	int lose_counter = 0;
-	char *cp = (char *) buf;
+	unsigned char *cp = (unsigned char *) buf;
 
 	if (fd >= 0) {
-		while (nbytes > 0) {
-			i = read(fd, cp, nbytes);
+		while (n > 0) {
+			i = read(fd, cp, n);
 			if (i <= 0) {
 				if (lose_counter++ > 16)
 					break;
 				continue;
 			}
-			nbytes -= i;
+			n -= i;
 			cp += i;
 			lose_counter = 0;
 		}
 	}
-
-	/* XXX put something better here if no /dev/random! */
-	for (i = 0; i < nbytes; i++)
-		*cp++ = rand() & 0xFF;
+	
+	/*
+	 * We do this all the time, but this is the only source of
+	 * randomness if /dev/random/urandom is out to lunch.
+	 */
+	for (cp = buf, i = 0; i < nbytes; i++)
+		*cp++ ^= (rand() >> 7) & 0xFF;
 	return;
 }