comparison random.c @ 185:5ccad7634388

* warn if we seem to be blocking on /dev/random
author Matt Johnston <matt@ucc.asn.au>
date Sun, 24 Apr 2005 15:56:36 +0000
parents 4bd4fc8023bd
children 06e326daf16a
comparison
equal deleted inserted replaced
184:ca55377e4f7e 185:5ccad7634388
48 * 48 *
49 */ 49 */
50 50
51 static void readrand(unsigned char* buf, unsigned int buflen) { 51 static void readrand(unsigned char* buf, unsigned int buflen) {
52 52
53 static int already_blocked = 0;
53 int readfd; 54 int readfd;
54 unsigned int readpos; 55 unsigned int readpos;
55 int readlen; 56 int readlen;
56 #ifdef DROPBEAR_PRNGD_SOCKET 57 #ifdef DROPBEAR_PRNGD_SOCKET
57 struct sockaddr_un egdsock; 58 struct sockaddr_un egdsock;
90 #endif 91 #endif
91 92
92 /* read the actual random data */ 93 /* read the actual random data */
93 readpos = 0; 94 readpos = 0;
94 do { 95 do {
96 if (!already_blocked)
97 {
98 int ret;
99 struct timeval timeout;
100 fd_set read_fds;
101
102 timeout.tv_sec = 2; /* two seconds should be enough */
103 timeout.tv_usec = 0;
104
105 FD_ZERO(&read_fds);
106 FD_SET(readfd, &read_fds);
107 ret = select(readfd + 1, &read_fds, NULL, NULL, &timeout);
108 if (ret == 0)
109 {
110 dropbear_log(LOG_INFO, "Warning: Reading the random source seems to have blocked.\nIf you experience problems, you probably need to find a better entropy source.");
111 already_blocked = 1;
112 }
113 }
95 readlen = read(readfd, &buf[readpos], buflen - readpos); 114 readlen = read(readfd, &buf[readpos], buflen - readpos);
96 if (readlen <= 0) { 115 if (readlen <= 0) {
97 if (readlen < 0 && errno == EINTR) { 116 if (readlen < 0 && errno == EINTR) {
98 continue; 117 continue;
99 } 118 }