Since some systems (at least Windows) does not have
/dev/random nor friends, we need another random-source.
This patch uses the C-runtime's rand()-function as a
poor-mans random-source.
Signed-off-by: Erik Faye-Lund <redacted>
---
imap-send.c | 17 ++++++++++-------
1 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/imap-send.c b/imap-send.c
index 8338717..dda7b7f 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -511,14 +511,17 @@ static void arc4_init(void)
unsigned char j, si, dat[128];
if ((fd = open("/dev/urandom", O_RDONLY)) < 0 && (fd = open("/dev/random", O_RDONLY)) < 0) {
- fprintf(stderr, "Fatal: no random number source available.\n");
- exit(3);
- }
- if (read_in_full(fd, dat, 128) != 128) {
- fprintf(stderr, "Fatal: cannot read random number source.\n");
- exit(3);
+ /* poor-mans random-source */
+ srand(clock());
+ for (i = 0; i < 128; ++i)
+ dat[i] = rand() & 0xFF;
+ } else {
+ if (read_in_full(fd, dat, 128) != 128) {
+ fprintf(stderr, "Fatal: cannot read random number source.\n");
+ exit(3);
+ }
+ close(fd);
}
- close(fd);
for (i = 0; i < 256; i++)
rs.s[i] = i;--
1.6.5.rc2.7.g4f8d3