[openssl-commits] [openssl] master update
paul.dale at oracle.com
paul.dale at oracle.com
Wed Feb 7 00:09:48 UTC 2018
The branch master has been updated
via 2b66fd5720c38c6e89f9cd00d36d2c828ed4cd4b (commit)
via 360fc9f412f1f60a4644228d9b6d386161aad406 (commit)
via 2ad2281a8005dbc9046059693995c78a04ed9e37 (commit)
from 7ff3a3b9e98104e3d080e652712c42b0dff915dd (commit)
- Log -----------------------------------------------------------------
commit 2b66fd5720c38c6e89f9cd00d36d2c828ed4cd4b
Author: Pauli <paul.dale at oracle.com>
Date: Tue Feb 6 07:17:31 2018 +1000
Unify timer code
Remove the timer and TSC additional input code and instead provide a single
routine that attempts to use the "best" timer/counter available on the
system. It attempts to use TSC, then various OS dependent resources and
finally several tries to obtain the date. If any of these timer/counters
is successful, the rest are skipped.
No randomness is credited for this.
Reviewed-by: Richard Levitte <levitte at openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre at ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/5231)
commit 360fc9f412f1f60a4644228d9b6d386161aad406
Author: Pauli <paul.dale at oracle.com>
Date: Tue Feb 6 07:16:26 2018 +1000
Make OPENSSL_rdtsc universally available.
If such a timer/counter register is not available, the return value is always
zero. This matches the assembly implementations' behaviour.
Reviewed-by: Richard Levitte <levitte at openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre at ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/5231)
commit 2ad2281a8005dbc9046059693995c78a04ed9e37
Author: Pauli <paul.dale at oracle.com>
Date: Tue Feb 6 07:15:53 2018 +1000
Make the OPENSSL_CPUID_OBJ define internal.
Patch by @levitte.
Reviewed-by: Richard Levitte <levitte at openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre at ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/5231)
-----------------------------------------------------------------------
Summary of changes:
Configure | 2 +
crypto/cryptlib.c | 8 ++++
crypto/rand/rand_lib.c | 92 +++++++++++++++++++++++++++++++---------
include/internal/cryptlib.h | 6 +--
include/openssl/opensslconf.h.in | 4 +-
5 files changed, 84 insertions(+), 28 deletions(-)
diff --git a/Configure b/Configure
index 22d42fb..a6f5a31 100755
--- a/Configure
+++ b/Configure
@@ -1292,6 +1292,8 @@ if ($target{sys_id} ne "")
unless ($disabled{asm}) {
$target{cpuid_asm_src}=$table{DEFAULTS}->{cpuid_asm_src} if ($config{processor} eq "386");
+ push @{$config{defines}}, "OPENSSL_CPUID_OBJ" if ($target{cpuid_asm_src} ne "mem_clr.o");
+
$target{bn_asm_src} =~ s/\w+-gf2m.c// if (defined($disabled{ec2m}));
# bn-586 is the only one implementing bn_*_part_words
diff --git a/crypto/cryptlib.c b/crypto/cryptlib.c
index a4f2fb8..a4d96d8 100644
--- a/crypto/cryptlib.c
+++ b/crypto/cryptlib.c
@@ -355,4 +355,12 @@ int CRYPTO_memcmp(const void * in_a, const void * in_b, size_t len)
return x;
}
+
+/*
+ * For systems that don't provide an instruction counter register or equivalent.
+ */
+uint32_t OPENSSL_rdtsc(void)
+{
+ return 0;
+}
#endif
diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c
index e82a63e..810677b 100644
--- a/crypto/rand/rand_lib.c
+++ b/crypto/rand/rand_lib.c
@@ -22,6 +22,9 @@
#endif
#include "e_os.h"
+/* Macro to convert two thirty two bit values into a sixty four bit one */
+#define TWO32TO64(a, b) ((((uint64_t)(a)) << 32) + (b))
+
#ifndef OPENSSL_NO_ENGINE
/* non-NULL if default_RAND_meth is ENGINE-provided */
static ENGINE *funct_ref;
@@ -194,6 +197,71 @@ size_t rand_drbg_get_entropy(RAND_DRBG *drbg,
}
/*
+ * Find a suitable system time. Start with the highest resolution source
+ * and work down to the slower ones. This is added as additional data and
+ * isn't counted as randomness, so any result is acceptable.
+ */
+static uint64_t get_timer_bits(void)
+{
+ uint64_t res = OPENSSL_rdtsc();
+
+ if (res != 0)
+ return res;
+#if defined(_WIN32)
+ {
+ LARGE_INTEGER t;
+ FILETIME ft;
+
+ if (QueryPerformanceCounter(&t) != 0)
+ return t.QuadPart;
+ GetSystemTimeAsFileTime(&ft);
+ return TWO32TO64(ft.dwHighDateTime, ft.dwLowDateTime);
+ }
+#elif defined(__sun) || defined(__hpux)
+ return gethrtime();
+#elif defined(_AIX)
+ {
+ timebasestruct_t t;
+
+ read_wall_time(&t, TIMEBASE_SZ);
+ return TWO32TO64(t.tb_high, t.tb_low);
+ }
+#else
+
+# if defined(_POSIX_C_SOURCE) \
+ && defined(_POSIX_TIMERS) \
+ && _POSIX_C_SOURCE >= 199309L \
+ && (!defined(__GLIBC__) || __GLIBC_PREREQ(2, 17))
+ {
+ struct timespec ts;
+ clockid_t cid;
+
+# ifdef CLOCK_BOOTTIME
+ cid = CLOCK_BOOTTIME;
+# elif defined(_POSIX_MONOTONIC_CLOCK)
+ cid = CLOCK_MONOTONIC;
+# else
+ cid = CLOCK_REALTIME;
+# endif
+
+ if (clock_gettime(cid, &ts) == 0)
+ return TWO32TO64(ts.tv_sec, ts.tv_nsec);
+ }
+# endif
+# if defined(__unix__) \
+ || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L)
+ {
+ struct timeval tv;
+
+ if (gettimeofday(&tv, NULL) == 0)
+ return TWO32TO64(tv.tv_sec, tv.tv_usec);
+ }
+# endif
+ return time(NULL);
+#endif
+}
+
+/*
* Generate additional data that can be used for the drbg. The data does
* not need to contain entropy, but it's useful if it contains at least
* some bits that are unpredictable.
@@ -210,15 +278,10 @@ size_t rand_drbg_get_additional_data(unsigned char **pout, size_t max_len)
size_t len;
#ifdef OPENSSL_SYS_UNIX
pid_t pid;
- struct timeval tv;
#elif defined(OPENSSL_SYS_WIN32)
DWORD pid;
- FILETIME ft;
- LARGE_INTEGER pc;
-#endif
-#ifdef OPENSSL_CPUID_OBJ
- uint32_t tsc = 0;
#endif
+ uint64_t tbits;
pool = RAND_POOL_new(0, 0, max_len);
if (pool == NULL)
@@ -236,21 +299,8 @@ size_t rand_drbg_get_additional_data(unsigned char **pout, size_t max_len)
if (thread_id != 0)
RAND_POOL_add(pool, (unsigned char *)&thread_id, sizeof(thread_id), 0);
-#ifdef OPENSSL_CPUID_OBJ
- tsc = OPENSSL_rdtsc();
- if (tsc != 0)
- RAND_POOL_add(pool, (unsigned char *)&tsc, sizeof(tsc), 0);
-#endif
-
-#ifdef OPENSSL_SYS_UNIX
- if (gettimeofday(&tv, NULL) == 0)
- RAND_POOL_add(pool, (unsigned char *)&tv, sizeof(tv), 0);
-#elif defined(OPENSSL_SYS_WIN32)
- 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);
-#endif
+ tbits = get_timer_bits();
+ RAND_POOL_add(pool, (unsigned char *)&tbits, sizeof(tbits), 0);
/* TODO: Use RDSEED? */
diff --git a/include/internal/cryptlib.h b/include/internal/cryptlib.h
index 25ccdb1..8a96de9 100644
--- a/include/internal/cryptlib.h
+++ b/include/internal/cryptlib.h
@@ -1,5 +1,5 @@
/*
- * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -94,9 +94,7 @@ FILE *openssl_fopen(const char *filename, const char *mode);
void *openssl_fopen(const char *filename, const char *mode);
# endif
-#ifdef OPENSSL_CPUID_OBJ
-uint32_t OPENSSL_rdtsc();
-#endif
+uint32_t OPENSSL_rdtsc(void);
#ifdef __cplusplus
}
diff --git a/include/openssl/opensslconf.h.in b/include/openssl/opensslconf.h.in
index 2603247..16aa82e 100644
--- a/include/openssl/opensslconf.h.in
+++ b/include/openssl/opensslconf.h.in
@@ -1,7 +1,7 @@
/*
* {- join("\n * ", @autowarntext) -}
*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -119,8 +119,6 @@ extern "C" {
# define DEPRECATEDIN_0_9_8(f)
#endif
-{- $target{cpuid_obj} ne "mem_clr.o" ? "#define OPENSSL_CPUID_OBJ" : "" -}
-
/* Generate 80386 code? */
{- $config{processor} eq "386" ? "#define" : "#undef" -} I386_ONLY
More information about the openssl-commits
mailing list