aboutsummaryrefslogtreecommitdiffstats
path: root/Attic
diff options
context:
space:
mode:
Diffstat (limited to 'Attic')
-rw-r--r--Attic/mutex/info.txt7
-rw-r--r--Attic/mutex/mutex.h56
-rw-r--r--Attic/mutex/noop_mutex/info.txt8
-rw-r--r--Attic/mutex/noop_mutex/mux_noop.cpp50
-rw-r--r--Attic/mutex/noop_mutex/mux_noop.h26
-rw-r--r--Attic/mutex/pthreads/info.txt28
-rw-r--r--Attic/mutex/pthreads/mux_pthr.cpp58
-rw-r--r--Attic/mutex/pthreads/mux_pthr.h26
-rw-r--r--Attic/mutex/qt_mutex/info.txt16
-rw-r--r--Attic/mutex/qt_mutex/mux_qt.cpp35
-rw-r--r--Attic/mutex/qt_mutex/mux_qt.h27
-rw-r--r--Attic/mutex/win32_crit_section/info.txt15
-rw-r--r--Attic/mutex/win32_crit_section/mux_win32.cpp34
-rw-r--r--Attic/mutex/win32_crit_section/mux_win32.h26
-rw-r--r--Attic/timer/cpu_counter/info.txt34
-rw-r--r--Attic/timer/cpu_counter/tm_hard.cpp51
-rw-r--r--Attic/timer/cpu_counter/tm_hard.h33
-rw-r--r--Attic/timer/gettimeofday/info.txt30
-rw-r--r--Attic/timer/gettimeofday/tm_unix.cpp23
-rw-r--r--Attic/timer/gettimeofday/tm_unix.h27
-rw-r--r--Attic/timer/info.txt12
-rw-r--r--Attic/timer/posix_rt/info.txt26
-rw-r--r--Attic/timer/posix_rt/tm_posix.cpp32
-rw-r--r--Attic/timer/posix_rt/tm_posix.h27
-rw-r--r--Attic/timer/timer.cpp64
-rw-r--r--Attic/timer/timer.h53
-rw-r--r--Attic/timer/win32_query_perf_ctr/info.txt23
-rw-r--r--Attic/timer/win32_query_perf_ctr/tm_win32.cpp23
-rw-r--r--Attic/timer/win32_query_perf_ctr/tm_win32.h27
29 files changed, 897 insertions, 0 deletions
diff --git a/Attic/mutex/info.txt b/Attic/mutex/info.txt
new file mode 100644
index 000000000..0f2836b64
--- /dev/null
+++ b/Attic/mutex/info.txt
@@ -0,0 +1,7 @@
+define MUTEX_WRAPPERS
+
+load_on auto
+
+<add>
+mutex.h
+</add>
diff --git a/Attic/mutex/mutex.h b/Attic/mutex/mutex.h
new file mode 100644
index 000000000..a04ff83c9
--- /dev/null
+++ b/Attic/mutex/mutex.h
@@ -0,0 +1,56 @@
+/*
+* Mutex
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_MUTEX_H__
+#define BOTAN_MUTEX_H__
+
+#include <botan/exceptn.h>
+
+namespace Botan {
+
+/*
+* Mutex Base Class
+*/
+class BOTAN_DLL Mutex
+ {
+ public:
+ virtual void lock() = 0;
+ virtual void unlock() = 0;
+ virtual ~Mutex() {}
+ };
+
+/*
+* Mutex Factory
+*/
+class BOTAN_DLL Mutex_Factory
+ {
+ public:
+ virtual Mutex* make() = 0;
+ virtual ~Mutex_Factory() {}
+ };
+
+/*
+* Mutex Holding Class
+*/
+class BOTAN_DLL Mutex_Holder
+ {
+ public:
+ Mutex_Holder(Mutex* m) : mux(m)
+ {
+ if(!mux)
+ throw Invalid_Argument("Mutex_Holder: Argument was NULL");
+ mux->lock();
+ }
+
+ ~Mutex_Holder() { mux->unlock(); }
+ private:
+ Mutex* mux;
+ };
+
+}
+
+#endif
diff --git a/Attic/mutex/noop_mutex/info.txt b/Attic/mutex/noop_mutex/info.txt
new file mode 100644
index 000000000..6025959c2
--- /dev/null
+++ b/Attic/mutex/noop_mutex/info.txt
@@ -0,0 +1,8 @@
+load_on auto
+
+define MUTEX_NOOP
+
+<add>
+mux_noop.cpp
+mux_noop.h
+</add>
diff --git a/Attic/mutex/noop_mutex/mux_noop.cpp b/Attic/mutex/noop_mutex/mux_noop.cpp
new file mode 100644
index 000000000..5c45084fe
--- /dev/null
+++ b/Attic/mutex/noop_mutex/mux_noop.cpp
@@ -0,0 +1,50 @@
+/*
+* No-Op Mutex Factory
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#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/Attic/mutex/noop_mutex/mux_noop.h b/Attic/mutex/noop_mutex/mux_noop.h
new file mode 100644
index 000000000..94201cb7c
--- /dev/null
+++ b/Attic/mutex/noop_mutex/mux_noop.h
@@ -0,0 +1,26 @@
+/*
+* No-Op Mutex Factory
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#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/Attic/mutex/pthreads/info.txt b/Attic/mutex/pthreads/info.txt
new file mode 100644
index 000000000..7315c186a
--- /dev/null
+++ b/Attic/mutex/pthreads/info.txt
@@ -0,0 +1,28 @@
+define MUTEX_PTHREAD
+
+load_on auto
+
+<add>
+mux_pthr.cpp
+mux_pthr.h
+</add>
+
+<libs>
+all!qnx,freebsd,dragonfly,openbsd,netbsd -> pthread
+</libs>
+
+<os>
+aix
+cygwin
+darwin
+freebsd
+dragonfly
+hpux
+irix
+linux
+netbsd
+openbsd
+qnx
+solaris
+tru64
+</os>
diff --git a/Attic/mutex/pthreads/mux_pthr.cpp b/Attic/mutex/pthreads/mux_pthr.cpp
new file mode 100644
index 000000000..9f1d9816e
--- /dev/null
+++ b/Attic/mutex/pthreads/mux_pthr.cpp
@@ -0,0 +1,58 @@
+/*
+* Pthread Mutex
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#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/Attic/mutex/pthreads/mux_pthr.h b/Attic/mutex/pthreads/mux_pthr.h
new file mode 100644
index 000000000..118853947
--- /dev/null
+++ b/Attic/mutex/pthreads/mux_pthr.h
@@ -0,0 +1,26 @@
+/*
+* Pthread Mutex
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_MUTEX_PTHREAD_H__
+#define BOTAN_MUTEX_PTHREAD_H__
+
+#include <botan/mutex.h>
+
+namespace Botan {
+
+/*
+* Pthread Mutex Factory
+*/
+class BOTAN_DLL Pthread_Mutex_Factory : public Mutex_Factory
+ {
+ public:
+ Mutex* make();
+ };
+
+}
+
+#endif
diff --git a/Attic/mutex/qt_mutex/info.txt b/Attic/mutex/qt_mutex/info.txt
new file mode 100644
index 000000000..922c38ed1
--- /dev/null
+++ b/Attic/mutex/qt_mutex/info.txt
@@ -0,0 +1,16 @@
+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/Attic/mutex/qt_mutex/mux_qt.cpp b/Attic/mutex/qt_mutex/mux_qt.cpp
new file mode 100644
index 000000000..0f670c8b4
--- /dev/null
+++ b/Attic/mutex/qt_mutex/mux_qt.cpp
@@ -0,0 +1,35 @@
+/*
+* Qt Thread Mutex
+* (C) 2004-2007 Justin Karneges
+* 2004-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#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/Attic/mutex/qt_mutex/mux_qt.h b/Attic/mutex/qt_mutex/mux_qt.h
new file mode 100644
index 000000000..5aed77f4b
--- /dev/null
+++ b/Attic/mutex/qt_mutex/mux_qt.h
@@ -0,0 +1,27 @@
+/*
+* Qt Mutex
+* (C) 2004-2007 Justin Karneges
+* 2004-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_MUTEX_QT_H__
+#define BOTAN_MUTEX_QT_H__
+
+#include <botan/mutex.h>
+
+namespace Botan {
+
+/*
+* Qt Mutex
+*/
+class BOTAN_DLL Qt_Mutex_Factory : public Mutex_Factory
+ {
+ public:
+ Mutex* make();
+ };
+
+}
+
+#endif
diff --git a/Attic/mutex/win32_crit_section/info.txt b/Attic/mutex/win32_crit_section/info.txt
new file mode 100644
index 000000000..ffa8a98e3
--- /dev/null
+++ b/Attic/mutex/win32_crit_section/info.txt
@@ -0,0 +1,15 @@
+define MUTEX_WIN32
+modset win32
+
+load_on auto
+
+<add>
+mux_win32.cpp
+mux_win32.h
+</add>
+
+<os>
+cygwin
+windows
+mingw
+</os>
diff --git a/Attic/mutex/win32_crit_section/mux_win32.cpp b/Attic/mutex/win32_crit_section/mux_win32.cpp
new file mode 100644
index 000000000..2a967892b
--- /dev/null
+++ b/Attic/mutex/win32_crit_section/mux_win32.cpp
@@ -0,0 +1,34 @@
+/*
+* Win32 Mutex
+* (C) 2006 Luca Piccarreta
+* 2006-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#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/Attic/mutex/win32_crit_section/mux_win32.h b/Attic/mutex/win32_crit_section/mux_win32.h
new file mode 100644
index 000000000..a91850e71
--- /dev/null
+++ b/Attic/mutex/win32_crit_section/mux_win32.h
@@ -0,0 +1,26 @@
+/*
+* Win32 Mutex
+* (C) 2006 Luca Piccarreta
+* 2006-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_MUTEX_WIN32_H__
+#define BOTAN_MUTEX_WIN32_H__
+
+#include <botan/mutex.h>
+
+namespace Botan {
+
+/*
+* Win32 Mutex Factory
+*/
+class BOTAN_DLL Win32_Mutex_Factory : public Mutex_Factory
+ {
+ public:
+ Mutex* make();
+ };
+}
+
+#endif
diff --git a/Attic/timer/cpu_counter/info.txt b/Attic/timer/cpu_counter/info.txt
new file mode 100644
index 000000000..d95e0fec5
--- /dev/null
+++ b/Attic/timer/cpu_counter/info.txt
@@ -0,0 +1,34 @@
+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
+</requires>
diff --git a/Attic/timer/cpu_counter/tm_hard.cpp b/Attic/timer/cpu_counter/tm_hard.cpp
new file mode 100644
index 000000000..9e31aee39
--- /dev/null
+++ b/Attic/timer/cpu_counter/tm_hard.cpp
@@ -0,0 +1,51 @@
+/*
+* Hardware Timer
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#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/Attic/timer/cpu_counter/tm_hard.h b/Attic/timer/cpu_counter/tm_hard.h
new file mode 100644
index 000000000..2e338eca8
--- /dev/null
+++ b/Attic/timer/cpu_counter/tm_hard.h
@@ -0,0 +1,33 @@
+/*
+* Hardware Timer
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_TIMER_HARDWARE_H__
+#define BOTAN_TIMER_HARDWARE_H__
+
+#include <botan/timer.h>
+
+namespace Botan {
+
+/*
+* Hardware Timer
+*/
+class BOTAN_DLL Hardware_Timer : public Timer
+ {
+ public:
+ /*
+ @todo: Add sync(Timer& wall_clock, bool milliseconds) which busy
+ loops using wall_clock and tries to guess the tick rate of the
+ hardware counter, allowing it to be used for benchmarks, etc
+ */
+
+ std::string name() const { return "Hardware Timer"; }
+ u64bit clock() const;
+ };
+
+}
+
+#endif
diff --git a/Attic/timer/gettimeofday/info.txt b/Attic/timer/gettimeofday/info.txt
new file mode 100644
index 000000000..f8b65b4ba
--- /dev/null
+++ b/Attic/timer/gettimeofday/info.txt
@@ -0,0 +1,30 @@
+define TIMER_UNIX
+
+load_on auto
+modset unix,beos
+
+<add>
+tm_unix.cpp
+tm_unix.h
+</add>
+
+<os>
+aix
+beos
+cygwin
+darwin
+freebsd
+dragonfly
+hpux
+irix
+linux
+netbsd
+openbsd
+qnx
+solaris
+tru64
+</os>
+
+<requires>
+timer
+</requires>
diff --git a/Attic/timer/gettimeofday/tm_unix.cpp b/Attic/timer/gettimeofday/tm_unix.cpp
new file mode 100644
index 000000000..9d8ac4a04
--- /dev/null
+++ b/Attic/timer/gettimeofday/tm_unix.cpp
@@ -0,0 +1,23 @@
+/*
+* Unix Timer
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/tm_unix.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/Attic/timer/gettimeofday/tm_unix.h b/Attic/timer/gettimeofday/tm_unix.h
new file mode 100644
index 000000000..c304dbb5c
--- /dev/null
+++ b/Attic/timer/gettimeofday/tm_unix.h
@@ -0,0 +1,27 @@
+/*
+* Unix Timer
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_TIMER_UNIX_H__
+#define BOTAN_TIMER_UNIX_H__
+
+#include <botan/timer.h>
+
+namespace Botan {
+
+/*
+* Unix Timer
+*/
+class BOTAN_DLL Unix_Timer : public Timer
+ {
+ public:
+ std::string name() const { return "Unix gettimeofday"; }
+ u64bit clock() const;
+ };
+
+}
+
+#endif
diff --git a/Attic/timer/info.txt b/Attic/timer/info.txt
new file mode 100644
index 000000000..1dff5ab6f
--- /dev/null
+++ b/Attic/timer/info.txt
@@ -0,0 +1,12 @@
+define TIMER
+
+load_on auto
+
+<add>
+timer.cpp
+timer.h
+</add>
+
+<requires>
+rng
+</requires>
diff --git a/Attic/timer/posix_rt/info.txt b/Attic/timer/posix_rt/info.txt
new file mode 100644
index 000000000..4b23a74fc
--- /dev/null
+++ b/Attic/timer/posix_rt/info.txt
@@ -0,0 +1,26 @@
+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
+dragonfly
+#netbsd
+#openbsd
+</os>
+
+<requires>
+timer
+</requires>
diff --git a/Attic/timer/posix_rt/tm_posix.cpp b/Attic/timer/posix_rt/tm_posix.cpp
new file mode 100644
index 000000000..96182025c
--- /dev/null
+++ b/Attic/timer/posix_rt/tm_posix.cpp
@@ -0,0 +1,32 @@
+/*
+* POSIX Timer
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/tm_posix.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/Attic/timer/posix_rt/tm_posix.h b/Attic/timer/posix_rt/tm_posix.h
new file mode 100644
index 000000000..8bedccfa2
--- /dev/null
+++ b/Attic/timer/posix_rt/tm_posix.h
@@ -0,0 +1,27 @@
+/*
+* POSIX Timer
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_TIMER_POSIX_H__
+#define BOTAN_TIMER_POSIX_H__
+
+#include <botan/timer.h>
+
+namespace Botan {
+
+/*
+* POSIX Timer
+*/
+class BOTAN_DLL POSIX_Timer : public Timer
+ {
+ public:
+ std::string name() const { return "POSIX clock_gettime"; }
+ u64bit clock() const;
+ };
+
+}
+
+#endif
diff --git a/Attic/timer/timer.cpp b/Attic/timer/timer.cpp
new file mode 100644
index 000000000..16d7dc368
--- /dev/null
+++ b/Attic/timer/timer.cpp
@@ -0,0 +1,64 @@
+/**
+* Timestamp Functions
+* (C) 1999-2009 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/timer.h>
+#include <botan/loadstor.h>
+#include <ctime>
+
+namespace Botan {
+
+/**
+* Get the system clock
+*/
+u64bit system_time()
+ {
+ return static_cast<u64bit>(std::time(0));
+ }
+
+/*
+* Convert a time_t to a struct tm
+*/
+std::tm time_t_to_tm(u64bit timer)
+ {
+ std::time_t time_val = static_cast<std::time_t>(timer);
+
+ std::tm* tm_p = std::gmtime(&time_val);
+ if (tm_p == 0)
+ throw Encoding_Error("time_t_to_tm could not convert");
+ return (*tm_p);
+ }
+
+/**
+* Read the clock and return the output
+*/
+void Timer::poll(Entropy_Accumulator& accum)
+ {
+ const u64bit clock_value = this->clock();
+ accum.add(clock_value, 0);
+ }
+
+/**
+* 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;
+
+ u64bit res = seconds * NANOSECONDS_UNITS;
+ res += parts * (NANOSECONDS_UNITS / parts_hz);
+ return res;
+ }
+
+/**
+* ANSI Clock
+*/
+u64bit ANSI_Clock_Timer::clock() const
+ {
+ return combine_timers(std::time(0), std::clock(), CLOCKS_PER_SEC);
+ }
+
+}
diff --git a/Attic/timer/timer.h b/Attic/timer/timer.h
new file mode 100644
index 000000000..603027f6d
--- /dev/null
+++ b/Attic/timer/timer.h
@@ -0,0 +1,53 @@
+/**
+* Timestamp Functions
+* (C) 1999-2009 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_TIMERS_H__
+#define BOTAN_TIMERS_H__
+
+#include <botan/rng.h>
+#include <ctime>
+
+namespace Botan {
+
+/*
+* Time Access/Conversion Functions
+*/
+BOTAN_DLL u64bit system_time();
+
+BOTAN_DLL std::tm time_t_to_tm(u64bit);
+
+/**
+* Timer Interface
+*/
+class BOTAN_DLL Timer : public EntropySource
+ {
+ public:
+ /**
+ @return nanoseconds resolution timestamp, unknown epoch
+ */
+ virtual u64bit clock() const = 0;
+
+ void poll(Entropy_Accumulator& accum);
+
+ virtual ~Timer() {}
+ protected:
+ static u64bit combine_timers(u32bit, u32bit, u32bit);
+ };
+
+/**
+* ANSI Clock Timer
+*/
+class BOTAN_DLL ANSI_Clock_Timer : public Timer
+ {
+ public:
+ std::string name() const { return "ANSI clock"; }
+ u64bit clock() const;
+ };
+
+}
+
+#endif
diff --git a/Attic/timer/win32_query_perf_ctr/info.txt b/Attic/timer/win32_query_perf_ctr/info.txt
new file mode 100644
index 000000000..d8611027a
--- /dev/null
+++ b/Attic/timer/win32_query_perf_ctr/info.txt
@@ -0,0 +1,23 @@
+define TIMER_WIN32
+modset win32
+
+load_on auto
+
+<add>
+tm_win32.cpp
+tm_win32.h
+</add>
+
+<os>
+cygwin
+windows
+mingw
+</os>
+
+<libs>
+windows -> user32.lib
+</libs>
+
+<requires>
+timer
+</requires>
diff --git a/Attic/timer/win32_query_perf_ctr/tm_win32.cpp b/Attic/timer/win32_query_perf_ctr/tm_win32.cpp
new file mode 100644
index 000000000..6b878e6e2
--- /dev/null
+++ b/Attic/timer/win32_query_perf_ctr/tm_win32.cpp
@@ -0,0 +1,23 @@
+/*
+* Win32 Timer
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#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/Attic/timer/win32_query_perf_ctr/tm_win32.h b/Attic/timer/win32_query_perf_ctr/tm_win32.h
new file mode 100644
index 000000000..5bcb720ab
--- /dev/null
+++ b/Attic/timer/win32_query_perf_ctr/tm_win32.h
@@ -0,0 +1,27 @@
+/*
+* Win32 Timer
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_TIMER_WIN32_H__
+#define BOTAN_TIMER_WIN32_H__
+
+#include <botan/timer.h>
+
+namespace Botan {
+
+/*
+* Win32 Timer
+*/
+class BOTAN_DLL Win32_Timer : public Timer
+ {
+ public:
+ std::string name() const { return "Win32 QueryPerformanceCounter"; }
+ u64bit clock() const;
+ };
+
+}
+
+#endif