<commit_before>/*
* High Resolution Timestamp Entropy Source
* (C) 1999-2009,2011 <NAME>
*
* Distributed under the terms of the Botan license
*/

#include <botan/internal/hres_timer.h>
#include <botan/cpuid.h>

#if defined(BOTAN_TARGET_OS_HAS_QUERY_PERF_COUNTER)
  #include <windows.h>
#endif

namespace Botan {

/*
* Get the timestamp
*/
void High_Resolution_Timestamp::poll(Entropy_Accumulator& accum)
   {
   // Don't count the timestamp as contributing any entropy
   const double ESTIMATED_ENTROPY_PER_BYTE = 0.0;

#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_POLL(src)                                      \
   do {                                                      \
     struct timespec ts;                                     \
     ::clock_gettime(src, &ts);                              \
     accum.add(&ts, sizeof(ts), ESTIMATED_ENTROPY_PER_BYTE); \
   } 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

   u64bit rtc = 0;

#if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY)
   if(CPUID::has_rdtsc()) // not availble on all x86 CPUs
      {
      u32bit rtc_low = 0, rtc_high = 0;
      asm volatile("rdtsc" : "=d" (rtc_high), "=a" (rtc_low));
      rtc = (static_cast<u64bit>(rtc_high) << 32) | rtc_low;<commit_msg>Add more possible clock types<commit_after>/*
* High Resolution Timestamp Entropy Source
* (C) 1999-2009,2011 <NAME>
*
* Distributed under the terms of the Botan license
*/

#include <botan/internal/hres_timer.h>
#include <botan/cpuid.h>

#if defined(BOTAN_TARGET_OS_HAS_QUERY_PERF_COUNTER)
  #include <windows.h>
#endif

namespace Botan {

/*
* Get the timestamp
*/
void High_Resolution_Timestamp::poll(Entropy_Accumulator& accum)
   {
   // Don't count the timestamp as contributing any entropy
   const double ESTIMATED_ENTROPY_PER_BYTE = 0.0;

#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_POLL(src)                                      \
   do {                                                      \
     struct timespec ts;                                     \
     ::clock_gettime(src, &ts);                              \
     accum.add(&ts, sizeof(ts), ESTIMATED_ENTROPY_PER_BYTE); \
   } while(0)

#if defined(CLOCK_REALTIME)
   CLOCK_POLL(CLOCK_REALTIME);
#endif

#if defined(CLOCK_REALTIME_COARSE)
   CLOCK_POLL(CLOCK_REALTIME_COARSE);
#endif

#if defined(CLOCK_MONOTONIC)
   CLOCK_POLL(CLOCK_MONOTONIC);
#endif

#if defined(CLOCK_MONOTONIC_COARSE)
   CLOCK_POLL(CLOCK_MONOTONIC_COARSE);
#endif

#if defined(CLOCK_MONOTONIC_RAW)
   CLOCK_POLL(CLOCK_MONOTONIC_RAW);
#endif

#if defined(CLOCK_BOOTTIME)
   CLOCK_POLL(CLOCK_BOOTTIME);
#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

   u64bit rtc = 0;

#if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY)
   if(CPUID::has_rdtsc()) // not availble on all x86 CPUs
      {
      u32bit rtc_low = 0, rtc_high = 0;
      asm volatile("rdtsc" : "=d" (rtc_high), "=a" (rtc_low));
      rtc = (static_cast<u64bit>(rtc_high) << 32) | rtc_low;
{'fraction_non_alphanumeric': 0.10233393177737882, 'fraction_numerical': 0.015388561169530648, 'mean_word_length': 3.318936877076412, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6944465', 'n_tokens_mistral': 1602, 'n_tokens_neox': 1485, 'n_words': 255}