aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-12-01 12:06:22 +0000
committerlloyd <[email protected]>2009-12-01 12:06:22 +0000
commit4aec044fc21526e1c9185b384f7e984b7f8622c7 (patch)
treef284b904c7f781d160caa4b22eb488f90621697b
parent51cb1979c0533c52f4548d37fb00fbdc6775bba6 (diff)
parent874dbb8323dd4d7eff3ff16cff0cfafc16ddbfa7 (diff)
propagate from branch 'net.randombit.botan' (head b3515264af291b4785d3d296e2cc0e877ca7816a)
to branch 'net.randombit.botan.c++0x' (head 66ca78008f08bb5efc2eca52a3d4501f02ffd736)
-rw-r--r--Attic/timer/cpu_counter/tm_hard.h33
-rw-r--r--Attic/timer/gettimeofday/info.txt24
-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.h53
-rw-r--r--Attic/timer/win32_query_perf_ctr/info.txt17
-rw-r--r--Attic/timer/win32_query_perf_ctr/tm_win32.cpp23
-rw-r--r--Attic/timer/win32_query_perf_ctr/tm_win32.h27
-rwxr-xr-xconfigure.py36
-rw-r--r--src/asn1/info.txt1
-rw-r--r--src/benchmark/benchmark.h2
-rw-r--r--src/build-data/os/aix.txt4
-rw-r--r--src/build-data/os/beos.txt4
-rw-r--r--src/build-data/os/cygwin.txt4
-rw-r--r--src/build-data/os/darwin.txt4
-rw-r--r--src/build-data/os/dragonfly.txt2
-rw-r--r--src/build-data/os/freebsd.txt1
-rw-r--r--src/build-data/os/hpux.txt4
-rw-r--r--src/build-data/os/irix.txt4
-rw-r--r--src/build-data/os/linux.txt2
-rw-r--r--src/build-data/os/netbsd.txt4
-rw-r--r--src/build-data/os/openbsd.txt4
-rw-r--r--src/build-data/os/qnx.txt4
-rw-r--r--src/build-data/os/solaris.txt1
-rw-r--r--src/build-data/os/tru64.txt4
-rw-r--r--src/entropy/hres_timer/hres_timer.cpp (renamed from Attic/timer/cpu_counter/tm_hard.cpp)39
-rw-r--r--src/entropy/hres_timer/hres_timer.h27
-rw-r--r--src/entropy/hres_timer/info.txt (renamed from Attic/timer/cpu_counter/info.txt)12
-rw-r--r--src/rng/auto_rng/auto_rng.cpp29
-rw-r--r--src/rng/randpool/randpool.cpp5
-rw-r--r--src/utils/info.txt2
-rw-r--r--src/utils/time.cpp (renamed from Attic/timer/timer.cpp)75
-rw-r--r--src/utils/time.h30
37 files changed, 217 insertions, 411 deletions
diff --git a/Attic/timer/cpu_counter/tm_hard.h b/Attic/timer/cpu_counter/tm_hard.h
deleted file mode 100644
index 2e338eca8..000000000
--- a/Attic/timer/cpu_counter/tm_hard.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
-* 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
deleted file mode 100644
index d1f6f7d74..000000000
--- a/Attic/timer/gettimeofday/info.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-define TIMER_UNIX
-
-load_on auto
-
-<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
deleted file mode 100644
index 9d8ac4a04..000000000
--- a/Attic/timer/gettimeofday/tm_unix.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
-* 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
deleted file mode 100644
index c304dbb5c..000000000
--- a/Attic/timer/gettimeofday/tm_unix.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
-* 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
deleted file mode 100644
index 1dff5ab6f..000000000
--- a/Attic/timer/info.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-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
deleted file mode 100644
index 4b23a74fc..000000000
--- a/Attic/timer/posix_rt/info.txt
+++ /dev/null
@@ -1,26 +0,0 @@
-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
deleted file mode 100644
index 96182025c..000000000
--- a/Attic/timer/posix_rt/tm_posix.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
-* 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
deleted file mode 100644
index 8bedccfa2..000000000
--- a/Attic/timer/posix_rt/tm_posix.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
-* 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.h b/Attic/timer/timer.h
deleted file mode 100644
index 603027f6d..000000000
--- a/Attic/timer/timer.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
-* 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
deleted file mode 100644
index 67db5bc95..000000000
--- a/Attic/timer/win32_query_perf_ctr/info.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-define TIMER_WIN32
-
-load_on auto
-
-<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
deleted file mode 100644
index 6b878e6e2..000000000
--- a/Attic/timer/win32_query_perf_ctr/tm_win32.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
-* 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
deleted file mode 100644
index 5bcb720ab..000000000
--- a/Attic/timer/win32_query_perf_ctr/tm_win32.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
-* 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
diff --git a/configure.py b/configure.py
index f44b106ab..6e05f5246 100755
--- a/configure.py
+++ b/configure.py
@@ -312,7 +312,7 @@ def lex_me_harder(infofile, to_obj, allowed_groups, name_val_pairs):
for group in allowed_groups:
to_obj.__dict__[group] = []
- for (key,val) in name_val_pairs.iteritems():
+ for (key,val) in name_val_pairs.items():
to_obj.__dict__[key] = val
def lexed_tokens(): # Convert to an interator
@@ -376,7 +376,15 @@ class ModuleInfo(object):
and not filename.startswith('.')]
# Coerce to more useful types
- self.libs = force_to_dict(self.libs)
+ def convert_lib_list(l):
+ result = {}
+ for (targetlist, vallist) in zip(l[::3], l[2::3]):
+ vals = vallist.split(',')
+ for target in targetlist.split(','):
+ result[target] = result.setdefault(target, []) + vals
+ return result
+
+ self.libs = convert_lib_list(self.libs)
def add_dir_name(filename):
if filename.count(':') == 0:
@@ -422,6 +430,17 @@ class ModuleInfo(object):
deps.append(self.parent_module)
return deps
+ """
+ Ensure that all dependencies of this module actually exist, warning
+ about any that do not
+ """
+ def dependencies_exist(self, modules):
+ all_deps = map(lambda s: s.split('|'), self.dependencies())
+
+ for missing in filter(lambda s: s not in modules, sum(all_deps, [])):
+ logging.warn("Module '%s', dep of '%s', does not exist" % (
+ missing, self.basename))
+
def __cmp__(self, other):
if self.basename < other.basename:
return -1
@@ -641,7 +660,7 @@ class OsInfo(object):
def defines(self):
return ['TARGET_OS_IS_%s' % (self.basename.upper())] + \
['TARGET_OS_HAS_' + feat.upper()
- for feat in self.target_features]
+ for feat in sorted(self.target_features)]
def fixup_proc_name(proc):
proc = proc.lower().replace(' ', '')
@@ -715,15 +734,15 @@ def create_template_vars(build_config, options, modules, cc, arch, osinfo):
def link_to():
libs = set()
for module in modules:
- for (osname,link_to) in module.libs.iteritems():
+ for (osname,link_to) in module.libs.items():
if osname == 'all' or osname == osinfo.basename:
- libs.add(link_to)
+ libs |= set(link_to)
else:
match = re.match('^all!(.*)', osname)
if match is not None:
exceptions = match.group(1).split(',')
if osinfo.basename not in exceptions:
- libs.add(link_to)
+ libs |= set(link_to)
return sorted(libs)
def objectfile_list(sources, obj_dir):
@@ -888,6 +907,9 @@ Determine which modules to load based on options, target, etc
"""
def choose_modules_to_use(modules, archinfo, options):
+ for mod in modules.values():
+ mod.dependencies_exist(modules)
+
to_load = []
maybe_dep = []
not_using_because = {}
@@ -895,7 +917,7 @@ def choose_modules_to_use(modules, archinfo, options):
def cannot_use_because(mod, reason):
not_using_because.setdefault(reason, []).append(mod)
- for (modname, module) in modules.iteritems():
+ for (modname, module) in modules.items():
if modname in options.disabled_modules:
cannot_use_because(modname, 'disabled by user')
elif modname in options.enabled_modules:
diff --git a/src/asn1/info.txt b/src/asn1/info.txt
index 621b8b628..d836b4c0b 100644
--- a/src/asn1/info.txt
+++ b/src/asn1/info.txt
@@ -26,5 +26,4 @@ alloc
bigint
filters
oid_lookup
-timer
</requires>
diff --git a/src/benchmark/benchmark.h b/src/benchmark/benchmark.h
index cc13ae58d..baabc14ca 100644
--- a/src/benchmark/benchmark.h
+++ b/src/benchmark/benchmark.h
@@ -12,14 +12,12 @@
#include <botan/rng.h>
#include <map>
#include <string>
-
namespace Botan {
/**
* Algorithm benchmark
* @param name the name of the algorithm to test (cipher, hash, or MAC)
* @param milliseconds total time for the benchmark to run
-* @param timer the timer to use
* @param rng the rng to use to generate random inputs
* @param af the algorithm factory used to create objects
* @return results a map from provider to speed in mebibytes per second
diff --git a/src/build-data/os/aix.txt b/src/build-data/os/aix.txt
index 0063948c7..312377096 100644
--- a/src/build-data/os/aix.txt
+++ b/src/build-data/os/aix.txt
@@ -1,5 +1,9 @@
os_type unix
+<target_features>
+gettimeofday
+</target_features>
+
<supports_shared>
all
</supports_shared>
diff --git a/src/build-data/os/beos.txt b/src/build-data/os/beos.txt
index b843bd525..f6a06b7af 100644
--- a/src/build-data/os/beos.txt
+++ b/src/build-data/os/beos.txt
@@ -5,6 +5,10 @@ header_dir ../develop/headers
lib_dir system/lib
doc_dir documentation
+<target_features>
+gettimeofday
+</target_features>
+
<supports_shared>
all
</supports_shared>
diff --git a/src/build-data/os/cygwin.txt b/src/build-data/os/cygwin.txt
index 7290648c2..f7c1f49ed 100644
--- a/src/build-data/os/cygwin.txt
+++ b/src/build-data/os/cygwin.txt
@@ -3,6 +3,10 @@ os_type unix
install_root c:\Botan
doc_dir docs
+<target_features>
+gettimeofday
+</target_features>
+
# Cygwin supports shared libs fine, but there are problems with making a Botan
# shared library when libraries it depends on are static-only (such as libz).
# So until I can figure out a work-around, it's disabled.
diff --git a/src/build-data/os/darwin.txt b/src/build-data/os/darwin.txt
index fb18ee191..af60e1bed 100644
--- a/src/build-data/os/darwin.txt
+++ b/src/build-data/os/darwin.txt
@@ -8,6 +8,10 @@ ar_needs_ranlib yes
doc_dir doc
+<target_features>
+gettimeofday
+</target_features>
+
<supports_shared>
all
</supports_shared>
diff --git a/src/build-data/os/dragonfly.txt b/src/build-data/os/dragonfly.txt
index 6823de5b6..7a002a65d 100644
--- a/src/build-data/os/dragonfly.txt
+++ b/src/build-data/os/dragonfly.txt
@@ -1,6 +1,8 @@
os_type unix
<target_features>
+clock_gettime
+gettimeofday
posix_mlock
</target_features>
diff --git a/src/build-data/os/freebsd.txt b/src/build-data/os/freebsd.txt
index 6823de5b6..3bcf58d62 100644
--- a/src/build-data/os/freebsd.txt
+++ b/src/build-data/os/freebsd.txt
@@ -2,6 +2,7 @@ os_type unix
<target_features>
posix_mlock
+gettimeofday
</target_features>
<supports_shared>
diff --git a/src/build-data/os/hpux.txt b/src/build-data/os/hpux.txt
index 9ff0f7f62..e7aa30e9c 100644
--- a/src/build-data/os/hpux.txt
+++ b/src/build-data/os/hpux.txt
@@ -2,6 +2,10 @@ os_type unix
so_suffix sl
+<target_features>
+gettimeofday
+</target_features>
+
<supports_shared>
all
</supports_shared>
diff --git a/src/build-data/os/irix.txt b/src/build-data/os/irix.txt
index 0063948c7..312377096 100644
--- a/src/build-data/os/irix.txt
+++ b/src/build-data/os/irix.txt
@@ -1,5 +1,9 @@
os_type unix
+<target_features>
+gettimeofday
+</target_features>
+
<supports_shared>
all
</supports_shared>
diff --git a/src/build-data/os/linux.txt b/src/build-data/os/linux.txt
index 3a92f9dd7..b3c227533 100644
--- a/src/build-data/os/linux.txt
+++ b/src/build-data/os/linux.txt
@@ -1,6 +1,8 @@
os_type unix
<target_features>
+clock_gettime
+gettimeofday
posix_mlock
</target_features>
diff --git a/src/build-data/os/netbsd.txt b/src/build-data/os/netbsd.txt
index 0063948c7..312377096 100644
--- a/src/build-data/os/netbsd.txt
+++ b/src/build-data/os/netbsd.txt
@@ -1,5 +1,9 @@
os_type unix
+<target_features>
+gettimeofday
+</target_features>
+
<supports_shared>
all
</supports_shared>
diff --git a/src/build-data/os/openbsd.txt b/src/build-data/os/openbsd.txt
index 0063948c7..312377096 100644
--- a/src/build-data/os/openbsd.txt
+++ b/src/build-data/os/openbsd.txt
@@ -1,5 +1,9 @@
os_type unix
+<target_features>
+gettimeofday
+</target_features>
+
<supports_shared>
all
</supports_shared>
diff --git a/src/build-data/os/qnx.txt b/src/build-data/os/qnx.txt
index 0063948c7..312377096 100644
--- a/src/build-data/os/qnx.txt
+++ b/src/build-data/os/qnx.txt
@@ -1,5 +1,9 @@
os_type unix
+<target_features>
+gettimeofday
+</target_features>
+
<supports_shared>
all
</supports_shared>
diff --git a/src/build-data/os/solaris.txt b/src/build-data/os/solaris.txt
index 47b06dcc4..df951d4fc 100644
--- a/src/build-data/os/solaris.txt
+++ b/src/build-data/os/solaris.txt
@@ -2,6 +2,7 @@ os_type unix
<target_features>
posix_mlock
+gettimeofday
</target_features>
<supports_shared>
diff --git a/src/build-data/os/tru64.txt b/src/build-data/os/tru64.txt
index 8fc301d79..677c38955 100644
--- a/src/build-data/os/tru64.txt
+++ b/src/build-data/os/tru64.txt
@@ -1,5 +1,9 @@
os_type unix
+<target_features>
+gettimeofday
+</target_features>
+
<supports_shared>
all
</supports_shared>
diff --git a/Attic/timer/cpu_counter/tm_hard.cpp b/src/entropy/hres_timer/hres_timer.cpp
index 9e31aee39..74ea801c4 100644
--- a/Attic/timer/cpu_counter/tm_hard.cpp
+++ b/src/entropy/hres_timer/hres_timer.cpp
@@ -1,25 +1,43 @@
/*
-* Hardware Timer
-* (C) 1999-2007 Jack Lloyd
+* High Resolution Timestamp Entropy Source
+* (C) 1999-2009 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
-#include <botan/tm_hard.h>
+#include <botan/hres_timer.h>
+#include <botan/cpuid.h>
+#include <botan/time.h>
+
+#if defined(BOTAN_TARGET_OS_IS_WINDOWS)
+ #include <windows.h>
+#endif
namespace Botan {
/*
* Get the timestamp
*/
-u64bit Hardware_Timer::clock() const
+void High_Resolution_Timestamp::poll(Entropy_Accumulator& accum)
{
+ // If Windows, grab the Performance Counter (usually TSC or PIT)
+#if defined(BOTAN_TARGET_OS_IS_WINDOWS)
+ LARGE_INTEGER tv;
+ ::QueryPerformanceCounter(&tv);
+ accum.add(tv.QuadPart, 0);
+#endif
+
+#if defined(BOTAN_USE_GCC_INLINE_ASM)
+
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;
+ 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;
+ }
#elif defined(BOTAN_TARGET_ARCH_IS_PPC) || defined(BOTAN_TARGET_ARCH_IS_PPC64)
u32bit rtc_low = 0, rtc_high = 0;
@@ -41,11 +59,12 @@ u64bit Hardware_Timer::clock() const
#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;
+ // Don't count the timestamp as contributing entropy
+ accum.add(rtc, 0);
+
+#endif
}
}
diff --git a/src/entropy/hres_timer/hres_timer.h b/src/entropy/hres_timer/hres_timer.h
new file mode 100644
index 000000000..8dfbfc2d7
--- /dev/null
+++ b/src/entropy/hres_timer/hres_timer.h
@@ -0,0 +1,27 @@
+/*
+* High Resolution Timestamp Entropy Source
+* (C) 1999-2009 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_ENTROPY_SRC_HRES_TIMER_H__
+#define BOTAN_ENTROPY_SRC_HRES_TIMER_H__
+
+#include <botan/entropy_src.h>
+
+namespace Botan {
+
+/*
+* High Resolution Timestamp Source
+*/
+class BOTAN_DLL High_Resolution_Timestamp : public EntropySource
+ {
+ public:
+ std::string name() const { return "High Resolution Timestamp"; }
+ void poll(Entropy_Accumulator& accum);
+ };
+
+}
+
+#endif
diff --git a/Attic/timer/cpu_counter/info.txt b/src/entropy/hres_timer/info.txt
index 2ab1343bc..566ce4ef6 100644
--- a/Attic/timer/cpu_counter/info.txt
+++ b/src/entropy/hres_timer/info.txt
@@ -1,14 +1,10 @@
-define TIMER_HARDWARE
+define ENTROPY_SRC_HIGH_RESOLUTION_TIMER
load_on asm_ok
-<add>
-tm_hard.cpp
-tm_hard.h
-</add>
-
<cc>
gcc
+icc
</cc>
<arch>
@@ -30,7 +26,3 @@ ia64 # ar.itc
s390x
hppa
</arch>
-
-<requires>
-timer
-</requires>
diff --git a/src/rng/auto_rng/auto_rng.cpp b/src/rng/auto_rng/auto_rng.cpp
index f02a9249f..6906d9d17 100644
--- a/src/rng/auto_rng/auto_rng.cpp
+++ b/src/rng/auto_rng/auto_rng.cpp
@@ -7,7 +7,6 @@
#include <botan/auto_rng.h>
#include <botan/parsing.h>
-#include <botan/timer.h>
#include <botan/hmac.h>
#include <botan/sha2_32.h>
#include <botan/sha2_64.h>
@@ -28,20 +27,8 @@
#include <botan/aes.h>
#endif
-#if defined(BOTAN_HAS_TIMER_HARDWARE)
- #include <botan/tm_hard.h>
-#endif
-
-#if defined(BOTAN_HAS_TIMER_POSIX)
- #include <botan/tm_posix.h>
-#endif
-
-#if defined(BOTAN_HAS_TIMER_UNIX)
- #include <botan/tm_unix.h>
-#endif
-
-#if defined(BOTAN_HAS_TIMER_WIN32)
- #include <botan/tm_win32.h>
+#if defined(BOTAN_HAS_ENTROPY_SRC_HIGH_RESOLUTION_TIMER)
+ #include <botan/hres_timer.h>
#endif
#if defined(BOTAN_HAS_ENTROPY_SRC_DEVICE)
@@ -81,16 +68,8 @@ namespace {
*/
void add_entropy_sources(RandomNumberGenerator* rng)
{
-
- // Add a high resolution timer, if available
-#if defined(BOTAN_HAS_TIMER_HARDWARE)
- rng->add_entropy_source(new Hardware_Timer);
-#elif defined(BOTAN_HAS_TIMER_POSIX)
- rng->add_entropy_source(new POSIX_Timer);
-#elif defined(BOTAN_HAS_TIMER_UNIX)
- rng->add_entropy_source(new Unix_Timer);
-#elif defined(BOTAN_HAS_TIMER_WIN32)
- rng->add_entropy_source(new Win32_Timer);
+#if defined(BOTAN_HAS_ENTROPY_SRC_HIGH_RESOLUTION_TIMER)
+ rng->add_entropy_source(new High_Resolution_Timestamp);
#endif
#if defined(BOTAN_HAS_ENTROPY_SRC_DEVICE)
diff --git a/src/rng/randpool/randpool.cpp b/src/rng/randpool/randpool.cpp
index f4ce84079..18a3b49a0 100644
--- a/src/rng/randpool/randpool.cpp
+++ b/src/rng/randpool/randpool.cpp
@@ -50,14 +50,9 @@ void Randpool::randomize(byte out[], u32bit length)
*/
void Randpool::update_buffer()
{
- const u64bit timestamp =
- std::chrono::duration_cast<std::chrono::nanoseconds>(
- std::chrono::high_resolution_clock::now().time_since_epoch()).count();
-
for(u32bit i = 0; i != counter.size(); ++i)
if(++counter[i])
break;
- store_be(timestamp, counter + 4);
mac->update(static_cast<byte>(GEN_OUTPUT));
mac->update(counter, counter.size());
diff --git a/src/utils/info.txt b/src/utils/info.txt
index 3d024fa09..110afeb64 100644
--- a/src/utils/info.txt
+++ b/src/utils/info.txt
@@ -3,5 +3,5 @@ define UTIL_FUNCTIONS
load_on always
<libs>
-tru64 -> rt
+linux,tru64 -> rt
</libs>
diff --git a/Attic/timer/timer.cpp b/src/utils/time.cpp
index 16d7dc368..856b1c7be 100644
--- a/Attic/timer/timer.cpp
+++ b/src/utils/time.cpp
@@ -1,16 +1,50 @@
/**
-* Timestamp Functions
+* Time Functions
* (C) 1999-2009 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
-#include <botan/timer.h>
-#include <botan/loadstor.h>
+#include <botan/time.h>
+#include <botan/exceptn.h>
#include <ctime>
+#if defined(BOTAN_TARGET_OS_HAS_GETTIMEOFDAY)
+ #include <sys/time.h>
+#endif
+
+#if defined(BOTAN_TARGET_OS_HAS_CLOCK_GETTIME)
+
+#ifndef _POSIX_C_SOURCE
+ #define _POSIX_C_SOURCE 199309
+#endif
+
+#include <time.h>
+
+#ifndef CLOCK_REALTIME
+ #define CLOCK_REALTIME 0
+#endif
+
+#endif
+
namespace Botan {
+namespace {
+
+/**
+* Combine a two time values into a single one
+*/
+u64bit 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;
+ }
+
+}
+
/**
* Get the system clock
*/
@@ -32,33 +66,22 @@ std::tm time_t_to_tm(u64bit timer)
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)
+u64bit get_nanoseconds_clock()
{
- static const u64bit NANOSECONDS_UNITS = 1000000000;
+#if defined(BOTAN_TARGET_OS_HAS_CLOCK_GETTIME)
+ struct ::timespec tv;
+ ::clock_gettime(CLOCK_REALTIME, &tv);
+ return combine_timers(tv.tv_sec, tv.tv_nsec, 1000000000);
- u64bit res = seconds * NANOSECONDS_UNITS;
- res += parts * (NANOSECONDS_UNITS / parts_hz);
- return res;
- }
+#elif defined(BOTAN_TARGET_OS_HAS_GETTIMEOFDAY)
+ struct ::timeval tv;
+ ::gettimeofday(&tv, 0);
+ return combine_timers(tv.tv_sec, tv.tv_usec, 1000000);
-/**
-* ANSI Clock
-*/
-u64bit ANSI_Clock_Timer::clock() const
- {
+#else
return combine_timers(std::time(0), std::clock(), CLOCKS_PER_SEC);
+
+#endif
}
}
diff --git a/src/utils/time.h b/src/utils/time.h
new file mode 100644
index 000000000..c7f459096
--- /dev/null
+++ b/src/utils/time.h
@@ -0,0 +1,30 @@
+/**
+* Time Functions
+* (C) 1999-2009 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_TIME_H__
+#define BOTAN_TIME_H__
+
+#include <botan/types.h>
+#include <ctime>
+
+namespace Botan {
+
+/*
+* Time Access/Conversion Functions
+*/
+BOTAN_DLL u64bit system_time();
+
+BOTAN_DLL std::tm time_t_to_tm(u64bit);
+
+/**
+@return nanoseconds resolution timestamp, unknown epoch
+*/
+BOTAN_DLL u64bit get_nanoseconds_clock();
+
+}
+
+#endif