# HG changeset patch # User Matt Johnston # Date 1361586469 -28800 # Node ID c85bb68e1db6bc0ec8e3bee457eee1d85eb67d13 # Parent c58a1598380822f43b46b1ebcddf6bc48fc571b2 add loadavg and entropy_avail as sources diff -r c58a15983808 -r c85bb68e1db6 random.c --- a/random.c Tue Feb 12 15:52:57 2013 +0000 +++ b/random.c Sat Feb 23 10:27:49 2013 +0800 @@ -73,10 +73,10 @@ } 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 @@ } } - 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 @@ } #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 @@ /* 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);