summaryrefslogtreecommitdiffstats
path: root/lib/libcrypto/rand/rand_unix.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libcrypto/rand/rand_unix.c')
-rw-r--r--lib/libcrypto/rand/rand_unix.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/libcrypto/rand/rand_unix.c b/lib/libcrypto/rand/rand_unix.c
index ec09d74603c..a7f66c6dfe9 100644
--- a/lib/libcrypto/rand/rand_unix.c
+++ b/lib/libcrypto/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