comparison random.c @ 641:2b1bb792cd4d dropbear-tfm

- Update tfm changes to current default tip
author Matt Johnston <matt@ucc.asn.au>
date Mon, 21 Nov 2011 19:52:28 +0800
parents 76097ec1a29a 2d896267f16d
children
comparison
equal deleted inserted replaced
640:76097ec1a29a 641:2b1bb792cd4d
62 #endif 62 #endif
63 63
64 #ifdef DROPBEAR_RANDOM_DEV 64 #ifdef DROPBEAR_RANDOM_DEV
65 readfd = open(DROPBEAR_RANDOM_DEV, O_RDONLY); 65 readfd = open(DROPBEAR_RANDOM_DEV, O_RDONLY);
66 if (readfd < 0) { 66 if (readfd < 0) {
67 dropbear_exit("couldn't open random device"); 67 dropbear_exit("Couldn't open random device");
68 } 68 }
69 #endif 69 #endif
70 70
71 #ifdef DROPBEAR_PRNGD_SOCKET 71 #ifdef DROPBEAR_PRNGD_SOCKET
72 memset((void*)&egdsock, 0x0, sizeof(egdsock)); 72 readfd = connect_unix(DROPBEAR_PRNGD_SOCKET);
73 egdsock.sun_family = AF_UNIX; 73
74 strlcpy(egdsock.sun_path, DROPBEAR_PRNGD_SOCKET,
75 sizeof(egdsock.sun_path));
76
77 readfd = socket(PF_UNIX, SOCK_STREAM, 0);
78 if (readfd < 0) { 74 if (readfd < 0) {
79 dropbear_exit("couldn't open random device"); 75 dropbear_exit("Couldn't open random device");
80 }
81 /* todo - try various common locations */
82 if (connect(readfd, (struct sockaddr*)&egdsock,
83 sizeof(struct sockaddr_un)) < 0) {
84 dropbear_exit("couldn't open random device");
85 } 76 }
86 77
87 if (buflen > 255) 78 if (buflen > 255)
88 dropbear_exit("can't request more than 255 bytes from egd"); 79 dropbear_exit("Can't request more than 255 bytes from egd");
89 egdcmd[0] = 0x02; /* blocking read */ 80 egdcmd[0] = 0x02; /* blocking read */
90 egdcmd[1] = (unsigned char)buflen; 81 egdcmd[1] = (unsigned char)buflen;
91 if (write(readfd, egdcmd, 2) < 0) 82 if (write(readfd, egdcmd, 2) < 0)
92 dropbear_exit("can't send command to egd"); 83 dropbear_exit("Can't send command to egd");
93 #endif 84 #endif
94 85
95 /* read the actual random data */ 86 /* read the actual random data */
96 readpos = 0; 87 readpos = 0;
97 do { 88 do {
116 readlen = read(readfd, &buf[readpos], buflen - readpos); 107 readlen = read(readfd, &buf[readpos], buflen - readpos);
117 if (readlen <= 0) { 108 if (readlen <= 0) {
118 if (readlen < 0 && errno == EINTR) { 109 if (readlen < 0 && errno == EINTR) {
119 continue; 110 continue;
120 } 111 }
121 dropbear_exit("error reading random source"); 112 dropbear_exit("Error reading random source");
122 } 113 }
123 readpos += readlen; 114 readpos += readlen;
124 } while (readpos < buflen); 115 } while (readpos < buflen);
125 116
126 close (readfd); 117 close (readfd);