diff options
author | lloyd <[email protected]> | 2011-12-18 01:19:25 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2011-12-18 01:19:25 +0000 |
commit | 8809043895d1d4cf37ff476cb69c9277b33cc957 (patch) | |
tree | 72ca6a117cce901c9a36631422b1a7e5d88e1aac /src/entropy | |
parent | 5a76eb4c07f0caedde1a3d1d2824f2764a46a582 (diff) | |
parent | a3d81efbd2c56749d4abf9e6a27cb36cbbb10702 (diff) |
propagate from branch 'net.randombit.botan' (head 39f53266912f33dc48e942b1b865ddcd6af66d8d)
to branch 'net.randombit.botan.cxx11' (head 0bf26cec09f71e75c547b4ec53365748c6d80d86)
Diffstat (limited to 'src/entropy')
-rw-r--r-- | src/entropy/hres_timer/hres_timer.cpp | 37 | ||||
-rw-r--r-- | src/entropy/hres_timer/hres_timer.h | 3 |
2 files changed, 39 insertions, 1 deletions
diff --git a/src/entropy/hres_timer/hres_timer.cpp b/src/entropy/hres_timer/hres_timer.cpp index a10cdaf46..c6b31d996 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 */ @@ -20,9 +20,44 @@ namespace Botan { void High_Resolution_Timestamp::poll(Entropy_Accumulator& accum) { #if defined(BOTAN_TARGET_OS_HAS_QUERY_PERF_COUNTER) + { 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 { |