summaryrefslogtreecommitdiff
path: root/crypto/rand/rand_unix.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/rand/rand_unix.c')
-rw-r--r--crypto/rand/rand_unix.c41
1 files changed, 38 insertions, 3 deletions
diff --git a/crypto/rand/rand_unix.c b/crypto/rand/rand_unix.c
index 71b98ec21..41259f369 100644
--- a/crypto/rand/rand_unix.c
+++ b/crypto/rand/rand_unix.c
@@ -232,7 +232,7 @@ int RAND_poll(void)
t.tv_sec = 0;
t.tv_usec = usec;
- if (FD_SETSIZE > 0 && (unsigned)fd >= FD_SETSIZE)
+ if (FD_SETSIZE > 0 && fd >= FD_SETSIZE)
{
/* can't use select, so just try to read once anyway */
try_read = 1;
@@ -323,8 +323,43 @@ int RAND_poll(void)
#if defined(OPENSSL_SYS_VXWORKS)
+/* Note: the existence of /dev/urandom on VxWorks platforms is uncommon
+* however we check for one and use it if found for those cases where
+* it is present. */
int RAND_poll(void)
- {
+{
+ unsigned long l;
+#ifdef DEVRANDOM
+ unsigned char buf[ENTROPY_NEEDED];
+ int n = 0, r, fd;
+
+ if ((fd = open("/dev/urandom", O_RDONLY, 0)) >= 0)
+ {
+ do
+ {
+ r = read(fd,(unsigned char *)buf+n, ENTROPY_NEEDED-n);
+ if (r > 0)
+ n += r;
+ }
+ while ((r > 0 || errno == EINTR) && n < ENTROPY_NEEDED);
+
+ close(fd);
+ }
+
+ if (n > 0)
+ {
+ RAND_add(buf,sizeof buf,(double)n);
+ OPENSSL_cleanse(buf,n);
+ }
+#endif
+
+ l=time(NULL);
+ RAND_add(&l,sizeof(l),0.0);
+
+#if defined(DEVRANDOM)
+ return 1;
+#else
return 0;
- }
+#endif
+}
#endif