summaryrefslogtreecommitdiffhomepage
path: root/random.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2013-02-23 10:27:49 +0800
committerMatt Johnston <matt@ucc.asn.au>2013-02-23 10:27:49 +0800
commit26b07ccafc7826fc14c3864ff43bd144fb650002 (patch)
tree8ca54b26b752685546c0ffdcbfcd0cb19f5584b4 /random.c
parent1205fa68dfcd5da94d562df885b9808273e8b909 (diff)
add loadavg and entropy_avail as sources
Diffstat (limited to 'random.c')
-rw-r--r--random.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/random.c b/random.c
index c97e712..1e59e8e 100644
--- a/random.c
+++ b/random.c
@@ -73,10 +73,10 @@ process_file(hash_state *hs, const char *filename,
}
readcount = 0;
- while (readcount < len)
+ while (len == 0 || readcount < len)
{
int readlen, wantread;
- unsigned char readbuf[128];
+ unsigned char readbuf[2048];
if (!already_blocked)
{
int ret;
@@ -93,7 +93,14 @@ process_file(hash_state *hs, const char *filename,
}
}
- wantread = MIN(sizeof(readbuf), len-readcount);
+ if (len == 0)
+ {
+ wantread = sizeof(readbuf);
+ }
+ else
+ {
+ wantread = MIN(sizeof(readbuf), len-readcount);
+ }
#ifdef DROPBEAR_PRNGD_SOCKET
if (prngd)
@@ -185,7 +192,8 @@ void seedrandom() {
}
#endif
- /* A few other sources to fall back on. Add more here for other platforms */
+ /* A few other sources to fall back on.
+ * Add more here for other platforms */
#ifdef __linux__
/* Seems to be a reasonable source of entropy from timers. Possibly hard
* for even local attackers to reproduce */
@@ -193,6 +201,9 @@ void seedrandom() {
/* Might help on systems with wireless */
process_file(&hs, "/proc/interrupts", 0, 0);
+ process_file(&hs, "/proc/loadavg", 0, 0);
+ process_file(&hs, "/proc/sys/kernel/random/entropy_avail", 0, 0);
+
/* Mostly network visible but useful in some situations */
process_file(&hs, "/proc/net/netstat", 0, 0);
process_file(&hs, "/proc/net/dev", 0, 0);