diff options
author | 2002-09-10 16:31:53 +0000 | |
---|---|---|
committer | 2002-09-10 16:31:53 +0000 | |
commit | 1f9308f95cf5f2eb77b454500c9bb49d76673ef3 (patch) | |
tree | c6825952eba2bd0bea9ff46656b25ab7eea8284b /lib/libssl/src/crypto/rand/rand_unix.c | |
parent | Update list of supported CMD and Promise devices. (diff) | |
download | wireguard-openbsd-1f9308f95cf5f2eb77b454500c9bb49d76673ef3.tar.xz wireguard-openbsd-1f9308f95cf5f2eb77b454500c9bb49d76673ef3.zip |
merge openssl-0.9.7-beta3, tested on vax by miod@
Diffstat (limited to 'lib/libssl/src/crypto/rand/rand_unix.c')
-rw-r--r-- | lib/libssl/src/crypto/rand/rand_unix.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/libssl/src/crypto/rand/rand_unix.c b/lib/libssl/src/crypto/rand/rand_unix.c index ec09d74603c..a7f66c6dfe9 100644 --- a/lib/libssl/src/crypto/rand/rand_unix.c +++ b/lib/libssl/src/crypto/rand/rand_unix.c @@ -124,6 +124,43 @@ #include <unistd.h> #include <time.h> +#ifdef __OpenBSD__ +#undef DEVRANDOM +#define DEVRANDOM "/dev/arandom" +int RAND_poll(void) +{ + unsigned long l; + pid_t curr_pid = getpid(); + FILE *fh; + + /* Use a random entropy pool device. Linux, FreeBSD and OpenBSD + * have this. Use /dev/urandom if you can as /dev/random may block + * if it runs out of random entries. */ + + if ((fh = fopen(DEVRANDOM, "r")) != NULL) + { + unsigned char tmpbuf[ENTROPY_NEEDED]; + int n; + + setvbuf(fh, NULL, _IONBF, 0); + n=fread((unsigned char *)tmpbuf,1,ENTROPY_NEEDED,fh); + fclose(fh); + RAND_add(tmpbuf,sizeof tmpbuf,n); + memset(tmpbuf,0,n); + } + + /* put in some default random data, we need more than just this */ + l=curr_pid; + RAND_add(&l,sizeof(l),0); + l=getuid(); + RAND_add(&l,sizeof(l),0); + + l=time(NULL); + RAND_add(&l,sizeof(l),0); + + return 1; +} +#else int RAND_poll(void) { unsigned long l; @@ -236,3 +273,4 @@ int RAND_poll(void) } #endif +#endif |