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