comparison random.c @ 189:06e326daf16a

merge of 6b56bdff53b47ae7366d93b496ce353d9e3753dc and b68c53583ba80ad14fd0ba70ff26ea3dbd8e8823
author Matt Johnston <matt@ucc.asn.au>
date Thu, 05 May 2005 04:00:10 +0000
parents c9483550701b 5ccad7634388
children 65585699d980
comparison
equal deleted inserted replaced
188:c9483550701b 189:06e326daf16a
49 * 49 *
50 */ 50 */
51 51
52 static void readrand(unsigned char* buf, unsigned int buflen) { 52 static void readrand(unsigned char* buf, unsigned int buflen) {
53 53
54 static int already_blocked = 0;
54 int readfd; 55 int readfd;
55 unsigned int readpos; 56 unsigned int readpos;
56 int readlen; 57 int readlen;
57 #ifdef DROPBEAR_PRNGD_SOCKET 58 #ifdef DROPBEAR_PRNGD_SOCKET
58 struct sockaddr_un egdsock; 59 struct sockaddr_un egdsock;
91 #endif 92 #endif
92 93
93 /* read the actual random data */ 94 /* read the actual random data */
94 readpos = 0; 95 readpos = 0;
95 do { 96 do {
97 if (!already_blocked)
98 {
99 int ret;
100 struct timeval timeout;
101 fd_set read_fds;
102
103 timeout.tv_sec = 2; /* two seconds should be enough */
104 timeout.tv_usec = 0;
105
106 FD_ZERO(&read_fds);
107 FD_SET(readfd, &read_fds);
108 ret = select(readfd + 1, &read_fds, NULL, NULL, &timeout);
109 if (ret == 0)
110 {
111 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.");
112 already_blocked = 1;
113 }
114 }
96 readlen = read(readfd, &buf[readpos], buflen - readpos); 115 readlen = read(readfd, &buf[readpos], buflen - readpos);
97 if (readlen <= 0) { 116 if (readlen <= 0) {
98 if (readlen < 0 && errno == EINTR) { 117 if (readlen < 0 && errno == EINTR) {
99 continue; 118 continue;
100 } 119 }