crypto/rand/rand_lib.c: fix undefined reference to `clock_gettime'
authorDr. Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Tue, 30 Jan 2018 22:53:57 +0000 (23:53 +0100)
committerDr. Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Wed, 31 Jan 2018 16:16:40 +0000 (17:16 +0100)
Some older glibc versions require the `-lrt` linker option for
resolving the reference to `clock_gettime'. Since it is not desired
to add new library dependencies in version 1.1.1, the call to
clock_gettime() is replaced by a call to gettimeofday() for the
moment. It will be added back in version 1.2.

Signed-off-by: Dr. Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/5199)

crypto/rand/rand_lib.c

index 3824d93317bf6fda4d44937e2ce69ff919e08910..ab033566461ec76caf5aa285b79b07efa08b5ada 100644 (file)
@@ -210,13 +210,15 @@ size_t rand_drbg_get_additional_data(unsigned char **pout, size_t max_len)
     size_t len;
 #ifdef OPENSSL_SYS_UNIX
     pid_t pid;
     size_t len;
 #ifdef OPENSSL_SYS_UNIX
     pid_t pid;
-    struct timespec ts;
+    struct timeval tv;
 #elif defined(OPENSSL_SYS_WIN32)
     DWORD pid;
     FILETIME ft;
     LARGE_INTEGER pc;
 #endif
 #elif defined(OPENSSL_SYS_WIN32)
     DWORD pid;
     FILETIME ft;
     LARGE_INTEGER pc;
 #endif
+#ifdef OPENSSL_CPUID_OBJ
     uint32_t tsc = 0;
     uint32_t tsc = 0;
+#endif
 
     pool = RAND_POOL_new(0, 0, max_len);
     if (pool == NULL)
 
     pool = RAND_POOL_new(0, 0, max_len);
     if (pool == NULL)
@@ -241,12 +243,10 @@ size_t rand_drbg_get_additional_data(unsigned char **pout, size_t max_len)
 #endif
 
 #ifdef OPENSSL_SYS_UNIX
 #endif
 
 #ifdef OPENSSL_SYS_UNIX
-    if (tsc == 0 && clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
-        RAND_POOL_add(pool, (unsigned char *)&ts, sizeof(ts), 0);
-    if (clock_gettime(CLOCK_REALTIME, &ts) == 0)
-        RAND_POOL_add(pool, (unsigned char *)&ts, sizeof(ts), 0);
+    if (gettimeofday(&tv, NULL) == 0)
+        RAND_POOL_add(pool, (unsigned char *)&tv, sizeof(tv), 0);
 #elif defined(OPENSSL_SYS_WIN32)
 #elif defined(OPENSSL_SYS_WIN32)
-    if (tsc == 0 && QueryPerformanceCounter(&pc) != 0)
+    if (QueryPerformanceCounter(&pc) != 0)
         RAND_POOL_add(pool, (unsigned char *)&pc, sizeof(pc), 0);
     GetSystemTimeAsFileTime(&ft);
     RAND_POOL_add(pool, (unsigned char *)&ft, sizeof(ft), 0);
         RAND_POOL_add(pool, (unsigned char *)&pc, sizeof(pc), 0);
     GetSystemTimeAsFileTime(&ft);
     RAND_POOL_add(pool, (unsigned char *)&ft, sizeof(ft), 0);