diff options
author | lloyd <[email protected]> | 2011-11-11 14:45:54 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2011-11-11 14:45:54 +0000 |
commit | 3c0fd408f50d9b4995b4d189331de8b58f204926 (patch) | |
tree | be97b8b5324eb3d3c68bf266e1f58e37933efea6 | |
parent | 8f590236f5f9bde3044fce715b69aac33e4a447a (diff) |
Poll clock_gettime in High_Resolution_Timestamp::poll with whatever
clock types we know about that have macros defined for them.
-rw-r--r-- | doc/log.txt | 3 | ||||
-rw-r--r-- | src/entropy/hres_timer/hres_timer.cpp | 37 | ||||
-rw-r--r-- | src/entropy/hres_timer/hres_timer.h | 3 |
3 files changed, 42 insertions, 1 deletions
diff --git a/doc/log.txt b/doc/log.txt index 696fa4ac9..d82f47157 100644 --- a/doc/log.txt +++ b/doc/log.txt @@ -16,6 +16,9 @@ Version 1.10.2, Not Yet Released replace will allow running it under Python 2.5:: perl -pi -e 's/except (.*) as (.*):/except $1, $2:/g' configure.py +* If clock_gettime is available on the system, poll all available + clock types in the hres_timer poll. + * Add AltiVec detection for IBM POWER7 processors. * Don't set a soname on OpenBSD, as it doesn't support it (PR 158) diff --git a/src/entropy/hres_timer/hres_timer.cpp b/src/entropy/hres_timer/hres_timer.cpp index 7313590e5..dd1fc6f7c 100644 --- a/src/entropy/hres_timer/hres_timer.cpp +++ b/src/entropy/hres_timer/hres_timer.cpp @@ -1,6 +1,6 @@ /* * High Resolution Timestamp Entropy Source -* (C) 1999-2009 Jack Lloyd +* (C) 1999-2009,2011 Jack Lloyd * * Distributed under the terms of the Botan license */ @@ -22,9 +22,44 @@ void High_Resolution_Timestamp::poll(Entropy_Accumulator& accum) { // If Windows, grab the Performance Counter (usually TSC or PIT) #if defined(BOTAN_TARGET_OS_IS_WINDOWS) + { LARGE_INTEGER tv; ::QueryPerformanceCounter(&tv); accum.add(tv.QuadPart, 0); + } +#endif + +#if defined(BOTAN_TARGET_OS_HAS_CLOCK_GETTIME) + +#define CLOCK_POLL(src) \ + do { \ + struct timespec ts; \ + clock_gettime(src, &ts); \ + accum.add(&ts, sizeof(ts), 0); \ + } while(0) + +#if defined(CLOCK_REALTIME) + CLOCK_POLL(CLOCK_REALTIME); +#endif + +#if defined(CLOCK_MONOTONIC) + CLOCK_POLL(CLOCK_MONOTONIC); +#endif + +#if defined(CLOCK_MONOTONIC_RAW) + CLOCK_POLL(CLOCK_MONOTONIC_RAW); +#endif + +#if defined(CLOCK_PROCESS_CPUTIME_ID) + CLOCK_POLL(CLOCK_PROCESS_CPUTIME_ID); +#endif + +#if defined(CLOCK_THREAD_CPUTIME_ID) + CLOCK_POLL(CLOCK_THREAD_CPUTIME_ID); +#endif + +#undef CLOCK_POLL + #endif #if BOTAN_USE_GCC_INLINE_ASM diff --git a/src/entropy/hres_timer/hres_timer.h b/src/entropy/hres_timer/hres_timer.h index c693b8d4e..8b95c8308 100644 --- a/src/entropy/hres_timer/hres_timer.h +++ b/src/entropy/hres_timer/hres_timer.h @@ -14,6 +14,9 @@ namespace Botan { /** * Entropy source using high resolution timers +* +* @note Any results from timers are marked as not contributing entropy +* to the poll, as a local attacker could observe them directly. */ class High_Resolution_Timestamp : public EntropySource { |