diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2013-10-16 15:27:55 +0200 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2013-10-20 23:07:36 +0200 |
commit | c051e521a7a390a9d61cdb3ae89b3fd69a96e724 (patch) | |
tree | 101a48b1ed5d7b55fd89fc6eb7917872fbc13250 /crypto/rand/md_rand.c | |
parent | Prevent use of RSA+MD5 in TLS 1.2 by default. (diff) | |
download | openssl-c051e521a7a390a9d61cdb3ae89b3fd69a96e724.tar.xz openssl-c051e521a7a390a9d61cdb3ae89b3fd69a96e724.zip |
Time value for various platforms.
The function gettimeofday() is not supported on all platforms. Use
more portable versions. Adapted from FIPS code.
Diffstat (limited to 'crypto/rand/md_rand.c')
-rw-r--r-- | crypto/rand/md_rand.c | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/crypto/rand/md_rand.c b/crypto/rand/md_rand.c index d479aa8a76..2d6a55f6ed 100644 --- a/crypto/rand/md_rand.c +++ b/crypto/rand/md_rand.c @@ -120,10 +120,16 @@ #include <assert.h> #include <stdio.h> #include <string.h> -#include <sys/time.h> #include "e_os.h" +#if !(defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYSNAME_DSPBIOS)) +# include <sys/time.h> +#endif +#if defined(OPENSSL_SYS_VXWORKS) +# include <time.h> +#endif + #include <openssl/crypto.h> #include <openssl/rand.h> #include "rand_lcl.h" @@ -361,10 +367,27 @@ static int ssleay_rand_bytes(unsigned char *buf, int num, int pseudo) pid_t curr_pid = getpid(); #endif time_t curr_time = time(NULL); - struct timeval tv; int do_stir_pool = 0; - +/* time value for various platforms */ +#ifdef OPENSSL_SYS_WIN32 + FILETIME tv; +# ifdef _WIN32_WCE + SYSTEMTIME t; + GetSystemTime(&t); + SystemTimeToFileTime(&t, &tv); +# else + GetSystemTimeAsFileTime(&tv); +# endif +#elif defined(OPENSSL_SYS_VXWORKS) + struct timespec tv; + clock_gettime(CLOCK_REALTIME, &ts); +#elif defined(OPENSSL_SYSNAME_DSPBIOS) + unsigned long long tv, OPENSSL_rdtsc(); + tv = OPENSSL_rdtsc(); +#else + struct timeval tv; gettimeofday(&tv, NULL); +#endif #ifdef PREDICT if (rand_predictable) @@ -504,14 +527,10 @@ static int ssleay_rand_bytes(unsigned char *buf, int num, int pseudo) if (!MD_Update(&m,(unsigned char*)&curr_time, sizeof curr_time)) goto err; - curr_time = 0; - } - if (tv.tv_sec) /* just in the first iteration to save time */ - { if (!MD_Update(&m,(unsigned char*)&tv, sizeof tv)) goto err; - tv.tv_sec = 0; + curr_time = 0; } if (!MD_Update(&m,local_md,MD_DIGEST_LENGTH)) goto err; |