aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-30 04:35:34 +0000
committerlloyd <[email protected]>2008-09-30 04:35:34 +0000
commit3c55f159b8e2ff80c0f0ab0820de0afc414be7db (patch)
tree6370650255987e8df89b8ef90f46a5eec92b70ed /src/utils
parenteee6e1e1ec225c3301cef6839225317a8cc9cf4a (diff)
Split off part of the core module into libstate (basically the whole
lookup/global_state piece). Move timer and mutex directories into utils/
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/mutex/noop_mutex/info.txt10
-rw-r--r--src/utils/mutex/noop_mutex/mux_noop.cpp48
-rw-r--r--src/utils/mutex/noop_mutex/mux_noop.h24
-rw-r--r--src/utils/mutex/pthreads/info.txt29
-rw-r--r--src/utils/mutex/pthreads/mux_pthr.cpp56
-rw-r--r--src/utils/mutex/pthreads/mux_pthr.h24
-rw-r--r--src/utils/mutex/qt_mutex/info.txt18
-rw-r--r--src/utils/mutex/qt_mutex/mux_qt.cpp33
-rw-r--r--src/utils/mutex/qt_mutex/mux_qt.h25
-rw-r--r--src/utils/mutex/win32_crit_section/info.txt16
-rw-r--r--src/utils/mutex/win32_crit_section/mux_win32.cpp32
-rw-r--r--src/utils/mutex/win32_crit_section/mux_win32.h24
-rw-r--r--src/utils/timer/cpu_counter/info.txt36
-rw-r--r--src/utils/timer/cpu_counter/tm_hard.cpp49
-rw-r--r--src/utils/timer/cpu_counter/tm_hard.h24
-rw-r--r--src/utils/timer/gettimeofday/info.txt32
-rw-r--r--src/utils/timer/gettimeofday/tm_unix.cpp22
-rw-r--r--src/utils/timer/gettimeofday/tm_unix.h24
-rw-r--r--src/utils/timer/posix_rt/info.txt28
-rw-r--r--src/utils/timer/posix_rt/tm_posix.cpp31
-rw-r--r--src/utils/timer/posix_rt/tm_posix.h24
-rw-r--r--src/utils/timer/timer_base/info.txt10
-rw-r--r--src/utils/timer/timer_base/timers.cpp52
-rw-r--r--src/utils/timer/timer_base/timers.h29
-rw-r--r--src/utils/timer/win32_query_perf_ctr/info.txt25
-rw-r--r--src/utils/timer/win32_query_perf_ctr/tm_win32.cpp21
-rw-r--r--src/utils/timer/win32_query_perf_ctr/tm_win32.h24
27 files changed, 770 insertions, 0 deletions
diff --git a/src/utils/mutex/noop_mutex/info.txt b/src/utils/mutex/noop_mutex/info.txt
new file mode 100644
index 000000000..1f49f5e1c
--- /dev/null
+++ b/src/utils/mutex/noop_mutex/info.txt
@@ -0,0 +1,10 @@
+realname "No-Op Mutex"
+
+load_on auto
+
+define MUTEX_NOOP
+
+<add>
+mux_noop.cpp
+mux_noop.h
+</add>
diff --git a/src/utils/mutex/noop_mutex/mux_noop.cpp b/src/utils/mutex/noop_mutex/mux_noop.cpp
new file mode 100644
index 000000000..eb3a12702
--- /dev/null
+++ b/src/utils/mutex/noop_mutex/mux_noop.cpp
@@ -0,0 +1,48 @@
+/*************************************************
+* No-Op Mutex Factory Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/mux_noop.h>
+
+namespace Botan {
+
+/*************************************************
+* No-Op Mutex Factory *
+*************************************************/
+Mutex* Noop_Mutex_Factory::make()
+ {
+ class Noop_Mutex : public Mutex
+ {
+ public:
+ class Mutex_State_Error : public Internal_Error
+ {
+ public:
+ Mutex_State_Error(const std::string& where) :
+ Internal_Error("Noop_Mutex::" + where + ": " +
+ "Mutex is already " + where + "ed") {}
+ };
+
+ void lock()
+ {
+ if(locked)
+ throw Mutex_State_Error("lock");
+ locked = true;
+ }
+
+ void unlock()
+ {
+ if(!locked)
+ throw Mutex_State_Error("unlock");
+ locked = false;
+ }
+
+ Noop_Mutex() { locked = false; }
+ private:
+ bool locked;
+ };
+
+ return new Noop_Mutex;
+ }
+
+}
diff --git a/src/utils/mutex/noop_mutex/mux_noop.h b/src/utils/mutex/noop_mutex/mux_noop.h
new file mode 100644
index 000000000..a5b802cc0
--- /dev/null
+++ b/src/utils/mutex/noop_mutex/mux_noop.h
@@ -0,0 +1,24 @@
+/*************************************************
+* No-Op Mutex Factory Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_NOOP_MUTEX_FACTORY_H__
+#define BOTAN_NOOP_MUTEX_FACTORY_H__
+
+#include <botan/mutex.h>
+
+namespace Botan {
+
+/*************************************************
+* No-Op Mutex Factory *
+*************************************************/
+class BOTAN_DLL Noop_Mutex_Factory : public Mutex_Factory
+ {
+ public:
+ Mutex* make();
+ };
+
+}
+
+#endif
diff --git a/src/utils/mutex/pthreads/info.txt b/src/utils/mutex/pthreads/info.txt
new file mode 100644
index 000000000..88de70de0
--- /dev/null
+++ b/src/utils/mutex/pthreads/info.txt
@@ -0,0 +1,29 @@
+realname "Pthread Mutex"
+
+define MUTEX_PTHREAD
+
+load_on auto
+
+<add>
+mux_pthr.cpp
+mux_pthr.h
+</add>
+
+<libs>
+all!qnx,freebsd,openbsd,netbsd -> pthread
+</libs>
+
+<os>
+aix
+cygwin
+darwin
+freebsd
+hpux
+irix
+linux
+netbsd
+openbsd
+qnx
+solaris
+tru64
+</os>
diff --git a/src/utils/mutex/pthreads/mux_pthr.cpp b/src/utils/mutex/pthreads/mux_pthr.cpp
new file mode 100644
index 000000000..d003fa298
--- /dev/null
+++ b/src/utils/mutex/pthreads/mux_pthr.cpp
@@ -0,0 +1,56 @@
+/*************************************************
+* Pthread Mutex Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/mux_pthr.h>
+#include <botan/exceptn.h>
+
+#ifndef _POSIX_C_SOURCE
+ #define _POSIX_C_SOURCE 199506
+#endif
+
+#include <pthread.h>
+
+namespace Botan {
+
+/*************************************************
+* Pthread Mutex Factory *
+*************************************************/
+Mutex* Pthread_Mutex_Factory::make()
+ {
+
+ class Pthread_Mutex : public Mutex
+ {
+ public:
+ void lock()
+ {
+ if(pthread_mutex_lock(&mutex) != 0)
+ throw Exception("Pthread_Mutex::lock: Error occured");
+ }
+
+ void unlock()
+ {
+ if(pthread_mutex_unlock(&mutex) != 0)
+ throw Exception("Pthread_Mutex::unlock: Error occured");
+ }
+
+ Pthread_Mutex()
+ {
+ if(pthread_mutex_init(&mutex, 0) != 0)
+ throw Exception("Pthread_Mutex: initialization failed");
+ }
+
+ ~Pthread_Mutex()
+ {
+ if(pthread_mutex_destroy(&mutex) != 0)
+ throw Invalid_State("~Pthread_Mutex: mutex is still locked");
+ }
+ private:
+ pthread_mutex_t mutex;
+ };
+
+ return new Pthread_Mutex();
+ }
+
+}
diff --git a/src/utils/mutex/pthreads/mux_pthr.h b/src/utils/mutex/pthreads/mux_pthr.h
new file mode 100644
index 000000000..efdabfed4
--- /dev/null
+++ b/src/utils/mutex/pthreads/mux_pthr.h
@@ -0,0 +1,24 @@
+/*************************************************
+* Pthread Mutex Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_MUTEX_PTHREAD_H__
+#define BOTAN_MUTEX_PTHREAD_H__
+
+#include <botan/mutex.h>
+
+namespace Botan {
+
+/*************************************************
+* Pthread Mutex Factory *
+*************************************************/
+class Pthread_Mutex_Factory : public Mutex_Factory
+ {
+ public:
+ Mutex* make();
+ };
+
+}
+
+#endif
diff --git a/src/utils/mutex/qt_mutex/info.txt b/src/utils/mutex/qt_mutex/info.txt
new file mode 100644
index 000000000..a21108c79
--- /dev/null
+++ b/src/utils/mutex/qt_mutex/info.txt
@@ -0,0 +1,18 @@
+realname "Qt Mutex"
+
+define MUTEX_QT
+
+note "You'll probably have to add -I/-L flags to the Makefile to find Qt"
+
+load_on request
+
+<add>
+mux_qt.cpp
+mux_qt.h
+</add>
+
+# I think we want to always use qt-mt, not qt -- not much point in supporting
+# mutexes in a single threaded application, after all.
+<libs>
+all -> qt-mt
+</libs>
diff --git a/src/utils/mutex/qt_mutex/mux_qt.cpp b/src/utils/mutex/qt_mutex/mux_qt.cpp
new file mode 100644
index 000000000..421b771c7
--- /dev/null
+++ b/src/utils/mutex/qt_mutex/mux_qt.cpp
@@ -0,0 +1,33 @@
+/*************************************************
+* Qt Thread Mutex Source File *
+* (C) 2004-2007 Justin Karneges *
+* 2004-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/mux_qt.h>
+#include <qmutex.h>
+
+#if !defined(QT_THREAD_SUPPORT)
+ #error Your version of Qt does not support threads or mutexes
+#endif
+
+namespace Botan {
+
+/*************************************************
+* Qt Mutex Factory *
+*************************************************/
+Mutex* Qt_Mutex_Factory::make()
+ {
+ class Qt_Mutex : public Mutex
+ {
+ public:
+ void lock() { mutex.lock(); }
+ void unlock() { mutex.unlock(); }
+ private:
+ QMutex mutex;
+ };
+
+ return new Qt_Mutex();
+ }
+
+}
diff --git a/src/utils/mutex/qt_mutex/mux_qt.h b/src/utils/mutex/qt_mutex/mux_qt.h
new file mode 100644
index 000000000..fffdc78ae
--- /dev/null
+++ b/src/utils/mutex/qt_mutex/mux_qt.h
@@ -0,0 +1,25 @@
+/*************************************************
+* Qt Mutex Header File *
+* (C) 2004-2007 Justin Karneges *
+* 2004-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_MUTEX_QT_H__
+#define BOTAN_MUTEX_QT_H__
+
+#include <botan/mutex.h>
+
+namespace Botan {
+
+/*************************************************
+* Qt Mutex *
+*************************************************/
+class Qt_Mutex_Factory : public Mutex_Factory
+ {
+ public:
+ Mutex* make();
+ };
+
+}
+
+#endif
diff --git a/src/utils/mutex/win32_crit_section/info.txt b/src/utils/mutex/win32_crit_section/info.txt
new file mode 100644
index 000000000..d235ff73c
--- /dev/null
+++ b/src/utils/mutex/win32_crit_section/info.txt
@@ -0,0 +1,16 @@
+realname "Win32 Mutex"
+
+define MUTEX_WIN32
+modset win32
+
+load_on auto
+
+<add>
+mux_win32.cpp
+mux_win32.h
+</add>
+
+<os>
+cygwin
+windows
+</os>
diff --git a/src/utils/mutex/win32_crit_section/mux_win32.cpp b/src/utils/mutex/win32_crit_section/mux_win32.cpp
new file mode 100644
index 000000000..622a707fa
--- /dev/null
+++ b/src/utils/mutex/win32_crit_section/mux_win32.cpp
@@ -0,0 +1,32 @@
+/*************************************************
+* Win32 Mutex Source File *
+* (C) 2006 Luca Piccarreta *
+* 2006-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/mux_win32.h>
+#include <windows.h>
+
+namespace Botan {
+
+/*************************************************
+* Win32 Mutex Factory *
+*************************************************/
+Mutex* Win32_Mutex_Factory::make()
+ {
+ class Win32_Mutex : public Mutex
+ {
+ public:
+ void lock() { EnterCriticalSection(&mutex); }
+ void unlock() { LeaveCriticalSection(&mutex); }
+
+ Win32_Mutex() { InitializeCriticalSection(&mutex); }
+ ~Win32_Mutex() { DeleteCriticalSection(&mutex); }
+ private:
+ CRITICAL_SECTION mutex;
+ };
+
+ return new Win32_Mutex();
+ }
+
+}
diff --git a/src/utils/mutex/win32_crit_section/mux_win32.h b/src/utils/mutex/win32_crit_section/mux_win32.h
new file mode 100644
index 000000000..20b245967
--- /dev/null
+++ b/src/utils/mutex/win32_crit_section/mux_win32.h
@@ -0,0 +1,24 @@
+/*************************************************
+* Win32 Mutex Header File *
+* (C) 2006 Luca Piccarreta *
+* 2006-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_MUTEX_WIN32_H__
+#define BOTAN_MUTEX_WIN32_H__
+
+#include <botan/mutex.h>
+
+namespace Botan {
+
+/*************************************************
+* Win32 Mutex Factory *
+*************************************************/
+class Win32_Mutex_Factory : public Mutex_Factory
+ {
+ public:
+ Mutex* make();
+ };
+}
+
+#endif
diff --git a/src/utils/timer/cpu_counter/info.txt b/src/utils/timer/cpu_counter/info.txt
new file mode 100644
index 000000000..eef6be5a2
--- /dev/null
+++ b/src/utils/timer/cpu_counter/info.txt
@@ -0,0 +1,36 @@
+realname "Hardware Timer"
+
+define TIMER_HARDWARE
+
+load_on asm_ok
+
+<add>
+tm_hard.cpp
+tm_hard.h
+</add>
+
+<cc>
+gcc
+</cc>
+
+<arch>
+# RDTSC: Pentium and up
+i586
+i686
+athlon
+pentium4
+pentium-m
+amd64
+
+ppc # PPC timebase register
+ppc64 # PPC timebase register
+alpha # rpcc
+sparc64 # %tick register
+ia64 # ar.itc
+s390x
+hppa
+</arch>
+
+<requires>
+timer_base
+</requires>
diff --git a/src/utils/timer/cpu_counter/tm_hard.cpp b/src/utils/timer/cpu_counter/tm_hard.cpp
new file mode 100644
index 000000000..2f7516930
--- /dev/null
+++ b/src/utils/timer/cpu_counter/tm_hard.cpp
@@ -0,0 +1,49 @@
+/*************************************************
+* Hardware Timer Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/tm_hard.h>
+
+namespace Botan {
+
+/*************************************************
+* Get the timestamp *
+*************************************************/
+u64bit Hardware_Timer::clock() const
+ {
+ u64bit rtc = 0;
+
+#if defined(BOTAN_TARGET_ARCH_IS_IA32) || defined(BOTAN_TARGET_ARCH_IS_AMD64)
+ 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;
+
+#elif defined(BOTAN_TARGET_ARCH_IS_PPC) || defined(BOTAN_TARGET_ARCH_IS_PPC64)
+ u32bit rtc_low = 0, rtc_high = 0;
+ asm volatile("mftbu %0; mftb %1" : "=r" (rtc_high), "=r" (rtc_low));
+ rtc = (static_cast<u64bit>(rtc_high) << 32) | rtc_low;
+
+#elif defined(BOTAN_TARGET_ARCH_IS_ALPHA)
+ asm volatile("rpcc %0" : "=r" (rtc));
+
+#elif defined(BOTAN_TARGET_ARCH_IS_SPARC64)
+ asm volatile("rd %%tick, %0" : "=r" (rtc));
+
+#elif defined(BOTAN_TARGET_ARCH_IS_IA64)
+ asm volatile("mov %0=ar.itc" : "=r" (rtc));
+
+#elif defined(BOTAN_TARGET_ARCH_IS_S390X)
+ asm volatile("stck 0(%0)" : : "a" (&rtc) : "memory", "cc");
+
+#elif defined(BOTAN_TARGET_ARCH_IS_HPPA)
+ asm volatile("mfctl 16,%0" : "=r" (rtc)); // 64-bit only?
+
+#else
+ #error "Unsure how to access hardware timer on this system"
+#endif
+
+ return rtc;
+ }
+
+}
diff --git a/src/utils/timer/cpu_counter/tm_hard.h b/src/utils/timer/cpu_counter/tm_hard.h
new file mode 100644
index 000000000..678513f81
--- /dev/null
+++ b/src/utils/timer/cpu_counter/tm_hard.h
@@ -0,0 +1,24 @@
+/*************************************************
+* Hardware Timer Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_TIMER_HARDWARE_H__
+#define BOTAN_TIMER_HARDWARE_H__
+
+#include <botan/timers.h>
+
+namespace Botan {
+
+/*************************************************
+* Hardware Timer *
+*************************************************/
+class Hardware_Timer : public Timer
+ {
+ public:
+ u64bit clock() const;
+ };
+
+}
+
+#endif
diff --git a/src/utils/timer/gettimeofday/info.txt b/src/utils/timer/gettimeofday/info.txt
new file mode 100644
index 000000000..c079dfd58
--- /dev/null
+++ b/src/utils/timer/gettimeofday/info.txt
@@ -0,0 +1,32 @@
+realname "Unix Timer"
+
+define TIMER_UNIX
+
+load_on auto
+modset unix,beos
+
+<add>
+tm_unix.cpp
+tm_unix.h
+</add>
+
+<os>
+aix
+beos
+cygwin
+darwin
+freebsd
+hpux
+irix
+linux
+netbsd
+openbsd
+qnx
+solaris
+tru64
+</os>
+
+<requires>
+timer_base
+</requires>
+
diff --git a/src/utils/timer/gettimeofday/tm_unix.cpp b/src/utils/timer/gettimeofday/tm_unix.cpp
new file mode 100644
index 000000000..654297753
--- /dev/null
+++ b/src/utils/timer/gettimeofday/tm_unix.cpp
@@ -0,0 +1,22 @@
+/*************************************************
+* Unix Timer Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/tm_unix.h>
+#include <botan/util.h>
+#include <sys/time.h>
+
+namespace Botan {
+
+/*************************************************
+* Get the timestamp *
+*************************************************/
+u64bit Unix_Timer::clock() const
+ {
+ struct ::timeval tv;
+ ::gettimeofday(&tv, 0);
+ return combine_timers(tv.tv_sec, tv.tv_usec, 1000000);
+ }
+
+}
diff --git a/src/utils/timer/gettimeofday/tm_unix.h b/src/utils/timer/gettimeofday/tm_unix.h
new file mode 100644
index 000000000..fd24a1563
--- /dev/null
+++ b/src/utils/timer/gettimeofday/tm_unix.h
@@ -0,0 +1,24 @@
+/*************************************************
+* Unix Timer Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_TIMER_UNIX_H__
+#define BOTAN_TIMER_UNIX_H__
+
+#include <botan/timers.h>
+
+namespace Botan {
+
+/*************************************************
+* Unix Timer *
+*************************************************/
+class Unix_Timer : public Timer
+ {
+ public:
+ u64bit clock() const;
+ };
+
+}
+
+#endif
diff --git a/src/utils/timer/posix_rt/info.txt b/src/utils/timer/posix_rt/info.txt
new file mode 100644
index 000000000..fb1870988
--- /dev/null
+++ b/src/utils/timer/posix_rt/info.txt
@@ -0,0 +1,28 @@
+realname "POSIX Timer"
+
+define TIMER_POSIX
+
+load_on auto
+
+<add>
+tm_posix.cpp
+tm_posix.h
+</add>
+
+<libs>
+linux -> rt
+</libs>
+
+# The *BSDs put clock_gettime in sys/time.h, not time.h like POSIX says
+<os>
+cygwin
+linux
+#freebsd
+#netbsd
+#openbsd
+</os>
+
+<requires>
+timer_base
+</requires>
+
diff --git a/src/utils/timer/posix_rt/tm_posix.cpp b/src/utils/timer/posix_rt/tm_posix.cpp
new file mode 100644
index 000000000..601b2b43d
--- /dev/null
+++ b/src/utils/timer/posix_rt/tm_posix.cpp
@@ -0,0 +1,31 @@
+/*************************************************
+* POSIX Timer Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/tm_posix.h>
+#include <botan/util.h>
+
+#ifndef _POSIX_C_SOURCE
+ #define _POSIX_C_SOURCE 199309
+#endif
+
+#include <time.h>
+
+#ifndef CLOCK_REALTIME
+ #define CLOCK_REALTIME 0
+#endif
+
+namespace Botan {
+
+/*************************************************
+* Get the timestamp *
+*************************************************/
+u64bit POSIX_Timer::clock() const
+ {
+ struct ::timespec tv;
+ ::clock_gettime(CLOCK_REALTIME, &tv);
+ return combine_timers(tv.tv_sec, tv.tv_nsec, 1000000000);
+ }
+
+}
diff --git a/src/utils/timer/posix_rt/tm_posix.h b/src/utils/timer/posix_rt/tm_posix.h
new file mode 100644
index 000000000..fc3ccdc74
--- /dev/null
+++ b/src/utils/timer/posix_rt/tm_posix.h
@@ -0,0 +1,24 @@
+/*************************************************
+* POSIX Timer Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_TIMER_POSIX_H__
+#define BOTAN_TIMER_POSIX_H__
+
+#include <botan/timers.h>
+
+namespace Botan {
+
+/*************************************************
+* POSIX Timer *
+*************************************************/
+class POSIX_Timer : public Timer
+ {
+ public:
+ u64bit clock() const;
+ };
+
+}
+
+#endif
diff --git a/src/utils/timer/timer_base/info.txt b/src/utils/timer/timer_base/info.txt
new file mode 100644
index 000000000..3637d4c94
--- /dev/null
+++ b/src/utils/timer/timer_base/info.txt
@@ -0,0 +1,10 @@
+realname "Timer Base Class"
+
+define TIMER
+
+load_on auto
+
+<add>
+timers.cpp
+timers.h
+</add>
diff --git a/src/utils/timer/timer_base/timers.cpp b/src/utils/timer/timer_base/timers.cpp
new file mode 100644
index 000000000..4f482916f
--- /dev/null
+++ b/src/utils/timer/timer_base/timers.cpp
@@ -0,0 +1,52 @@
+/*************************************************
+* Timestamp Functions Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/timers.h>
+#include <botan/loadstor.h>
+#include <botan/util.h>
+#include <ctime>
+
+namespace Botan {
+
+/*************************************************
+* Get the system clock *
+*************************************************/
+u64bit system_time()
+ {
+ return static_cast<u64bit>(std::time(0));
+ }
+
+/*************************************************
+* Default Timer clock reading *
+*************************************************/
+u64bit Timer::clock() const
+ {
+ return combine_timers(std::time(0), std::clock(), CLOCKS_PER_SEC);
+ }
+
+/*************************************************
+* Read the clock and return the output *
+*************************************************/
+u32bit Timer::slow_poll(byte out[], u32bit length)
+ {
+ const u64bit clock_value = this->clock();
+
+ for(u32bit j = 0; j != sizeof(clock_value); ++j)
+ out[j % length] ^= get_byte(j, clock_value);
+
+ return (length < 8) ? length : 8;
+ }
+
+/*************************************************
+* Combine a two time values into a single one *
+*************************************************/
+u64bit Timer::combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz)
+ {
+ static const u64bit NANOSECONDS_UNITS = 1000000000;
+ parts *= (NANOSECONDS_UNITS / parts_hz);
+ return ((seconds * NANOSECONDS_UNITS) + parts);
+ }
+
+}
diff --git a/src/utils/timer/timer_base/timers.h b/src/utils/timer/timer_base/timers.h
new file mode 100644
index 000000000..253f71f6b
--- /dev/null
+++ b/src/utils/timer/timer_base/timers.h
@@ -0,0 +1,29 @@
+/*************************************************
+* Timestamp Functions Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_TIMERS_H__
+#define BOTAN_TIMERS_H__
+
+#include <botan/rng.h>
+
+namespace Botan {
+
+/*************************************************
+* Timer Interface *
+*************************************************/
+class BOTAN_DLL Timer : public EntropySource
+ {
+ public:
+ virtual u64bit clock() const;
+ u32bit slow_poll(byte[], u32bit);
+
+ virtual ~Timer() {}
+ protected:
+ static u64bit combine_timers(u32bit, u32bit, u32bit);
+ };
+
+}
+
+#endif
diff --git a/src/utils/timer/win32_query_perf_ctr/info.txt b/src/utils/timer/win32_query_perf_ctr/info.txt
new file mode 100644
index 000000000..e956f99c5
--- /dev/null
+++ b/src/utils/timer/win32_query_perf_ctr/info.txt
@@ -0,0 +1,25 @@
+realname "Win32 Timer"
+
+define TIMER_WIN32
+modset win32
+
+load_on auto
+
+<add>
+tm_win32.cpp
+tm_win32.h
+</add>
+
+<os>
+cygwin
+windows
+</os>
+
+<libs>
+windows -> user32
+</libs>
+
+<requires>
+timer_base
+</requires>
+
diff --git a/src/utils/timer/win32_query_perf_ctr/tm_win32.cpp b/src/utils/timer/win32_query_perf_ctr/tm_win32.cpp
new file mode 100644
index 000000000..58f7b0f55
--- /dev/null
+++ b/src/utils/timer/win32_query_perf_ctr/tm_win32.cpp
@@ -0,0 +1,21 @@
+/*************************************************
+* Win32 Timer Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/tm_win32.h>
+#include <windows.h>
+
+namespace Botan {
+
+/*************************************************
+* Get the timestamp *
+*************************************************/
+u64bit Win32_Timer::clock() const
+ {
+ LARGE_INTEGER tv;
+ ::QueryPerformanceCounter(&tv);
+ return tv.QuadPart;
+ }
+
+}
diff --git a/src/utils/timer/win32_query_perf_ctr/tm_win32.h b/src/utils/timer/win32_query_perf_ctr/tm_win32.h
new file mode 100644
index 000000000..67b045e78
--- /dev/null
+++ b/src/utils/timer/win32_query_perf_ctr/tm_win32.h
@@ -0,0 +1,24 @@
+/*************************************************
+* Win32 Timer Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_TIMER_WIN32_H__
+#define BOTAN_TIMER_WIN32_H__
+
+#include <botan/timers.h>
+
+namespace Botan {
+
+/*************************************************
+* Win32 Timer *
+*************************************************/
+class Win32_Timer : public Timer
+ {
+ public:
+ u64bit clock() const;
+ };
+
+}
+
+#endif