summaryrefslogtreecommitdiff
path: root/bsd-misc.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2000-01-29 20:40:22 +1100
committerDamien Miller <djm@mindrot.org>2000-01-29 20:40:22 +1100
commitf07390e90da683fecbf55849a3cee6dc9b79a3e3 (patch)
treec9c7ad28557e08ff024da1e9a5302fc78d4de4f7 /bsd-misc.c
parent4e61b79d5bcb3c5ac3014fe55be55214e23b2927 (diff)
- Seed OpenSSL's random number generator before generating RSA keypairs
- Split random collector into seperate file
Diffstat (limited to 'bsd-misc.c')
-rw-r--r--bsd-misc.c62
1 files changed, 2 insertions, 60 deletions
diff --git a/bsd-misc.c b/bsd-misc.c
index b00c793c..99fe2981 100644
--- a/bsd-misc.c
+++ b/bsd-misc.c
@@ -44,8 +44,6 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include <sys/socket.h>
-#include <sys/un.h>
#include <fcntl.h>
#ifdef HAVE_STDDEF_H
#include <stddef.h>
@@ -54,10 +52,7 @@
#include "xmalloc.h"
#include "ssh.h"
#include "bsd-misc.h"
-
-#ifndef offsetof
-#define offsetof(type, member) ((size_t) &((type *)0)->member)
-#endif
+#include "random.h"
#ifndef HAVE_ARC4RANDOM
@@ -68,7 +63,6 @@ typedef struct
int j;
} rc4_t;
-void get_random_bytes(unsigned char *buf, int len);
void rc4_key(rc4_t *r, unsigned char *key, int len);
void rc4_getbytes(rc4_t *r, unsigned char *buffer, int len);
@@ -134,59 +128,7 @@ void arc4random_stir(void)
get_random_bytes(rand_buf, sizeof(rand_buf));
rc4_key(rc4, rand_buf, sizeof(rand_buf));
-}
-
-void get_random_bytes(unsigned char *buf, int len)
-{
- static int random_pool;
- int c;
-#ifdef HAVE_EGD
- char egd_message[2] = { 0x02, 0x00 };
- struct sockaddr_un addr;
- int addr_len;
-
- memset(&addr, '\0', sizeof(addr));
- addr.sun_family = AF_UNIX;
-
- /* FIXME: compile time check? */
- if (sizeof(RANDOM_POOL) > sizeof(addr.sun_path))
- fatal("Random pool path is too long");
-
- strcpy(addr.sun_path, RANDOM_POOL);
-
- addr_len = offsetof(struct sockaddr_un, sun_path) + sizeof(RANDOM_POOL);
-
- random_pool = socket(AF_UNIX, SOCK_STREAM, 0);
-
- if (random_pool == -1)
- fatal("Couldn't create AF_UNIX socket: %s", strerror(errno));
-
- if (connect(random_pool, (struct sockaddr*)&addr, addr_len) == -1)
- fatal("Couldn't connect to EGD socket \"%s\": %s", addr.sun_path, strerror(errno));
-
- if (len > 255)
- fatal("Too many bytes to read from EGD");
-
- /* Send blocking read request to EGD */
- egd_message[1] = len;
-
- c = atomicio(write, random_pool, egd_message, sizeof(egd_message));
- if (c == -1)
- fatal("Couldn't write to EGD socket \"%s\": %s", RANDOM_POOL, strerror(errno));
-
-#else /* HAVE_EGD */
-
- random_pool = open(RANDOM_POOL, O_RDONLY);
- if (random_pool == -1)
- fatal("Couldn't open random pool \"%s\": %s", RANDOM_POOL, strerror(errno));
-
-#endif /* HAVE_EGD */
-
- c = atomicio(read, random_pool, buf, len);
- if (c <= 0)
- fatal("Couldn't read from random pool \"%s\": %s", RANDOM_POOL, strerror(errno));
-
- close(random_pool);
+ memset(rand_buf, 0, sizeof(rand_buf));
}
#endif /* !HAVE_ARC4RANDOM */