X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=crypto%2Frand%2Frand_unix.c;h=e9ead3a529688fd2c49a95b6871240d24ac6d70d;hb=7cc684f4f7fbcdc5cf4683eaf025d4f915acbf3c;hp=e9cba6479d1f81954863980242c3632eace6df52;hpb=5e4430e70df0020f5f1517249851696cb9ac4ad2;p=oweals%2Fopenssl.git diff --git a/crypto/rand/rand_unix.c b/crypto/rand/rand_unix.c index e9cba6479d..e9ead3a529 100644 --- a/crypto/rand/rand_unix.c +++ b/crypto/rand/rand_unix.c @@ -133,7 +133,50 @@ # define FD_SETSIZE (8*sizeof(fd_set)) #endif -#ifdef __OpenBSD__ +#ifdef __VOS__ +int RAND_poll(void) +{ + unsigned char buf[ENTROPY_NEEDED]; + pid_t curr_pid; + uid_t curr_uid; + static int first=1; + int i; + long rnd = 0; + struct timespec ts; + unsigned seed; + +/* The VOS random() function starts from a static seed so its + initial value is predictable. If random() returns the + initial value, reseed it with dynamic data. The VOS + real-time clock has a granularity of 1 nsec so it should be + reasonably difficult to predict its exact value. Do not + gratuitously reseed the PRNG because other code in this + process or thread may be using it. */ + + if (first) { + first = 0; + rnd = random (); + if (rnd == 1804289383) { + clock_gettime (CLOCK_REALTIME, &ts); + curr_pid = getpid(); + curr_uid = getuid(); + seed = ts.tv_sec ^ ts.tv_nsec ^ curr_pid ^ curr_uid; + srandom (seed); + } + } + + for (i = 0; i < sizeof(buf); i++) { + if (i % 4 == 0) + rnd = random(); + buf[i] = rnd; + rnd >>= 8; + } + RAND_add(buf, sizeof(buf), ENTROPY_NEEDED); + memset(buf, 0, sizeof(buf)); + + return 1; +} +#elif defined __OpenBSD__ int RAND_poll(void) { u_int32_t rnd = 0, i; @@ -157,7 +200,7 @@ int RAND_poll(void) pid_t curr_pid = getpid(); #if defined(DEVRANDOM) || defined(DEVRANDOM_EGD) unsigned char tmpbuf[ENTROPY_NEEDED]; - size_t n = 0; + int n = 0; #endif #ifdef DEVRANDOM static const char *randomfiles[] = { DEVRANDOM }; @@ -238,7 +281,7 @@ int RAND_poll(void) t.tv_sec = 0; t.tv_usec = usec; - if (FD_SETSIZE > 0 && fd >= FD_SETSIZE) + if (FD_SETSIZE > 0 && (unsigned)fd >= FD_SETSIZE) { /* can't use select, so just try to read once anyway */ try_read = 1; @@ -261,7 +304,7 @@ int RAND_poll(void) if (try_read) { - r = read(fd,tmpbuf+n,ENTROPY_NEEDED-n); + r = read(fd,(unsigned char *)tmpbuf+n, ENTROPY_NEEDED-n); if (r > 0) n += r; #if defined(OPENSSL_SYS_BEOS_R5)