summaryrefslogtreecommitdiff
path: root/helper.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>1999-11-11 10:40:23 +1100
committerDamien Miller <djm@mindrot.org>1999-11-11 10:40:23 +1100
commitab18c412e6773b34e4640e4b9277573fd91a66bf (patch)
treef0ab48cd9e112a4d866785d2a5b64eda39986b4e /helper.c
parentb77870fa7341d95024e55a116a3454e9bfe2f21e (diff)
- Added (untested) Entropy Gathering Daemon (EGD) support
- Merged several minor fixed: - ssh-agent commandline parsing - RPM spec file now installs ssh setuid root - Makefile creates libdir - Merged beginnings of Solaris compability from Marc G. Fournier <marc.fournier@acadiau.ca>
Diffstat (limited to 'helper.c')
-rw-r--r--helper.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/helper.c b/helper.c
index 6959535d2..6d77759de 100644
--- a/helper.c
+++ b/helper.c
@@ -45,6 +45,7 @@
45 45
46#include "rc4.h" 46#include "rc4.h"
47#include "xmalloc.h" 47#include "xmalloc.h"
48#include "ssh.h"
48#include "config.h" 49#include "config.h"
49#include "helper.h" 50#include "helper.h"
50 51
@@ -79,28 +80,35 @@ void arc4random_stir(void)
79 80
80void get_random_bytes(unsigned char *buf, int len) 81void get_random_bytes(unsigned char *buf, int len)
81{ 82{
82 int urandom; 83 int random_pool;
83 int c; 84 int c;
85#ifdef HAVE_EGD
86 char egd_message[2] = { 0x02, 0x00 };
87#endif /* HAVE_EGD */
84 88
85 urandom = open("/dev/urandom", O_RDONLY); 89 random_pool = open(RANDOM_POOL, O_RDONLY);
86 if (urandom == -1) 90 if (random_pool == -1)
87 { 91 fatal("Couldn't open random pool \"%s\": %s", RANDOM_POOL, strerror(errno));
88 fprintf(stderr, "Couldn't open /dev/urandom: %s", strerror(errno));
89 exit(1);
90 }
91 92
92 c = read(urandom, buf, len); 93#ifdef HAVE_EGD
94 if (len > 255)
95 fatal("Too many bytes to read from EGD");
96
97 /* Send blocking read request to EGD */
98 egd_message[1] = len;
99 c = write(random_pool, egd_message, sizeof(egd_message));
100 if (c == -1)
101 fatal("Couldn't write to EGD socket \"%s\": %s", RANDOM_POOL, strerror(errno));
102#endif /* HAVE_EGD */
103
104 c = read(random_pool, buf, len);
93 if (c == -1) 105 if (c == -1)
94 { 106 fatal("Couldn't read from random pool \"%s\": %s", RANDOM_POOL, strerror(errno));
95 fprintf(stderr, "Couldn't read from /dev/urandom: %s", strerror(errno));
96 exit(1);
97 }
98 107
99 if (c != len) 108 if (c != len)
100 { 109 fatal("Short read from random pool \"%s\"", RANDOM_POOL);
101 fprintf(stderr, "Short read from /dev/urandom"); 110
102 exit(1); 111 close(random_pool);
103 }
104} 112}
105#endif /* !HAVE_ARC4RANDOM */ 113#endif /* !HAVE_ARC4RANDOM */
106 114