diff options
author | lloyd <[email protected]> | 2014-08-09 16:18:41 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-08-09 16:18:41 +0000 |
commit | 69122ae59b199a2a202a9f0f07be81bf001f376b (patch) | |
tree | cff37a9a58648a7446883905876ca60650419383 /src/lib/entropy | |
parent | 90cd8ae0572f907ddbe6158a493a748616176039 (diff) |
Don't bother polling std:: clocks if we have clock_gettime
Diffstat (limited to 'src/lib/entropy')
-rw-r--r-- | src/lib/entropy/hres_timer/hres_timer.cpp | 54 |
1 files changed, 22 insertions, 32 deletions
diff --git a/src/lib/entropy/hres_timer/hres_timer.cpp b/src/lib/entropy/hres_timer/hres_timer.cpp index 1768e8ed0..3fc68c771 100644 --- a/src/lib/entropy/hres_timer/hres_timer.cpp +++ b/src/lib/entropy/hres_timer/hres_timer.cpp @@ -1,6 +1,6 @@ /* * High Resolution Timestamp Entropy Source -* (C) 1999-2009,2011 Jack Lloyd +* (C) 1999-2009,2011,2014 Jack Lloyd * * Distributed under the terms of the Botan license */ @@ -29,25 +29,6 @@ void High_Resolution_Timestamp::poll(Entropy_Accumulator& accum) // Don't count any timestamps as contributing any entropy const double ESTIMATED_ENTROPY_PER_BYTE = 0.0; -#define STD_CHRONO_POLL(clock) \ - do { \ - auto timestamp = clock::now().time_since_epoch().count(); \ - accum.add(timestamp, ESTIMATED_ENTROPY_PER_BYTE); \ - } while(0) - - STD_CHRONO_POLL(std::chrono::high_resolution_clock); - STD_CHRONO_POLL(std::chrono::system_clock); - -#undef STD_CHRONO_POLL - -#if defined(BOTAN_TARGET_OS_HAS_QUERY_PERF_COUNTER) - { - LARGE_INTEGER tv; - ::QueryPerformanceCounter(&tv); - accum.add(tv.QuadPart, ESTIMATED_ENTROPY_PER_BYTE); - } -#endif - #if defined(BOTAN_TARGET_OS_HAS_CLOCK_GETTIME) #define CLOCK_GETTIME_POLL(src) \ @@ -61,26 +42,14 @@ void High_Resolution_Timestamp::poll(Entropy_Accumulator& accum) CLOCK_GETTIME_POLL(CLOCK_REALTIME); #endif -#if defined(CLOCK_REALTIME_COARSE) - CLOCK_GETTIME_POLL(CLOCK_REALTIME_COARSE); -#endif - #if defined(CLOCK_MONOTONIC) CLOCK_GETTIME_POLL(CLOCK_MONOTONIC); #endif -#if defined(CLOCK_MONOTONIC_COARSE) - CLOCK_GETTIME_POLL(CLOCK_MONOTONIC_COARSE); -#endif - #if defined(CLOCK_MONOTONIC_RAW) CLOCK_GETTIME_POLL(CLOCK_MONOTONIC_RAW); #endif -#if defined(CLOCK_BOOTTIME) - CLOCK_GETTIME_POLL(CLOCK_BOOTTIME); -#endif - #if defined(CLOCK_PROCESS_CPUTIME_ID) CLOCK_GETTIME_POLL(CLOCK_PROCESS_CPUTIME_ID); #endif @@ -91,6 +60,19 @@ void High_Resolution_Timestamp::poll(Entropy_Accumulator& accum) #undef CLOCK_GETTIME_POLL +#else + +#define STD_CHRONO_POLL(clock) \ + do { \ + auto timestamp = clock::now().time_since_epoch().count(); \ + accum.add(timestamp, ESTIMATED_ENTROPY_PER_BYTE); \ + } while(0) + + STD_CHRONO_POLL(std::chrono::high_resolution_clock); + STD_CHRONO_POLL(std::chrono::system_clock); + +#undef STD_CHRONO_POLL + #endif #if BOTAN_USE_GCC_INLINE_ASM @@ -130,6 +112,14 @@ void High_Resolution_Timestamp::poll(Entropy_Accumulator& accum) accum.add(rtc, ESTIMATED_ENTROPY_PER_BYTE); #endif + +#if defined(BOTAN_TARGET_OS_HAS_QUERY_PERF_COUNTER) + { + LARGE_INTEGER tv; + ::QueryPerformanceCounter(&tv); + accum.add(tv.QuadPart, ESTIMATED_ENTROPY_PER_BYTE); + } +#endif } } |