summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/rand/rand_unix.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/rand/rand_unix.c')
-rw-r--r--src/lib/libcrypto/rand/rand_unix.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/src/lib/libcrypto/rand/rand_unix.c b/src/lib/libcrypto/rand/rand_unix.c
index ec09d74603..0b29235130 100644
--- a/src/lib/libcrypto/rand/rand_unix.c
+++ b/src/lib/libcrypto/rand/rand_unix.c
@@ -109,8 +109,6 @@
109 * 109 *
110 */ 110 */
111 111
112#define USE_SOCKETS
113#include "e_os.h"
114#include "cryptlib.h" 112#include "cryptlib.h"
115#include <openssl/rand.h> 113#include <openssl/rand.h>
116#include "rand_lcl.h" 114#include "rand_lcl.h"
@@ -124,6 +122,43 @@
124#include <unistd.h> 122#include <unistd.h>
125#include <time.h> 123#include <time.h>
126 124
125#ifdef __OpenBSD__
126#undef DEVRANDOM
127#define DEVRANDOM "/dev/arandom"
128int RAND_poll(void)
129{
130 unsigned long l;
131 pid_t curr_pid = getpid();
132 FILE *fh;
133
134 /* Use a random entropy pool device. Linux, FreeBSD and OpenBSD
135 * have this. Use /dev/urandom if you can as /dev/random may block
136 * if it runs out of random entries. */
137
138 if ((fh = fopen(DEVRANDOM, "r")) != NULL)
139 {
140 unsigned char tmpbuf[ENTROPY_NEEDED];
141 int n;
142
143 setvbuf(fh, NULL, _IONBF, 0);
144 n=fread((unsigned char *)tmpbuf,1,ENTROPY_NEEDED,fh);
145 fclose(fh);
146 RAND_add(tmpbuf,sizeof tmpbuf,n);
147 memset(tmpbuf,0,n);
148 }
149
150 /* put in some default random data, we need more than just this */
151 l=curr_pid;
152 RAND_add(&l,sizeof(l),0);
153 l=getuid();
154 RAND_add(&l,sizeof(l),0);
155
156 l=time(NULL);
157 RAND_add(&l,sizeof(l),0);
158
159 return 1;
160}
161#else
127int RAND_poll(void) 162int RAND_poll(void)
128{ 163{
129 unsigned long l; 164 unsigned long l;
@@ -236,3 +271,4 @@ int RAND_poll(void)
236} 271}
237 272
238#endif 273#endif
274#endif