From 855b569d25b5810213ae7e52c04df4e5e0cf8d46 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 1 Apr 2009 14:54:29 +0000 Subject: Start a new branch for C++0x experimentation. With GCC, build as C++0x (set the binary name to my particular installed GCC 4.4 snapshot). --- src/build-data/cc/gcc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/build-data/cc/gcc b/src/build-data/cc/gcc index 68d79ddf8..bde1e5822 100644 --- a/src/build-data/cc/gcc +++ b/src/build-data/cc/gcc @@ -1,6 +1,6 @@ realname "GNU C++" -binary_name "g++" +binary_name "g++-4.4-20090331" compiler_has_tr1 yes @@ -10,7 +10,7 @@ add_include_dir_option "-I" add_lib_dir_option "-L" add_lib_option "-l" -lang_flags "-D_REENTRANT -ansi -Wno-long-long" +lang_flags "-D_REENTRANT -ansi -Wno-long-long -std=c++0x" warning_flags "-W -Wall" #warning_flags "-Wextra -Wall -Wstrict-aliasing -Wstrict-overflow=5 -Wcast-align -Wmissing-declarations -Wno-unused-parameter" -- cgit v1.2.3 From 99e8c1a20700631103ec20386f8080eeee4df588 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 1 Apr 2009 15:43:27 +0000 Subject: Remove the mutex classes in favor of C++0x's std::mutex and std::lock_guard --- Attic/mutex.h | 56 ++++++++++++++++++++ Attic/mutex/noop_mutex/info.txt | 10 ++++ Attic/mutex/noop_mutex/mux_noop.cpp | 50 ++++++++++++++++++ Attic/mutex/noop_mutex/mux_noop.h | 26 ++++++++++ Attic/mutex/pthreads/info.txt | 29 +++++++++++ Attic/mutex/pthreads/mux_pthr.cpp | 58 +++++++++++++++++++++ Attic/mutex/pthreads/mux_pthr.h | 26 ++++++++++ Attic/mutex/qt_mutex/info.txt | 18 +++++++ Attic/mutex/qt_mutex/mux_qt.cpp | 35 +++++++++++++ Attic/mutex/qt_mutex/mux_qt.h | 27 ++++++++++ Attic/mutex/win32_crit_section/info.txt | 17 +++++++ Attic/mutex/win32_crit_section/mux_win32.cpp | 34 +++++++++++++ Attic/mutex/win32_crit_section/mux_win32.h | 26 ++++++++++ src/algo_factory/algo_cache.h | 16 +++--- src/algo_factory/algo_factory.cpp | 11 ++-- src/algo_factory/algo_factory.h | 5 +- src/alloc/alloc_mmap/mmap_mem.h | 1 - src/alloc/mem_pool/mem_pool.cpp | 9 ++-- src/alloc/mem_pool/mem_pool.h | 6 +-- src/alloc/system_alloc/defalloc.h | 2 - src/libstate/init.cpp | 35 ++----------- src/libstate/libstate.cpp | 76 +++++++--------------------- src/libstate/libstate.h | 21 ++++---- src/mutex/noop_mutex/info.txt | 10 ---- src/mutex/noop_mutex/mux_noop.cpp | 50 ------------------ src/mutex/noop_mutex/mux_noop.h | 26 ---------- src/mutex/pthreads/info.txt | 29 ----------- src/mutex/pthreads/mux_pthr.cpp | 58 --------------------- src/mutex/pthreads/mux_pthr.h | 26 ---------- src/mutex/qt_mutex/info.txt | 18 ------- src/mutex/qt_mutex/mux_qt.cpp | 35 ------------- src/mutex/qt_mutex/mux_qt.h | 27 ---------- src/mutex/win32_crit_section/info.txt | 17 ------- src/mutex/win32_crit_section/mux_win32.cpp | 34 ------------- src/mutex/win32_crit_section/mux_win32.h | 26 ---------- src/utils/info.txt | 1 - src/utils/mutex.h | 56 -------------------- src/utils/scan_name.cpp | 1 + 38 files changed, 463 insertions(+), 545 deletions(-) create mode 100644 Attic/mutex.h create mode 100644 Attic/mutex/noop_mutex/info.txt create mode 100644 Attic/mutex/noop_mutex/mux_noop.cpp create mode 100644 Attic/mutex/noop_mutex/mux_noop.h create mode 100644 Attic/mutex/pthreads/info.txt create mode 100644 Attic/mutex/pthreads/mux_pthr.cpp create mode 100644 Attic/mutex/pthreads/mux_pthr.h create mode 100644 Attic/mutex/qt_mutex/info.txt create mode 100644 Attic/mutex/qt_mutex/mux_qt.cpp create mode 100644 Attic/mutex/qt_mutex/mux_qt.h create mode 100644 Attic/mutex/win32_crit_section/info.txt create mode 100644 Attic/mutex/win32_crit_section/mux_win32.cpp create mode 100644 Attic/mutex/win32_crit_section/mux_win32.h delete mode 100644 src/mutex/noop_mutex/info.txt delete mode 100644 src/mutex/noop_mutex/mux_noop.cpp delete mode 100644 src/mutex/noop_mutex/mux_noop.h delete mode 100644 src/mutex/pthreads/info.txt delete mode 100644 src/mutex/pthreads/mux_pthr.cpp delete mode 100644 src/mutex/pthreads/mux_pthr.h delete mode 100644 src/mutex/qt_mutex/info.txt delete mode 100644 src/mutex/qt_mutex/mux_qt.cpp delete mode 100644 src/mutex/qt_mutex/mux_qt.h delete mode 100644 src/mutex/win32_crit_section/info.txt delete mode 100644 src/mutex/win32_crit_section/mux_win32.cpp delete mode 100644 src/mutex/win32_crit_section/mux_win32.h delete mode 100644 src/utils/mutex.h (limited to 'src') diff --git a/Attic/mutex.h b/Attic/mutex.h new file mode 100644 index 000000000..a04ff83c9 --- /dev/null +++ b/Attic/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 + +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..1f49f5e1c --- /dev/null +++ b/Attic/mutex/noop_mutex/info.txt @@ -0,0 +1,10 @@ +realname "No-Op Mutex" + +load_on auto + +define MUTEX_NOOP + + +mux_noop.cpp +mux_noop.h + 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 + +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 + +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..88de70de0 --- /dev/null +++ b/Attic/mutex/pthreads/info.txt @@ -0,0 +1,29 @@ +realname "Pthread Mutex" + +define MUTEX_PTHREAD + +load_on auto + + +mux_pthr.cpp +mux_pthr.h + + + +all!qnx,freebsd,openbsd,netbsd -> pthread + + + +aix +cygwin +darwin +freebsd +hpux +irix +linux +netbsd +openbsd +qnx +solaris +tru64 + 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 +#include + +#ifndef _POSIX_C_SOURCE + #define _POSIX_C_SOURCE 199506 +#endif + +#include + +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 + +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..a21108c79 --- /dev/null +++ b/Attic/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 + + +mux_qt.cpp +mux_qt.h + + +# I think we want to always use qt-mt, not qt -- not much point in supporting +# mutexes in a single threaded application, after all. + +all -> qt-mt + 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 +#include + +#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 + +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..a2d339c3b --- /dev/null +++ b/Attic/mutex/win32_crit_section/info.txt @@ -0,0 +1,17 @@ +realname "Win32 Mutex" + +define MUTEX_WIN32 +modset win32 + +load_on auto + + +mux_win32.cpp +mux_win32.h + + + +cygwin +windows +mingw + 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 +#include + +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 + +namespace Botan { + +/* +* Win32 Mutex Factory +*/ +class BOTAN_DLL Win32_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; +} + +#endif diff --git a/src/algo_factory/algo_cache.h b/src/algo_factory/algo_cache.h index 17ea9964a..97e14f85a 100644 --- a/src/algo_factory/algo_cache.h +++ b/src/algo_factory/algo_cache.h @@ -5,8 +5,9 @@ #ifndef BOTAN_ALGORITHM_CACHE_TEMPLATE_H__ #define BOTAN_ALGORITHM_CACHE_TEMPLATE_H__ -#include +#include #include +#include #include #include #include @@ -47,7 +48,6 @@ class Algorithm_Cache */ std::vector providers_of(const std::string& algo_name); - Algorithm_Cache(Mutex* m) : mutex(m) {} ~Algorithm_Cache(); private: typedef typename std::map >::iterator @@ -57,7 +57,7 @@ class Algorithm_Cache algorithms_iterator find_algorithm(const std::string& algo_spec); - Mutex* mutex; + std::mutex mutex; std::map aliases; std::map pref_providers; std::map > algorithms; @@ -93,7 +93,7 @@ template const T* Algorithm_Cache::get(const std::string& algo_spec, const std::string& requested_provider) { - Mutex_Holder lock(mutex); + std::lock_guard lock(mutex); algorithms_iterator algo = find_algorithm(algo_spec); if(algo == algorithms.end()) // algo not found at all (no providers) @@ -145,7 +145,7 @@ void Algorithm_Cache::add(T* algo, if(!algo) return; - Mutex_Holder lock(mutex); + std::lock_guard lock(mutex); delete algorithms[algo->name()][provider]; algorithms[algo->name()][provider] = algo; @@ -163,7 +163,7 @@ void Algorithm_Cache::add(T* algo, template std::vector Algorithm_Cache::providers_of(const std::string& algo_name) { - Mutex_Holder lock(mutex); + std::lock_guard lock(mutex); std::vector providers; @@ -190,7 +190,7 @@ template void Algorithm_Cache::set_preferred_provider(const std::string& algo_spec, const std::string& provider) { - Mutex_Holder lock(mutex); + std::lock_guard lock(mutex); pref_providers[algo_spec] = provider; } @@ -215,8 +215,6 @@ Algorithm_Cache::~Algorithm_Cache() ++algo; } - - delete mutex; } } diff --git a/src/algo_factory/algo_factory.cpp b/src/algo_factory/algo_factory.cpp index 269c58c3b..71bd26827 100644 --- a/src/algo_factory/algo_factory.cpp +++ b/src/algo_factory/algo_factory.cpp @@ -80,15 +80,14 @@ const T* factory_prototype(const std::string& algo_spec, /** * Setup caches */ -Algorithm_Factory::Algorithm_Factory(const std::vector& engines_in, - Mutex_Factory& mf) +Algorithm_Factory::Algorithm_Factory(const std::vector& engines_in) { engines = engines_in; - block_cipher_cache = new Algorithm_Cache(mf.make()); - stream_cipher_cache = new Algorithm_Cache(mf.make()); - hash_cache = new Algorithm_Cache(mf.make()); - mac_cache = new Algorithm_Cache(mf.make()); + block_cipher_cache = new Algorithm_Cache(); + stream_cipher_cache = new Algorithm_Cache(); + hash_cache = new Algorithm_Cache(); + mac_cache = new Algorithm_Cache(); } /** diff --git a/src/algo_factory/algo_factory.h b/src/algo_factory/algo_factory.h index 73e592013..1f4b577ee 100644 --- a/src/algo_factory/algo_factory.h +++ b/src/algo_factory/algo_factory.h @@ -8,7 +8,7 @@ #ifndef BOTAN_ALGORITHM_FACTORY_H__ #define BOTAN_ALGORITHM_FACTORY_H__ -#include +#include #include #include @@ -37,8 +37,7 @@ class BOTAN_DLL Algorithm_Factory * @param engines_in the list of engines to use * @param mf a mutex factory */ - Algorithm_Factory(const std::vector& engines_in, - Mutex_Factory& mf); + Algorithm_Factory(const std::vector& engines_in); /** * Destructor diff --git a/src/alloc/alloc_mmap/mmap_mem.h b/src/alloc/alloc_mmap/mmap_mem.h index bef166a16..30e6d9ebb 100644 --- a/src/alloc/alloc_mmap/mmap_mem.h +++ b/src/alloc/alloc_mmap/mmap_mem.h @@ -18,7 +18,6 @@ namespace Botan { class BOTAN_DLL MemoryMapping_Allocator : public Pooling_Allocator { public: - MemoryMapping_Allocator(Mutex* m) : Pooling_Allocator(m) {} std::string type() const { return "mmap"; } private: void* alloc_block(u32bit); diff --git a/src/alloc/mem_pool/mem_pool.cpp b/src/alloc/mem_pool/mem_pool.cpp index 38e0c3285..a3858add6 100644 --- a/src/alloc/mem_pool/mem_pool.cpp +++ b/src/alloc/mem_pool/mem_pool.cpp @@ -109,7 +109,7 @@ void Pooling_Allocator::Memory_Block::free(void* ptr, u32bit blocks) throw() /* * Pooling_Allocator Constructor */ -Pooling_Allocator::Pooling_Allocator(Mutex* m) : mutex(m) +Pooling_Allocator::Pooling_Allocator() { last_used = blocks.begin(); } @@ -119,7 +119,6 @@ Pooling_Allocator::Pooling_Allocator(Mutex* m) : mutex(m) */ Pooling_Allocator::~Pooling_Allocator() { - delete mutex; if(blocks.size()) throw Invalid_State("Pooling_Allocator: Never released memory"); } @@ -129,7 +128,7 @@ Pooling_Allocator::~Pooling_Allocator() */ void Pooling_Allocator::destroy() { - Mutex_Holder lock(mutex); + std::lock_guard lock(mutex); blocks.clear(); @@ -146,7 +145,7 @@ void* Pooling_Allocator::allocate(u32bit n) const u32bit BITMAP_SIZE = Memory_Block::bitmap_size(); const u32bit BLOCK_SIZE = Memory_Block::block_size(); - Mutex_Holder lock(mutex); + std::lock_guard lock(mutex); if(n <= BITMAP_SIZE * BLOCK_SIZE) { @@ -183,7 +182,7 @@ void Pooling_Allocator::deallocate(void* ptr, u32bit n) if(ptr == 0 && n == 0) return; - Mutex_Holder lock(mutex); + std::lock_guard lock(mutex); if(n > BITMAP_SIZE * BLOCK_SIZE) dealloc_block(ptr, n); diff --git a/src/alloc/mem_pool/mem_pool.h b/src/alloc/mem_pool/mem_pool.h index a57800972..871f135bd 100644 --- a/src/alloc/mem_pool/mem_pool.h +++ b/src/alloc/mem_pool/mem_pool.h @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include @@ -27,7 +27,7 @@ class BOTAN_DLL Pooling_Allocator : public Allocator void destroy(); - Pooling_Allocator(Mutex*); + Pooling_Allocator(); ~Pooling_Allocator(); private: void get_more_core(u32bit); @@ -66,7 +66,7 @@ class BOTAN_DLL Pooling_Allocator : public Allocator std::vector blocks; std::vector::iterator last_used; std::vector > allocated; - Mutex* mutex; + std::mutex mutex; }; } diff --git a/src/alloc/system_alloc/defalloc.h b/src/alloc/system_alloc/defalloc.h index 627e8df70..ed2682ec0 100644 --- a/src/alloc/system_alloc/defalloc.h +++ b/src/alloc/system_alloc/defalloc.h @@ -30,8 +30,6 @@ class BOTAN_DLL Malloc_Allocator : public Allocator class BOTAN_DLL Locking_Allocator : public Pooling_Allocator { public: - Locking_Allocator(Mutex* m) : Pooling_Allocator(m) {} - std::string type() const { return "locking"; } private: void* alloc_block(u32bit); diff --git a/src/libstate/init.cpp b/src/libstate/init.cpp index b908de6c7..0d9a2420c 100644 --- a/src/libstate/init.cpp +++ b/src/libstate/init.cpp @@ -1,12 +1,11 @@ /** * Default Initialization Function -* (C) 1999-2007 Jack Lloyd +* (C) 1999-2009 Jack Lloyd * * Distributed under the terms of the Botan license */ #include -#include #include namespace Botan { @@ -14,36 +13,8 @@ namespace Botan { /* * Library Initialization */ -void LibraryInitializer::initialize(const std::string& arg_string) +void LibraryInitializer::initialize(const std::string&) { - bool thread_safe = false; - - const std::vector arg_list = split_on(arg_string, ' '); - for(u32bit j = 0; j != arg_list.size(); ++j) - { - if(arg_list[j].size() == 0) - continue; - - std::string name, value; - - if(arg_list[j].find('=') == std::string::npos) - { - name = arg_list[j]; - value = "true"; - } - else - { - std::vector name_and_value = split_on(arg_list[j], '='); - name = name_and_value[0]; - value = name_and_value[1]; - } - - bool is_on = - (value == "1" || value == "true" || value == "yes" || value == "on"); - - if(name == "thread_safe") - thread_safe = is_on; - } try { @@ -55,7 +26,7 @@ void LibraryInitializer::initialize(const std::string& arg_string) */ set_global_state(new Library_State); - global_state().initialize(thread_safe); + global_state().initialize(); } catch(...) { diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp index 3275c6493..839d71d60 100644 --- a/src/libstate/libstate.cpp +++ b/src/libstate/libstate.cpp @@ -9,21 +9,12 @@ #include #include #include -#include #include #include #include #include #include -#if defined(BOTAN_HAS_MUTEX_PTHREAD) - #include -#elif defined(BOTAN_HAS_MUTEX_WIN32) - #include -#elif defined(BOTAN_HAS_MUTEX_QT) - #include -#endif - #if defined(BOTAN_HAS_ALLOC_MMAP) #include #endif @@ -91,20 +82,12 @@ Library_State* swap_global_state(Library_State* new_state) return old_state; } -/* -* Get a new mutex object -*/ -Mutex* Library_State::get_mutex() const - { - return mutex_factory->make(); - } - /* * Get an allocator by its name */ -Allocator* Library_State::get_allocator(const std::string& type) const +Allocator* Library_State::get_allocator(const std::string& type) { - Mutex_Holder lock(allocator_lock); + std::lock_guard lock(allocator_lock); if(type != "") return search_map(alloc_factory, type, 0); @@ -128,7 +111,7 @@ Allocator* Library_State::get_allocator(const std::string& type) const */ void Library_State::add_allocator(Allocator* allocator) { - Mutex_Holder lock(allocator_lock); + std::lock_guard lock(allocator_lock); allocator->init(); @@ -141,7 +124,7 @@ void Library_State::add_allocator(Allocator* allocator) */ void Library_State::set_default_allocator(const std::string& type) { - Mutex_Holder lock(allocator_lock); + std::lock_guard lock(allocator_lock); if(type == "") return; @@ -154,9 +137,9 @@ void Library_State::set_default_allocator(const std::string& type) * Get a configuration value */ std::string Library_State::get(const std::string& section, - const std::string& key) const + const std::string& key) { - Mutex_Holder lock(config_lock); + std::lock_guard lock(config_lock); return search_map(config, section + "/" + key, ""); @@ -166,9 +149,9 @@ std::string Library_State::get(const std::string& section, * See if a particular option has been set */ bool Library_State::is_set(const std::string& section, - const std::string& key) const + const std::string& key) { - Mutex_Holder lock(config_lock); + std::lock_guard lock(config_lock); return search_map(config, section + "/" + key, false, true); } @@ -179,7 +162,7 @@ bool Library_State::is_set(const std::string& section, void Library_State::set(const std::string& section, const std::string& key, const std::string& value, bool overwrite) { - Mutex_Holder lock(config_lock); + std::lock_guard lock(config_lock); std::string full_key = section + "/" + key; @@ -201,7 +184,7 @@ void Library_State::add_alias(const std::string& key, const std::string& value) /* * Dereference an alias to a fixed name */ -std::string Library_State::deref_alias(const std::string& key) const +std::string Library_State::deref_alias(const std::string& key) { std::string result = key; while(is_set("alias", result)) @@ -221,7 +204,7 @@ void Library_State::set_option(const std::string key, /* * Get an option value */ -std::string Library_State::option(const std::string& key) const +std::string Library_State::option(const std::string& key) { return get("conf", key); } @@ -239,38 +222,18 @@ Algorithm_Factory& Library_State::algorithm_factory() /* * Load a set of modules */ -void Library_State::initialize(bool thread_safe) +void Library_State::initialize() { - if(mutex_factory) + if(m_algorithm_factory) throw Invalid_State("Library_State has already been initialized"); - if(!thread_safe) - { - mutex_factory = new Noop_Mutex_Factory; - } - else - { -#if defined(BOTAN_HAS_MUTEX_PTHREAD) - mutex_factory = new Pthread_Mutex_Factory; -#elif defined(BOTAN_HAS_MUTEX_WIN32) - mutex_factory = new Win32_Mutex_Factory; -#elif defined(BOTAN_HAS_MUTEX_QT) - mutex_factory Qt_Mutex_Factory; -#else - throw Invalid_State("Could not find a thread-safe mutex object to use"); -#endif - } - - allocator_lock = mutex_factory->make(); - config_lock = mutex_factory->make(); - cached_default_allocator = 0; add_allocator(new Malloc_Allocator); - add_allocator(new Locking_Allocator(mutex_factory->make())); + add_allocator(new Locking_Allocator); #if defined(BOTAN_HAS_ALLOC_MMAP) - add_allocator(new MemoryMapping_Allocator(mutex_factory->make())); + add_allocator(new MemoryMapping_Allocator); #endif set_default_allocator("locking"); @@ -301,7 +264,7 @@ void Library_State::initialize(bool thread_safe) engines.push_back(new Default_Engine); - m_algorithm_factory = new Algorithm_Factory(engines, *mutex_factory); + m_algorithm_factory = new Algorithm_Factory(engines); } /* @@ -309,8 +272,6 @@ void Library_State::initialize(bool thread_safe) */ Library_State::Library_State() { - mutex_factory = 0; - allocator_lock = config_lock = 0; cached_default_allocator = 0; m_algorithm_factory = 0; } @@ -321,6 +282,7 @@ Library_State::Library_State() Library_State::~Library_State() { delete m_algorithm_factory; + m_algorithm_factory = 0; cached_default_allocator = 0; @@ -329,10 +291,6 @@ Library_State::~Library_State() allocators[j]->destroy(); delete allocators[j]; } - - delete allocator_lock; - delete mutex_factory; - delete config_lock; } } diff --git a/src/libstate/libstate.h b/src/libstate/libstate.h index 2493863a9..eb3b3b3be 100644 --- a/src/libstate/libstate.h +++ b/src/libstate/libstate.h @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -27,11 +28,11 @@ class BOTAN_DLL Library_State Library_State(); ~Library_State(); - void initialize(bool thread_safe); + void initialize(); Algorithm_Factory& algorithm_factory(); - Allocator* get_allocator(const std::string& = "") const; + Allocator* get_allocator(const std::string& = ""); void add_allocator(Allocator*); void set_default_allocator(const std::string&); @@ -42,7 +43,7 @@ class BOTAN_DLL Library_State * @result the value of the parameter */ std::string get(const std::string& section, - const std::string& key) const; + const std::string& key); /** * Check whether a certain parameter is set @@ -52,7 +53,7 @@ class BOTAN_DLL Library_State * @result true if the parameters value is set, * false otherwise */ - bool is_set(const std::string& section, const std::string& key) const; + bool is_set(const std::string& section, const std::string& key); /** * Set a configuration parameter. @@ -70,7 +71,7 @@ class BOTAN_DLL Library_State * referred to as option). * @param key the desired keys name */ - std::string option(const std::string& key) const; + std::string option(const std::string& key); /** * Set an option. @@ -91,21 +92,17 @@ class BOTAN_DLL Library_State * @param alias the alias to resolve. * @return what the alias stands for */ - std::string deref_alias(const std::string&) const; - - class Mutex* get_mutex() const; + std::string deref_alias(const std::string&); private: void load_default_config(); Library_State(const Library_State&) {} Library_State& operator=(const Library_State&) { return (*this); } - class Mutex_Factory* mutex_factory; - + std::mutex config_lock; std::map config; - class Mutex* config_lock; - class Mutex* allocator_lock; + std::mutex allocator_lock; std::map alloc_factory; mutable Allocator* cached_default_allocator; std::vector allocators; diff --git a/src/mutex/noop_mutex/info.txt b/src/mutex/noop_mutex/info.txt deleted file mode 100644 index 1f49f5e1c..000000000 --- a/src/mutex/noop_mutex/info.txt +++ /dev/null @@ -1,10 +0,0 @@ -realname "No-Op Mutex" - -load_on auto - -define MUTEX_NOOP - - -mux_noop.cpp -mux_noop.h - diff --git a/src/mutex/noop_mutex/mux_noop.cpp b/src/mutex/noop_mutex/mux_noop.cpp deleted file mode 100644 index 5c45084fe..000000000 --- a/src/mutex/noop_mutex/mux_noop.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* -* No-Op Mutex Factory -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include - -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/mutex/noop_mutex/mux_noop.h b/src/mutex/noop_mutex/mux_noop.h deleted file mode 100644 index 94201cb7c..000000000 --- a/src/mutex/noop_mutex/mux_noop.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -* 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 - -namespace Botan { - -/* -* No-Op Mutex Factory -*/ -class BOTAN_DLL Noop_Mutex_Factory : public Mutex_Factory - { - public: - Mutex* make(); - }; - -} - -#endif diff --git a/src/mutex/pthreads/info.txt b/src/mutex/pthreads/info.txt deleted file mode 100644 index 88de70de0..000000000 --- a/src/mutex/pthreads/info.txt +++ /dev/null @@ -1,29 +0,0 @@ -realname "Pthread Mutex" - -define MUTEX_PTHREAD - -load_on auto - - -mux_pthr.cpp -mux_pthr.h - - - -all!qnx,freebsd,openbsd,netbsd -> pthread - - - -aix -cygwin -darwin -freebsd -hpux -irix -linux -netbsd -openbsd -qnx -solaris -tru64 - diff --git a/src/mutex/pthreads/mux_pthr.cpp b/src/mutex/pthreads/mux_pthr.cpp deleted file mode 100644 index 9f1d9816e..000000000 --- a/src/mutex/pthreads/mux_pthr.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* -* Pthread Mutex -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include -#include - -#ifndef _POSIX_C_SOURCE - #define _POSIX_C_SOURCE 199506 -#endif - -#include - -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/mutex/pthreads/mux_pthr.h b/src/mutex/pthreads/mux_pthr.h deleted file mode 100644 index 118853947..000000000 --- a/src/mutex/pthreads/mux_pthr.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -* 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 - -namespace Botan { - -/* -* Pthread Mutex Factory -*/ -class BOTAN_DLL Pthread_Mutex_Factory : public Mutex_Factory - { - public: - Mutex* make(); - }; - -} - -#endif diff --git a/src/mutex/qt_mutex/info.txt b/src/mutex/qt_mutex/info.txt deleted file mode 100644 index a21108c79..000000000 --- a/src/mutex/qt_mutex/info.txt +++ /dev/null @@ -1,18 +0,0 @@ -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 - - -mux_qt.cpp -mux_qt.h - - -# I think we want to always use qt-mt, not qt -- not much point in supporting -# mutexes in a single threaded application, after all. - -all -> qt-mt - diff --git a/src/mutex/qt_mutex/mux_qt.cpp b/src/mutex/qt_mutex/mux_qt.cpp deleted file mode 100644 index 0f670c8b4..000000000 --- a/src/mutex/qt_mutex/mux_qt.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* -* Qt Thread Mutex -* (C) 2004-2007 Justin Karneges -* 2004-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include -#include - -#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/mutex/qt_mutex/mux_qt.h b/src/mutex/qt_mutex/mux_qt.h deleted file mode 100644 index 5aed77f4b..000000000 --- a/src/mutex/qt_mutex/mux_qt.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -* 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 - -namespace Botan { - -/* -* Qt Mutex -*/ -class BOTAN_DLL Qt_Mutex_Factory : public Mutex_Factory - { - public: - Mutex* make(); - }; - -} - -#endif diff --git a/src/mutex/win32_crit_section/info.txt b/src/mutex/win32_crit_section/info.txt deleted file mode 100644 index a2d339c3b..000000000 --- a/src/mutex/win32_crit_section/info.txt +++ /dev/null @@ -1,17 +0,0 @@ -realname "Win32 Mutex" - -define MUTEX_WIN32 -modset win32 - -load_on auto - - -mux_win32.cpp -mux_win32.h - - - -cygwin -windows -mingw - diff --git a/src/mutex/win32_crit_section/mux_win32.cpp b/src/mutex/win32_crit_section/mux_win32.cpp deleted file mode 100644 index 2a967892b..000000000 --- a/src/mutex/win32_crit_section/mux_win32.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* -* Win32 Mutex -* (C) 2006 Luca Piccarreta -* 2006-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include -#include - -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/mutex/win32_crit_section/mux_win32.h b/src/mutex/win32_crit_section/mux_win32.h deleted file mode 100644 index a91850e71..000000000 --- a/src/mutex/win32_crit_section/mux_win32.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -* 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 - -namespace Botan { - -/* -* Win32 Mutex Factory -*/ -class BOTAN_DLL Win32_Mutex_Factory : public Mutex_Factory - { - public: - Mutex* make(); - }; -} - -#endif diff --git a/src/utils/info.txt b/src/utils/info.txt index ffc19c852..815ad4efc 100644 --- a/src/utils/info.txt +++ b/src/utils/info.txt @@ -27,7 +27,6 @@ exceptn.h loadstor.h mem_ops.h mlock.cpp -mutex.h parsing.cpp parsing.h rotate.h diff --git a/src/utils/mutex.h b/src/utils/mutex.h deleted file mode 100644 index a04ff83c9..000000000 --- a/src/utils/mutex.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -* Mutex -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_MUTEX_H__ -#define BOTAN_MUTEX_H__ - -#include - -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/src/utils/scan_name.cpp b/src/utils/scan_name.cpp index 3425425e2..92fded3c4 100644 --- a/src/utils/scan_name.cpp +++ b/src/utils/scan_name.cpp @@ -8,6 +8,7 @@ SCAN Name Abstraction #include #include #include +#include #include #include -- cgit v1.2.3 From 515faa2ef86221f08fa2ef4f9eae66126d151e06 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 1 Apr 2009 15:48:16 +0000 Subject: Remove copy_if, now included in C++0x (also, it turns out, not being used in the source). --- src/utils/stl_util.h | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'src') diff --git a/src/utils/stl_util.h b/src/utils/stl_util.h index 18c8b149b..fc4d4effe 100644 --- a/src/utils/stl_util.h +++ b/src/utils/stl_util.h @@ -12,22 +12,6 @@ namespace Botan { -/* -* Copy-on-Predicate Algorithm -*/ -template -OutputIterator copy_if(InputIterator current, InputIterator end, - OutputIterator dest, Predicate copy_p) - { - while(current != end) - { - if(copy_p(*current)) - *dest++ = *current; - ++current; - } - return dest; - } - /* * Searching through a std::map */ -- cgit v1.2.3 From 62b2008ec3041441a70b8396c7fabba90e42c546 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 1 Apr 2009 16:26:02 +0000 Subject: A few experiments with auto keyword type inference. Looks like things will be much cleaner, though I am looking forward to the new for syntax which will simplify a lot of these uses further. --- src/asn1/asn1_dn.cpp | 70 ++++++++++++++++-------------------------- src/hash/par_hash/par_hash.cpp | 41 ++++++++++++++----------- src/utils/parsing.cpp | 36 +++++++++++----------- 3 files changed, 68 insertions(+), 79 deletions(-) (limited to 'src') diff --git a/src/asn1/asn1_dn.cpp b/src/asn1/asn1_dn.cpp index c5a132d85..dd5bc94dc 100644 --- a/src/asn1/asn1_dn.cpp +++ b/src/asn1/asn1_dn.cpp @@ -26,9 +26,8 @@ X509_DN::X509_DN() */ X509_DN::X509_DN(const std::multimap& args) { - std::multimap::const_iterator j; - for(j = args.begin(); j != args.end(); ++j) - add_attribute(j->first, j->second); + for(auto i = args.begin(); i != args.end(); ++i) + add_attribute(i->first, i->second); } /* @@ -36,9 +35,8 @@ X509_DN::X509_DN(const std::multimap& args) */ X509_DN::X509_DN(const std::multimap& args) { - std::multimap::const_iterator j; - for(j = args.begin(); j != args.end(); ++j) - add_attribute(OIDS::lookup(j->first), j->second); + for(auto i = args.begin(); i != args.end(); ++i) + add_attribute(OIDS::lookup(i->first), i->second); } /* @@ -59,11 +57,9 @@ void X509_DN::add_attribute(const OID& oid, const std::string& str) if(str == "") return; - typedef std::multimap::iterator rdn_iter; - - std::pair range = dn_info.equal_range(oid); - for(rdn_iter j = range.first; j != range.second; ++j) - if(j->second.value() == str) + auto range = dn_info.equal_range(oid); + for(auto i = range.first; i != range.second; ++i) + if(i->second.value() == str) return; multimap_insert(dn_info, oid, ASN1_String(str)); @@ -75,11 +71,9 @@ void X509_DN::add_attribute(const OID& oid, const std::string& str) */ std::multimap X509_DN::get_attributes() const { - typedef std::multimap::const_iterator rdn_iter; - std::multimap retval; - for(rdn_iter j = dn_info.begin(); j != dn_info.end(); ++j) - multimap_insert(retval, j->first, j->second.value()); + for(auto i = dn_info.begin(); i != dn_info.end(); ++i) + multimap_insert(retval, i->first, i->second.value()); return retval; } @@ -88,11 +82,9 @@ std::multimap X509_DN::get_attributes() const */ std::multimap X509_DN::contents() const { - typedef std::multimap::const_iterator rdn_iter; - std::multimap retval; - for(rdn_iter j = dn_info.begin(); j != dn_info.end(); ++j) - multimap_insert(retval, OIDS::lookup(j->first), j->second.value()); + for(auto i = dn_info.begin(); i != dn_info.end(); ++i) + multimap_insert(retval, OIDS::lookup(i->first), i->second.value()); return retval; } @@ -101,14 +93,13 @@ std::multimap X509_DN::contents() const */ std::vector X509_DN::get_attribute(const std::string& attr) const { - typedef std::multimap::const_iterator rdn_iter; - const OID oid = OIDS::lookup(deref_info_field(attr)); - std::pair range = dn_info.equal_range(oid); + + auto range = dn_info.equal_range(oid); std::vector values; - for(rdn_iter j = range.first; j != range.second; ++j) - values.push_back(j->second.value()); + for(auto i = range.first; i != range.second; ++i) + values.push_back(i->second.value()); return values; } @@ -171,15 +162,13 @@ std::string X509_DN::deref_info_field(const std::string& info) */ bool operator==(const X509_DN& dn1, const X509_DN& dn2) { - typedef std::multimap::const_iterator rdn_iter; - - std::multimap attr1 = dn1.get_attributes(); - std::multimap attr2 = dn2.get_attributes(); + auto attr1 = dn1.get_attributes(); + auto attr2 = dn2.get_attributes(); if(attr1.size() != attr2.size()) return false; - rdn_iter p1 = attr1.begin(); - rdn_iter p2 = attr2.begin(); + auto p1 = attr1.begin(); + auto p2 = attr2.begin(); while(true) { @@ -209,18 +198,15 @@ bool operator!=(const X509_DN& dn1, const X509_DN& dn2) */ bool operator<(const X509_DN& dn1, const X509_DN& dn2) { - typedef std::multimap::const_iterator rdn_iter; - - std::multimap attr1 = dn1.get_attributes(); - std::multimap attr2 = dn2.get_attributes(); + auto attr1 = dn1.get_attributes(); + auto attr2 = dn2.get_attributes(); if(attr1.size() < attr2.size()) return true; if(attr1.size() > attr2.size()) return false; - for(rdn_iter p1 = attr1.begin(); p1 != attr1.end(); ++p1) + for(auto p1 = attr1.begin(); p1 != attr1.end(); ++p1) { - std::multimap::const_iterator p2; - p2 = attr2.find(p1->first); + auto p2 = attr2.find(p1->first); if(p2 == attr2.end()) return false; if(p1->second > p2->second) return false; if(p1->second < p2->second) return true; @@ -238,8 +224,6 @@ void do_ava(DER_Encoder& encoder, ASN1_Tag string_type, const std::string& oid_str, bool must_exist = false) { - typedef std::multimap::const_iterator rdn_iter; - const OID oid = OIDS::lookup(oid_str); const bool exists = (dn_info.find(oid) != dn_info.end()); @@ -247,14 +231,14 @@ void do_ava(DER_Encoder& encoder, throw Encoding_Error("X509_DN: No entry for " + oid_str); if(!exists) return; - std::pair range = dn_info.equal_range(oid); + auto range = dn_info.equal_range(oid); - for(rdn_iter j = range.first; j != range.second; ++j) + for(auto i = range.first; i != range.second; ++i) { encoder.start_cons(SET) .start_cons(SEQUENCE) .encode(oid) - .encode(ASN1_String(j->second, string_type)) + .encode(ASN1_String(i->second, string_type)) .end_cons() .end_cons(); } @@ -267,7 +251,7 @@ void do_ava(DER_Encoder& encoder, */ void X509_DN::encode_into(DER_Encoder& der) const { - std::multimap dn_info = get_attributes(); + auto dn_info = get_attributes(); der.start_cons(SEQUENCE); diff --git a/src/hash/par_hash/par_hash.cpp b/src/hash/par_hash/par_hash.cpp index 4b0c7c466..789238647 100644 --- a/src/hash/par_hash/par_hash.cpp +++ b/src/hash/par_hash/par_hash.cpp @@ -1,6 +1,6 @@ /* * Parallel -* (C) 1999-2007 Jack Lloyd +* (C) 1999-2009 Jack Lloyd * * Distributed under the terms of the Botan license */ @@ -18,8 +18,8 @@ u32bit sum_of_hash_lengths(const std::vector& hashes) { u32bit sum = 0; - for(u32bit j = 0; j != hashes.size(); ++j) - sum += hashes[j]->OUTPUT_LENGTH; + for(auto hash = hashes.begin(); hash != hashes.end(); ++hash) + sum += (*hash)->OUTPUT_LENGTH; return sum; } @@ -31,20 +31,21 @@ u32bit sum_of_hash_lengths(const std::vector& hashes) */ void Parallel::add_data(const byte input[], u32bit length) { - for(u32bit j = 0; j != hashes.size(); ++j) - hashes[j]->update(input, length); + for(auto hash = hashes.begin(); hash != hashes.end(); ++hash) + (*hash)->update(input, length); } /* * Finalize the hash */ -void Parallel::final_result(byte hash[]) +void Parallel::final_result(byte out[]) { u32bit offset = 0; - for(u32bit j = 0; j != hashes.size(); ++j) + + for(auto hash = hashes.begin(); hash != hashes.end(); ++hash) { - hashes[j]->final(hash + offset); - offset += hashes[j]->OUTPUT_LENGTH; + (*hash)->final(out + offset); + offset += (*hash)->OUTPUT_LENGTH; } } @@ -54,12 +55,14 @@ void Parallel::final_result(byte hash[]) std::string Parallel::name() const { std::string hash_names; - for(u32bit j = 0; j != hashes.size(); ++j) + + for(auto hash = hashes.begin(); hash != hashes.end(); ++hash) { - if(j) + if(hash != hashes.begin()) hash_names += ','; - hash_names += hashes[j]->name(); + hash_names += (*hash)->name(); } + return "Parallel(" + hash_names + ")"; } @@ -69,8 +72,10 @@ std::string Parallel::name() const HashFunction* Parallel::clone() const { std::vector hash_copies; - for(u32bit j = 0; j != hashes.size(); ++j) - hash_copies.push_back(hashes[j]->clone()); + + for(auto hash = hashes.begin(); hash != hashes.end(); ++hash) + hash_copies.push_back((*hash)->clone()); + return new Parallel(hash_copies); } @@ -79,8 +84,8 @@ HashFunction* Parallel::clone() const */ void Parallel::clear() throw() { - for(u32bit j = 0; j != hashes.size(); ++j) - hashes[j]->clear(); + for(auto hash = hashes.begin(); hash != hashes.end(); ++hash) + (*hash)->clear(); } /* @@ -96,8 +101,8 @@ Parallel::Parallel(const std::vector& hash_in) : */ Parallel::~Parallel() { - for(u32bit j = 0; j != hashes.size(); ++j) - delete hashes[j]; + for(auto hash = hashes.begin(); hash != hashes.end(); ++hash) + delete (*hash); } } diff --git a/src/utils/parsing.cpp b/src/utils/parsing.cpp index bdb9e79dc..556e2f65c 100644 --- a/src/utils/parsing.cpp +++ b/src/utils/parsing.cpp @@ -19,11 +19,11 @@ u32bit to_u32bit(const std::string& number) { u32bit n = 0; - for(std::string::const_iterator j = number.begin(); j != number.end(); ++j) + for(auto i = number.begin(); i != number.end(); ++i) { const u32bit OVERFLOW_MARK = 0xFFFFFFFF / 10; - byte digit = Charset::char2digit(*j); + byte digit = Charset::char2digit(*i); if((n > OVERFLOW_MARK) || (n == OVERFLOW_MARK && digit > 5)) throw Decoding_Error("to_u32bit: Integer overflow"); @@ -103,15 +103,15 @@ std::vector parse_algorithm_name(const std::string& namex) elems.push_back(name.substr(0, name.find('('))); name = name.substr(name.find('(')); - for(std::string::const_iterator j = name.begin(); j != name.end(); ++j) + for(auto i = name.begin(); i != name.end(); ++i) { - char c = *j; + char c = *i; if(c == '(') ++level; if(c == ')') { - if(level == 1 && j == name.end() - 1) + if(level == 1 && i == name.end() - 1) { if(elems.size() == 1) elems.push_back(substring.substr(1)); @@ -120,7 +120,7 @@ std::vector parse_algorithm_name(const std::string& namex) return elems; } - if(level == 0 || (level == 1 && j != name.end() - 1)) + if(level == 0 || (level == 1 && i != name.end() - 1)) throw Invalid_Algorithm_Name(namex); --level; } @@ -152,16 +152,16 @@ std::vector split_on(const std::string& str, char delim) if(str == "") return elems; std::string substr; - for(std::string::const_iterator j = str.begin(); j != str.end(); ++j) + for(auto i = str.begin(); i != str.end(); ++i) { - if(*j == delim) + if(*i == delim) { if(substr != "") elems.push_back(substr); substr.clear(); } else - substr += *j; + substr += *i; } if(substr == "") @@ -179,9 +179,9 @@ std::vector parse_asn1_oid(const std::string& oid) std::string substring; std::vector oid_elems; - for(std::string::const_iterator j = oid.begin(); j != oid.end(); ++j) + for(auto i = oid.begin(); i != oid.end(); ++i) { - char c = *j; + char c = *i; if(c == '.') { @@ -209,8 +209,8 @@ std::vector parse_asn1_oid(const std::string& oid) */ bool x500_name_cmp(const std::string& name1, const std::string& name2) { - std::string::const_iterator p1 = name1.begin(); - std::string::const_iterator p2 = name2.begin(); + auto p1 = name1.begin(); + auto p2 = name2.begin(); while((p1 != name1.end()) && Charset::is_space(*p1)) ++p1; while((p2 != name2.end()) && Charset::is_space(*p2)) ++p2; @@ -255,9 +255,9 @@ u32bit string_to_ipv4(const std::string& str) u32bit ip = 0; - for(size_t j = 0; j != parts.size(); j++) + for(auto part = parts.begin(); part != parts.end(); ++part) { - u32bit octet = to_u32bit(parts[j]); + u32bit octet = to_u32bit(*part); if(octet > 255) throw Decoding_Error("Invalid IP string " + str); @@ -275,11 +275,11 @@ std::string ipv4_to_string(u32bit ip) { std::string str; - for(size_t j = 0; j != sizeof(ip); j++) + for(size_t i = 0; i != sizeof(ip); i++) { - if(j) + if(i) str += "."; - str += to_string(get_byte(j, ip)); + str += to_string(get_byte(i, ip)); } return str; -- cgit v1.2.3 From 327115405b0f483c2b432e2233f355a349b1f9d7 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 1 Apr 2009 16:38:08 +0000 Subject: Replace the (deprecated) auto_ptr with unique_ptr. This was mostly a s/auto_ptr/unique_ptr/, except in the CVC code and one function in ECDSA, which relied on auto_ptr's move semantics (ugh) and had to be modified in various ways. --- checks/cvc_tests.cpp | 18 +++++++-------- checks/ec_tests.cpp | 4 ++-- checks/ecdsa.cpp | 34 +++++++++++++-------------- checks/eckaeg.cpp | 2 +- checks/pk.cpp | 16 ++++++------- checks/pk_bench.cpp | 24 +++++++++---------- checks/x509.cpp | 2 +- src/cert/cvc/cvc_ado.cpp | 4 ++-- src/cert/cvc/cvc_ado.h | 2 +- src/cert/cvc/cvc_ca.cpp | 2 +- src/cert/cvc/cvc_ca.h | 2 +- src/cert/cvc/cvc_cert.cpp | 2 +- src/cert/cvc/cvc_gen_cert.h | 12 +++++----- src/cert/cvc/cvc_req.cpp | 2 +- src/cert/cvc/cvc_self.cpp | 47 +++++++++++++++++++++++--------------- src/cert/cvc/eac_obj.h | 10 ++++---- src/cert/cvc/ecdsa_sig.cpp | 2 +- src/cert/x509/x509_ca.cpp | 4 ++-- src/cert/x509/x509_obj.cpp | 2 +- src/cert/x509/x509self.cpp | 4 ++-- src/cert/x509/x509stor.cpp | 4 ++-- src/math/numbertheory/dsa_gen.cpp | 2 +- src/pubkey/ec_dompar/ec_dompar.cpp | 2 +- src/pubkey/ecc_key/ecc_key.cpp | 2 +- src/pubkey/ecc_key/ecc_key.h | 4 ++-- src/pubkey/ecdsa/ecdsa.cpp | 11 ++++----- src/pubkey/eckaeg/eckaeg.cpp | 4 ++-- src/pubkey/eckaeg/eckaeg.h | 2 +- src/pubkey/keypair/keypair.cpp | 8 +++---- src/pubkey/pubkey/pkcs8.cpp | 10 ++++---- src/pubkey/pubkey/x509_key.cpp | 6 ++--- 31 files changed, 129 insertions(+), 121 deletions(-) (limited to 'src') diff --git a/checks/cvc_tests.cpp b/checks/cvc_tests.cpp index 792e9c58d..cde8c8b2c 100644 --- a/checks/cvc_tests.cpp +++ b/checks/cvc_tests.cpp @@ -163,8 +163,8 @@ void test_enc_gen_selfsigned(RandomNumberGenerator& rng) } CHECK(ill_date_exc2); //cout << "readable = '" << cert_in.get_ced().readable_string() << "'\n"; - std::auto_ptr p_pk = cert_in.subject_public_key(); - //auto_ptr ecdsa_pk = dynamic_cast >(p_pk); + std::unique_ptr p_pk = cert_in.subject_public_key(); + //unique_ptr ecdsa_pk = dynamic_cast >(p_pk); ECDSA_PublicKey* p_ecdsa_pk = dynamic_cast(p_pk.get()); // let´s see if encoding is truely implicitca, because this is what the key should have // been set to when decoding (see above)(because it has no domain params): @@ -182,7 +182,7 @@ void test_enc_gen_selfsigned(RandomNumberGenerator& rng) CHECK(exc); // set them and try again //cert_in.set_domain_parameters(dom_pars); - std::auto_ptr p_pk2 = cert_in.subject_public_key(); + std::unique_ptr p_pk2 = cert_in.subject_public_key(); ECDSA_PublicKey* p_ecdsa_pk2 = dynamic_cast(p_pk2.get()); p_ecdsa_pk2->set_domain_parameters(dom_pars); CHECK(p_ecdsa_pk2->domain_parameters().get_order() == dom_pars.get_order()); @@ -213,7 +213,7 @@ void test_enc_gen_req(RandomNumberGenerator& rng) // read and check signature... EAC1_1_Req req_in(TEST_DATA_DIR "/my_cv_req.ber"); //req_in.set_domain_parameters(dom_pars); - std::auto_ptr p_pk = req_in.subject_public_key(); + std::unique_ptr p_pk = req_in.subject_public_key(); ECDSA_PublicKey* p_ecdsa_pk = dynamic_cast(p_pk.get()); p_ecdsa_pk->set_domain_parameters(dom_pars); CHECK(p_ecdsa_pk->domain_parameters().get_order() == dom_pars.get_order()); @@ -228,7 +228,7 @@ void test_cvc_req_ext(RandomNumberGenerator&) EAC1_1_Req req_in(TEST_DATA_DIR "/DE1_flen_chars_cvcRequest_ECDSA.der"); EC_Domain_Params dom_pars(get_EC_Dom_Pars_by_oid("1.3.36.3.3.2.8.1.1.5")); // "german curve" //req_in.set_domain_parameters(dom_pars); - std::auto_ptr p_pk = req_in.subject_public_key(); + std::unique_ptr p_pk = req_in.subject_public_key(); ECDSA_PublicKey* p_ecdsa_pk = dynamic_cast(p_pk.get()); p_ecdsa_pk->set_domain_parameters(dom_pars); CHECK(p_ecdsa_pk->domain_parameters().get_order() == dom_pars.get_order()); @@ -390,11 +390,11 @@ void test_ver_cvca(RandomNumberGenerator&) EAC1_1_CVC req_in(TEST_DATA_DIR "/cvca01.cv.crt"); - //auto_ptr ecdsa_pk = dynamic_cast >(p_pk); + //unique_ptr ecdsa_pk = dynamic_cast >(p_pk); //ECDSA_PublicKey* p_ecdsa_pk = dynamic_cast(p_pk.get()); bool exc = false; - std::auto_ptr p_pk2 = req_in.subject_public_key(); + std::unique_ptr p_pk2 = req_in.subject_public_key(); ECDSA_PublicKey* p_ecdsa_pk2 = dynamic_cast(p_pk2.get()); bool ver_ec = req_in.check_signature(*p_pk2); CHECK_MESSAGE(ver_ec, "could not positively verify correct selfsigned cvca certificate"); @@ -512,7 +512,7 @@ void test_cvc_chain(RandomNumberGenerator& rng) CHECK(link12.check_signature(cvca_privk)); EAC1_1_CVC link12_reloaded(TEST_DATA_DIR "/cvc_chain_link12.cer"); EAC1_1_CVC cvca1_reloaded(TEST_DATA_DIR "/cvc_chain_cvca.cer"); - std::auto_ptr cvca1_rel_pk = cvca1_reloaded.subject_public_key(); + std::unique_ptr cvca1_rel_pk = cvca1_reloaded.subject_public_key(); CHECK(link12_reloaded.check_signature(*cvca1_rel_pk)); // create first round dvca-req @@ -542,7 +542,7 @@ void test_cvc_chain(RandomNumberGenerator& rng) // verify the ado and sign the request too - std::auto_ptr ap_pk = dvca_cert1.subject_public_key(); + std::unique_ptr ap_pk = dvca_cert1.subject_public_key(); ECDSA_PublicKey* cert_pk = dynamic_cast(ap_pk.get()); cert_pk->set_domain_parameters(dom_pars); diff --git a/checks/ec_tests.cpp b/checks/ec_tests.cpp index 2d25e2153..b079ebd47 100644 --- a/checks/ec_tests.cpp +++ b/checks/ec_tests.cpp @@ -794,11 +794,11 @@ void test_enc_dec_uncompressed_521_prime_too_large() BigInt bi_b_secp = BigInt::decode ( sv_b_secp.begin(), sv_b_secp.size() ); CurveGFp secp521r1 ( GFpElement ( bi_p_secp,bi_a_secp ), GFpElement ( bi_p_secp, bi_b_secp ), bi_p_secp ); - std::auto_ptr p_G; + std::unique_ptr p_G; bool exc = false; try { - p_G = std::auto_ptr(new PointGFp(OS2ECP ( sv_G_secp_uncomp, secp521r1))); + p_G = std::unique_ptr(new PointGFp(OS2ECP ( sv_G_secp_uncomp, secp521r1))); p_G->check_invariants(); } catch (std::exception e) diff --git a/checks/ecdsa.cpp b/checks/ecdsa.cpp index 532a1c546..37880b755 100644 --- a/checks/ecdsa.cpp +++ b/checks/ecdsa.cpp @@ -70,7 +70,7 @@ void test_hash_larger_than_n(RandomNumberGenerator& rng) { format = "EMSA1_BSI(SHA-1)"; } - std::auto_ptr pk_signer(get_pk_signer(priv_key, format)); + std::unique_ptr pk_signer(get_pk_signer(priv_key, format)); SecureVector signature; bool sig_exc = false; try @@ -93,7 +93,7 @@ void test_hash_larger_than_n(RandomNumberGenerator& rng) if(i==0) // makes no sense to check for sha224 { - std::auto_ptr pk_verifier(get_pk_verifier(priv_key, format)); + std::unique_ptr pk_verifier(get_pk_verifier(priv_key, format)); bool ver = pk_verifier->verify_message(message, signature); CHECK(ver); } @@ -103,10 +103,10 @@ void test_hash_larger_than_n(RandomNumberGenerator& rng) // now check that verification alone fails // sign it with the normal EMSA1 - std::auto_ptr pk_signer(get_pk_signer(priv_key, "EMSA1(SHA-224)")); + std::unique_ptr pk_signer(get_pk_signer(priv_key, "EMSA1(SHA-224)")); SecureVector signature = pk_signer->sign_message(message, rng); - std::auto_ptr pk_verifier(get_pk_verifier(priv_key, "EMSA1_BSI(SHA-224)")); + std::unique_ptr pk_verifier(get_pk_verifier(priv_key, "EMSA1_BSI(SHA-224)")); // verify against EMSA1_BSI // we make sure it doesn't fail because of the invalid signature, @@ -164,7 +164,7 @@ void test_decode_ecdsa_X509() CHECK_MESSAGE(to_hex(cert.authority_key_id()) == "0096452DE588F966C4CCDF161DD1F3F5341B71E7", "error reading authority key id from x509 ecdsa certificate"); CHECK_MESSAGE(to_hex(cert.subject_key_id()) == "0096452DE588F966C4CCDF161DD1F3F5341B71E7", "error reading Subject key id from x509 ecdsa certificate"); - std::auto_ptr pubkey(cert.subject_public_key()); + std::unique_ptr pubkey(cert.subject_public_key()); bool ver_ec = cert.check_signature(*pubkey); CHECK_MESSAGE(ver_ec, "could not positively verify correct selfsigned x509-ecdsa certificate"); } @@ -176,7 +176,7 @@ void test_decode_ver_link_SHA256() X509_Certificate root_cert(TEST_DATA_DIR "/root2_SHA256.cer"); X509_Certificate link_cert(TEST_DATA_DIR "/link_SHA256.cer"); - std::auto_ptr pubkey(root_cert.subject_public_key()); + std::unique_ptr pubkey(root_cert.subject_public_key()); bool ver_ec = link_cert.check_signature(*pubkey); CHECK_MESSAGE(ver_ec, "could not positively verify correct SHA256 link x509-ecdsa certificate"); @@ -188,7 +188,7 @@ void test_decode_ver_link_SHA1() X509_Certificate root_cert(TEST_DATA_DIR "/root_SHA1.163.crt"); X509_Certificate link_cert(TEST_DATA_DIR "/link_SHA1.166.crt"); - std::auto_ptr pubkey(root_cert.subject_public_key()); + std::unique_ptr pubkey(root_cert.subject_public_key()); bool ver_ec = link_cert.check_signature(*pubkey); CHECK_MESSAGE(ver_ec, "could not positively verify correct SHA1 link x509-ecdsa certificate"); } @@ -231,8 +231,8 @@ bool test_ec_sign(RandomNumberGenerator& rng) ECDSA_PrivateKey priv_key(rng, dom_pars); std::string pem_encoded_key = PKCS8::PEM_encode(priv_key); - std::auto_ptr signer(get_pk_signer(priv_key, "EMSA1(SHA-224)")); - std::auto_ptr verifier(get_pk_verifier(priv_key, "EMSA1(SHA-224)")); + std::unique_ptr signer(get_pk_signer(priv_key, "EMSA1(SHA-224)")); + std::unique_ptr verifier(get_pk_verifier(priv_key, "EMSA1(SHA-224)")); for(u32bit i = 0; i != 256; ++i) signer->update((byte)i); @@ -313,11 +313,11 @@ void test_create_and_verify(RandomNumberGenerator& rng) std::ofstream priv_key(TEST_DATA_DIR "/dompar_private.pkcs8.pem"); priv_key << PKCS8::PEM_encode(key); - std::auto_ptr loaded_key(PKCS8::load_key(TEST_DATA_DIR "/wo_dompar_private.pkcs8.pem", rng)); + std::unique_ptr loaded_key(PKCS8::load_key(TEST_DATA_DIR "/wo_dompar_private.pkcs8.pem", rng)); ECDSA_PrivateKey* loaded_ec_key = dynamic_cast(loaded_key.get()); CHECK_MESSAGE(loaded_ec_key, "the loaded key could not be converted into an ECDSA_PrivateKey"); - std::auto_ptr loaded_key_1(PKCS8::load_key(TEST_DATA_DIR "/rsa_private.pkcs8.pem", rng)); + std::unique_ptr loaded_key_1(PKCS8::load_key(TEST_DATA_DIR "/rsa_private.pkcs8.pem", rng)); ECDSA_PrivateKey* loaded_rsa_key = dynamic_cast(loaded_key_1.get()); CHECK_MESSAGE(!loaded_rsa_key, "the loaded key is ECDSA_PrivateKey -> shouldn't be, is a RSA-Key"); @@ -350,7 +350,7 @@ void test_create_and_verify(RandomNumberGenerator& rng) std::string key_odd_oid_str = PKCS8::PEM_encode(key_odd_oid); DataSource_Memory key_data_src(key_odd_oid_str); - std::auto_ptr loaded_key2(PKCS8::load_key(key_data_src, rng)); + std::unique_ptr loaded_key2(PKCS8::load_key(key_data_src, rng)); if(!dynamic_cast(loaded_key.get())) { @@ -420,7 +420,7 @@ void test_read_pkcs8(RandomNumberGenerator& rng) std::cout << "." << std::flush; try { - std::auto_ptr loaded_key(PKCS8::load_key(TEST_DATA_DIR "/wo_dompar_private.pkcs8.pem", rng)); + std::unique_ptr loaded_key(PKCS8::load_key(TEST_DATA_DIR "/wo_dompar_private.pkcs8.pem", rng)); ECDSA_PrivateKey* loaded_ec_key = dynamic_cast(loaded_key.get()); CHECK_MESSAGE(loaded_ec_key, "the loaded key could not be converted into an ECDSA_PrivateKey"); @@ -431,7 +431,7 @@ void test_read_pkcs8(RandomNumberGenerator& rng) bool ver_success = loaded_ec_key->verify(sv_message.begin(), sv_message.size(), signature.begin(), signature.size()); CHECK_MESSAGE(ver_success, "generated signature could not be verified positively"); - std::auto_ptr loaded_key_nodp(PKCS8::load_key(TEST_DATA_DIR "/nodompar_private.pkcs8.pem", rng)); + std::unique_ptr loaded_key_nodp(PKCS8::load_key(TEST_DATA_DIR "/nodompar_private.pkcs8.pem", rng)); // anew in each test with unregistered domain-parameters ECDSA_PrivateKey* loaded_ec_key_nodp = dynamic_cast(loaded_key_nodp.get()); CHECK_MESSAGE(loaded_ec_key_nodp, "the loaded key could not be converted into an ECDSA_PrivateKey"); @@ -442,7 +442,7 @@ void test_read_pkcs8(RandomNumberGenerator& rng) CHECK_MESSAGE(ver_success_nodp, "generated signature could not be verified positively (no_dom)"); try { - std::auto_ptr loaded_key_withdp(PKCS8::load_key(TEST_DATA_DIR "/withdompar_private.pkcs8.pem", rng)); + std::unique_ptr loaded_key_withdp(PKCS8::load_key(TEST_DATA_DIR "/withdompar_private.pkcs8.pem", rng)); std::cout << "Unexpected success: loaded key with unknown OID\n"; } @@ -461,7 +461,7 @@ void test_cp_and_as_ctors(RandomNumberGenerator& rng) { std::cout << "." << std::flush; - std::auto_ptr loaded_key(PKCS8::load_key(TEST_DATA_DIR "/wo_dompar_private.pkcs8.pem", rng)); + std::unique_ptr loaded_key(PKCS8::load_key(TEST_DATA_DIR "/wo_dompar_private.pkcs8.pem", rng)); ECDSA_PrivateKey* loaded_ec_key = dynamic_cast(loaded_key.get()); CHECK_MESSAGE(loaded_ec_key, "the loaded key could not be converted into an ECDSA_PrivateKey"); std::string str_message = ("12345678901234567890abcdef12"); @@ -497,7 +497,7 @@ void test_non_init_ecdsa_keys(RandomNumberGenerator& rng) { std::cout << "." << std::flush; - std::auto_ptr loaded_key(PKCS8::load_key(TEST_DATA_DIR "/wo_dompar_private.pkcs8.pem", rng)); + std::unique_ptr loaded_key(PKCS8::load_key(TEST_DATA_DIR "/wo_dompar_private.pkcs8.pem", rng)); //ECDSA_PrivateKey* loaded_ec_key = dynamic_cast(loaded_key.get()); //CHECK_MESSAGE(loaded_ec_key, "the loaded key could not be converted into an ECDSA_PrivateKey"); std::string str_message = ("12345678901234567890abcdef12"); diff --git a/checks/eckaeg.cpp b/checks/eckaeg.cpp index f25fbb292..501ad8c3d 100644 --- a/checks/eckaeg.cpp +++ b/checks/eckaeg.cpp @@ -103,7 +103,7 @@ void test_eckaeg_some_dp(RandomNumberGenerator& rng) Botan::EC_Domain_Params dom_pars(Botan::get_EC_Dom_Pars_by_oid(oids[i])); Botan::ECKAEG_PrivateKey private_a(rng, dom_pars); Botan::ECKAEG_PublicKey public_a = private_a; - /*auto_ptr x509_key_enc = public_a.x509_encoder(); + /*unique_ptr x509_key_enc = public_a.x509_encoder(); Botan::MemoryVector enc_key_a = Botan::DER_Encoder() .start_cons(Botan::SEQUENCE) .encode(x509_key_enc->alg_id()) diff --git a/checks/pk.cpp b/checks/pk.cpp index c02005245..e8746ad04 100644 --- a/checks/pk.cpp +++ b/checks/pk.cpp @@ -178,7 +178,7 @@ u32bit validate_rsa_enc_pkcs8(const std::string& algo, DataSource_Memory keysource(reinterpret_cast(str[0].c_str()), str[0].length()); - std::auto_ptr privkey(PKCS8::load_key(keysource, rng, pass)); + std::unique_ptr privkey(PKCS8::load_key(keysource, rng, pass)); RSA_PrivateKey* rsapriv = dynamic_cast(privkey.get()); if(!rsapriv) @@ -297,7 +297,7 @@ u32bit validate_rsa_ver(const std::string& algo, std::string emsa = algo.substr(6, std::string::npos); - std::auto_ptr v(get_pk_verifier(key, emsa)); + std::unique_ptr v(get_pk_verifier(key, emsa)); SecureVector msg = decode_hex(str[2]); SecureVector sig = decode_hex(str[3]); @@ -320,7 +320,7 @@ u32bit validate_rsa_ver_x509(const std::string& algo, DataSource_Memory keysource(reinterpret_cast(str[0].c_str()), str[0].length()); - std::auto_ptr key(X509::load_key(keysource)); + std::unique_ptr key(X509::load_key(keysource)); RSA_PublicKey* rsakey = dynamic_cast(key.get()); @@ -329,7 +329,7 @@ u32bit validate_rsa_ver_x509(const std::string& algo, std::string emsa = algo.substr(11, std::string::npos); - std::auto_ptr v(get_pk_verifier(*rsakey, emsa)); + std::unique_ptr v(get_pk_verifier(*rsakey, emsa)); SecureVector msg = decode_hex(str[1]); SecureVector sig = decode_hex(str[2]); @@ -355,7 +355,7 @@ u32bit validate_rw_ver(const std::string& algo, std::string emsa = algo.substr(5, std::string::npos); - std::auto_ptr v(get_pk_verifier(key, emsa)); + std::unique_ptr v(get_pk_verifier(key, emsa)); SecureVector msg = decode_hex(str[2]); SecureVector sig = decode_hex(str[3]); @@ -411,7 +411,7 @@ u32bit validate_dsa_sig(const std::string& algo, DataSource_Memory keysource(reinterpret_cast(str[0].c_str()), str[0].length()); - std::auto_ptr privkey(PKCS8::load_key(keysource, rng, pass)); + std::unique_ptr privkey(PKCS8::load_key(keysource, rng, pass)); DSA_PrivateKey* dsapriv = dynamic_cast(privkey.get()); if(!dsapriv) @@ -443,7 +443,7 @@ u32bit validate_dsa_ver(const std::string& algo, #if defined(BOTAN_HAS_DSA) - std::auto_ptr key(X509::load_key(keysource)); + std::unique_ptr key(X509::load_key(keysource)); DSA_PublicKey* dsakey = dynamic_cast(key.get()); @@ -452,7 +452,7 @@ u32bit validate_dsa_ver(const std::string& algo, std::string emsa = algo.substr(7, std::string::npos); - std::auto_ptr v(get_pk_verifier(*dsakey, emsa)); + std::unique_ptr v(get_pk_verifier(*dsakey, emsa)); SecureVector msg = decode_hex(str[1]); SecureVector sig = decode_hex(str[2]); diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp index a944934fb..8e5054a9a 100644 --- a/checks/pk_bench.cpp +++ b/checks/pk_bench.cpp @@ -191,12 +191,12 @@ void benchmark_rsa(RandomNumberGenerator& rng, while(verify_timer.seconds() < seconds || sig_timer.seconds() < seconds) { - std::auto_ptr enc(get_pk_encryptor(key, enc_padding)); - std::auto_ptr dec(get_pk_decryptor(key, enc_padding)); + std::unique_ptr enc(get_pk_encryptor(key, enc_padding)); + std::unique_ptr dec(get_pk_decryptor(key, enc_padding)); benchmark_enc_dec(*enc, *dec, enc_timer, dec_timer, rng, 10000, seconds); - std::auto_ptr sig(get_pk_signer(key, sig_padding)); - std::auto_ptr ver(get_pk_verifier(key, sig_padding)); + std::unique_ptr sig(get_pk_signer(key, sig_padding)); + std::unique_ptr ver(get_pk_verifier(key, sig_padding)); benchmark_sig_ver(*ver, *sig, verify_timer, sig_timer, rng, 10000, seconds); } @@ -246,8 +246,8 @@ void benchmark_rw(RandomNumberGenerator& rng, RW_PrivateKey key(rng, keylen); keygen_timer.stop(); - std::auto_ptr sig(get_pk_signer(key, padding)); - std::auto_ptr ver(get_pk_verifier(key, padding)); + std::unique_ptr sig(get_pk_signer(key, padding)); + std::unique_ptr ver(get_pk_verifier(key, padding)); benchmark_sig_ver(*ver, *sig, verify_timer, sig_timer, rng, 10000, seconds); } @@ -300,8 +300,8 @@ void benchmark_ecdsa(RandomNumberGenerator& rng, ECDSA_PrivateKey key(rng, params); keygen_timer.stop(); - std::auto_ptr sig(get_pk_signer(key, padding)); - std::auto_ptr ver(get_pk_verifier(key, padding)); + std::unique_ptr sig(get_pk_signer(key, padding)); + std::unique_ptr ver(get_pk_verifier(key, padding)); benchmark_sig_ver(*ver, *sig, verify_timer, sig_timer, rng, 1000, seconds); @@ -416,8 +416,8 @@ void benchmark_dsa_nr(RandomNumberGenerator& rng, PRIV_KEY_TYPE key(rng, group); keygen_timer.stop(); - std::auto_ptr sig(get_pk_signer(key, padding)); - std::auto_ptr ver(get_pk_verifier(key, padding)); + std::unique_ptr sig(get_pk_signer(key, padding)); + std::unique_ptr ver(get_pk_verifier(key, padding)); benchmark_sig_ver(*ver, *sig, verify_timer, sig_timer, rng, 1000, seconds); @@ -586,8 +586,8 @@ void benchmark_elg(RandomNumberGenerator& rng, ElGamal_PrivateKey key(rng, group); keygen_timer.stop(); - std::auto_ptr dec(get_pk_decryptor(key, padding)); - std::auto_ptr enc(get_pk_encryptor(key, padding)); + std::unique_ptr dec(get_pk_decryptor(key, padding)); + std::unique_ptr enc(get_pk_encryptor(key, padding)); benchmark_enc_dec(*enc, *dec, enc_timer, dec_timer, rng, 1000, seconds); } diff --git a/checks/x509.cpp b/checks/x509.cpp index 6f191285c..3aba4ce1a 100644 --- a/checks/x509.cpp +++ b/checks/x509.cpp @@ -34,7 +34,7 @@ namespace { u64bit key_id(const Public_Key* key) { - std::auto_ptr encoder(key->x509_encoder()); + std::unique_ptr encoder(key->x509_encoder()); if(!encoder.get()) throw Internal_Error("Public_Key:key_id: No encoder found"); diff --git a/src/cert/cvc/cvc_ado.cpp b/src/cert/cvc/cvc_ado.cpp index 6e1484e90..19d76fe7f 100644 --- a/src/cert/cvc/cvc_ado.cpp +++ b/src/cert/cvc/cvc_ado.cpp @@ -47,12 +47,12 @@ void EAC1_1_ADO::force_decode() } MemoryVector EAC1_1_ADO::make_signed( - std::auto_ptr signer, + PK_Signer& signer, const MemoryRegion& tbs_bits, RandomNumberGenerator& rng) { SecureVector concat_sig = - EAC1_1_obj::make_signature(signer.get(), tbs_bits, rng); + EAC1_1_obj::make_signature(signer, tbs_bits, rng); assert(concat_sig.size() % 2 == 0); MemoryVector result = DER_Encoder() .start_cons(ASN1_Tag(7), APPLICATION) diff --git a/src/cert/cvc/cvc_ado.h b/src/cert/cvc/cvc_ado.h index 2c4f3ce70..ef469cc09 100644 --- a/src/cert/cvc/cvc_ado.h +++ b/src/cert/cvc/cvc_ado.h @@ -47,7 +47,7 @@ class BOTAN_DLL EAC1_1_ADO : public EAC1_1_obj * @param tbs_bits the TBS data to sign */ static MemoryVector make_signed( - std::auto_ptr signer, + PK_Signer& signer, const MemoryRegion& tbs_bits, RandomNumberGenerator& rng); diff --git a/src/cert/cvc/cvc_ca.cpp b/src/cert/cvc/cvc_ca.cpp index 638d3f984..7b1c5fcba 100644 --- a/src/cert/cvc/cvc_ca.cpp +++ b/src/cert/cvc/cvc_ca.cpp @@ -5,7 +5,7 @@ #include namespace Botan { -EAC1_1_CVC EAC1_1_CVC_CA::make_cert(std::auto_ptr signer, +EAC1_1_CVC EAC1_1_CVC_CA::make_cert(PK_Signer& signer, MemoryRegion const& public_key, ASN1_Car const& car, ASN1_Chr const& chr, diff --git a/src/cert/cvc/cvc_ca.h b/src/cert/cvc/cvc_ca.h index 3ec307bb3..87699808f 100644 --- a/src/cert/cvc/cvc_ca.h +++ b/src/cert/cvc/cvc_ca.h @@ -36,7 +36,7 @@ class BOTAN_DLL EAC1_1_CVC_CA * @param ced the CED to appear in the certificate * @param ced the CEX to appear in the certificate */ - static EAC1_1_CVC make_cert(std::auto_ptr signer, + static EAC1_1_CVC make_cert(PK_Signer& signer, MemoryRegion const& public_key, ASN1_Car const& car, ASN1_Chr const& chr, diff --git a/src/cert/cvc/cvc_cert.cpp b/src/cert/cvc/cvc_cert.cpp index 71ca0cf16..7964b8900 100644 --- a/src/cert/cvc/cvc_cert.cpp +++ b/src/cert/cvc/cvc_cert.cpp @@ -61,7 +61,7 @@ void EAC1_1_CVC::force_decode() // XXX: PK algos have no notion of EAC encoder/decoder currently #if 0 ECDSA_PublicKey tmp_pk; - std::auto_ptr dec = tmp_pk.cvc_eac1_1_decoder(); + std::unique_ptr dec = tmp_pk.cvc_eac1_1_decoder(); sig_algo = dec->public_key(enc_pk); diff --git a/src/cert/cvc/cvc_gen_cert.h b/src/cert/cvc/cvc_gen_cert.h index 4a788026c..8620cd89a 100644 --- a/src/cert/cvc/cvc_gen_cert.h +++ b/src/cert/cvc/cvc_gen_cert.h @@ -33,7 +33,7 @@ class BOTAN_DLL EAC1_1_gen_CVC : public EAC1_1_obj // CRTP continuation * Get this certificates public key. * @result this certificates public key */ - std::auto_ptr subject_public_key() const; + std::unique_ptr subject_public_key() const; /** * Find out whether this object is self signed. @@ -75,7 +75,7 @@ class BOTAN_DLL EAC1_1_gen_CVC : public EAC1_1_obj // CRTP continuation * @result the DER encoded signed generalized CVC object */ static MemoryVector make_signed( - std::auto_ptr signer, + PK_Signer& signer, const MemoryRegion& tbs_bits, RandomNumberGenerator& rng); virtual ~EAC1_1_gen_CVC() @@ -103,11 +103,11 @@ template bool EAC1_1_gen_CVC::is_self_signed() const } template MemoryVector EAC1_1_gen_CVC::make_signed( - std::auto_ptr signer, + PK_Signer& signer, const MemoryRegion& tbs_bits, RandomNumberGenerator& rng) // static { - SecureVector concat_sig = EAC1_1_obj::make_signature(signer.get(), tbs_bits, rng); + SecureVector concat_sig = EAC1_1_obj::make_signature(signer, tbs_bits, rng); assert(concat_sig.size() % 2 == 0); return DER_Encoder() .start_cons(ASN1_Tag(33), APPLICATION) @@ -117,9 +117,9 @@ template MemoryVector EAC1_1_gen_CVC::make_sign .get_contents(); } -template std::auto_ptr EAC1_1_gen_CVC::subject_public_key() const +template std::unique_ptr EAC1_1_gen_CVC::subject_public_key() const { - return std::auto_ptr(new ECDSA_PublicKey(m_pk)); + return std::unique_ptr(new ECDSA_PublicKey(m_pk)); } template SecureVector EAC1_1_gen_CVC::build_cert_body(MemoryRegion const& tbs) diff --git a/src/cert/cvc/cvc_req.cpp b/src/cert/cvc/cvc_req.cpp index a9a94827c..c2318dc1b 100644 --- a/src/cert/cvc/cvc_req.cpp +++ b/src/cert/cvc/cvc_req.cpp @@ -44,7 +44,7 @@ void EAC1_1_Req::force_decode() // XXX: No EAC support in ECDSA #if 0 ECDSA_PublicKey tmp_pk; - std::auto_ptr dec = tmp_pk.cvc_eac1_1_decoder(); + std::unique_ptr dec = tmp_pk.cvc_eac1_1_decoder(); sig_algo = dec->public_key(enc_pk); m_pk = tmp_pk; #endif diff --git a/src/cert/cvc/cvc_self.cpp b/src/cert/cvc/cvc_self.cpp index 45a584cb3..c31741956 100644 --- a/src/cert/cvc/cvc_self.cpp +++ b/src/cert/cvc/cvc_self.cpp @@ -84,16 +84,18 @@ EAC1_1_CVC create_self_signed_cert(Private_Key const& key, sig_algo.oid = OIDS::lookup(priv_key->algo_name() + "/" + padding_and_hash); sig_algo = AlgorithmIdentifier(sig_algo.oid, AlgorithmIdentifier::USE_NULL_PARAM); - std::auto_ptr signer(get_pk_signer(*priv_key, padding_and_hash)); + std::unique_ptr signer(get_pk_signer(*priv_key, padding_and_hash)); #if 0 - std::auto_ptr enc(priv_key->cvc_eac1_1_encoder()); + std::unique_ptr enc(priv_key->cvc_eac1_1_encoder()); MemoryVector enc_public_key = enc->public_key(sig_algo); #else MemoryVector enc_public_key; #endif - return EAC1_1_CVC_CA::make_cert(signer, enc_public_key, opt.car, chr, opt.holder_auth_templ, opt.ced, opt.cex, rng); + return EAC1_1_CVC_CA::make_cert(*signer.get(), enc_public_key, + opt.car, chr, opt.holder_auth_templ, + opt.ced, opt.cex, rng); } @@ -113,10 +115,10 @@ EAC1_1_Req create_cvc_req(Private_Key const& key, sig_algo.oid = OIDS::lookup(priv_key->algo_name() + "/" + padding_and_hash); sig_algo = AlgorithmIdentifier(sig_algo.oid, AlgorithmIdentifier::USE_NULL_PARAM); - std::auto_ptr signer(get_pk_signer(*priv_key, padding_and_hash)); + std::unique_ptr signer(get_pk_signer(*priv_key, padding_and_hash)); -#if 0 - std::auto_ptr enc(priv_key->cvc_eac1_1_encoder()); +#if 0 // FIXME + std::unique_ptr enc(priv_key->cvc_eac1_1_encoder()); MemoryVector enc_public_key = enc->public_key(sig_algo); #else MemoryVector enc_public_key; @@ -130,7 +132,10 @@ EAC1_1_Req create_cvc_req(Private_Key const& key, .encode(chr) .get_contents(); - MemoryVector signed_cert = EAC1_1_gen_CVC::make_signed(signer, EAC1_1_gen_CVC::build_cert_body(tbs), rng); + MemoryVector signed_cert = + EAC1_1_gen_CVC::make_signed(*signer.get(), + EAC1_1_gen_CVC::build_cert_body(tbs), rng); + std::tr1::shared_ptr source(new DataSource_Memory(signed_cert)); return EAC1_1_Req(source); } @@ -146,11 +151,15 @@ EAC1_1_ADO create_ado_req(Private_Key const& key, { throw Invalid_Argument("CVC_EAC::create_self_signed_cert(): unsupported key type"); } + std::string padding_and_hash = padding_and_hash_from_oid(req.signature_algorithm().oid); - std::auto_ptr signer(get_pk_signer(*priv_key, padding_and_hash)); + + std::unique_ptr signer(get_pk_signer(*priv_key, padding_and_hash)); + SecureVector tbs_bits = req.BER_encode(); tbs_bits.append(DER_Encoder().encode(car).get_contents()); - MemoryVector signed_cert = EAC1_1_ADO::make_signed(signer, tbs_bits, rng); + + MemoryVector signed_cert = EAC1_1_ADO::make_signed(*signer.get(), tbs_bits, rng); std::tr1::shared_ptr source(new DataSource_Memory(signed_cert)); return EAC1_1_ADO(source); } @@ -210,19 +219,19 @@ EAC1_1_CVC link_cvca(EAC1_1_CVC const& signer, } AlgorithmIdentifier sig_algo = signer.signature_algorithm(); std::string padding_and_hash = padding_and_hash_from_oid(sig_algo.oid); - std::auto_ptr pk_signer(get_pk_signer(*priv_key, padding_and_hash)); - std::auto_ptr pk = signee.subject_public_key(); + std::unique_ptr pk_signer(get_pk_signer(*priv_key, padding_and_hash)); + std::unique_ptr pk = signee.subject_public_key(); ECDSA_PublicKey* subj_pk = dynamic_cast(pk.get()); subj_pk->set_parameter_encoding(ENC_EXPLICIT); #if 0 - std::auto_ptr enc(subj_pk->cvc_eac1_1_encoder()); + std::unique_ptr enc(subj_pk->cvc_eac1_1_encoder()); MemoryVector enc_public_key = enc->public_key(sig_algo); #else MemoryVector enc_public_key; #endif - return EAC1_1_CVC_CA::make_cert(pk_signer, enc_public_key, + return EAC1_1_CVC_CA::make_cert(*pk_signer.get(), enc_public_key, signer.get_car(), signee.get_chr(), signer.get_chat_value(), @@ -250,10 +259,10 @@ EAC1_1_CVC sign_request(EAC1_1_CVC const& signer_cert, chr_str.append(fixed_len_seqnr(seqnr, seqnr_len)); ASN1_Chr chr(chr_str); std::string padding_and_hash = padding_and_hash_from_oid(signee.signature_algorithm().oid); - std::auto_ptr pk_signer(get_pk_signer(*priv_key, padding_and_hash)); - std::auto_ptr pk = signee.subject_public_key(); + std::unique_ptr pk_signer(get_pk_signer(*priv_key, padding_and_hash)); + std::unique_ptr pk = signee.subject_public_key(); ECDSA_PublicKey* subj_pk = dynamic_cast(pk.get()); - std::auto_ptr signer_pk = signer_cert.subject_public_key(); + std::unique_ptr signer_pk = signer_cert.subject_public_key(); // for the case that the domain parameters are not set... // (we use those from the signer because they must fit) @@ -261,8 +270,8 @@ EAC1_1_CVC sign_request(EAC1_1_CVC const& signer_cert, subj_pk->set_parameter_encoding(ENC_IMPLICITCA); -#if 0 - std::auto_ptr enc(subj_pk->cvc_eac1_1_encoder()); +#if 0 // FIXME + std::unique_ptr enc(subj_pk->cvc_eac1_1_encoder()); MemoryVector enc_public_key = enc->public_key(sig_algo); #else MemoryVector enc_public_key; @@ -298,7 +307,7 @@ EAC1_1_CVC sign_request(EAC1_1_CVC const& signer_cert, throw Invalid_Argument("sign_request(): encountered illegal value for CHAT"); // (IS cannot sign certificates) } - return EAC1_1_CVC_CA::make_cert(pk_signer, enc_public_key, + return EAC1_1_CVC_CA::make_cert(*pk_signer.get(), enc_public_key, ASN1_Car(signer_cert.get_chr().iso_8859()), chr, chat_val, diff --git a/src/cert/cvc/eac_obj.h b/src/cert/cvc/eac_obj.h index 04afd7e59..b41b78b2c 100644 --- a/src/cert/cvc/eac_obj.h +++ b/src/cert/cvc/eac_obj.h @@ -54,7 +54,7 @@ class BOTAN_DLL EAC1_1_obj : public EAC_Signed_Object protected: void init(SharedPtrConverter in); - static SecureVector make_signature(PK_Signer* signer, + static SecureVector make_signature(PK_Signer& signer, const MemoryRegion& tbs_bits, RandomNumberGenerator& rng); @@ -68,12 +68,12 @@ template SecureVector EAC1_1_obj::get_concat_si } template SecureVector -EAC1_1_obj::make_signature(PK_Signer* signer, +EAC1_1_obj::make_signature(PK_Signer& signer, const MemoryRegion& tbs_bits, RandomNumberGenerator& rng) { // this is the signature as a der sequence - SecureVector seq_sig = signer->sign_message(tbs_bits, rng); + SecureVector seq_sig = signer.sign_message(tbs_bits, rng); ECDSA_Signature sig(decode_seq(seq_sig)); SecureVector concat_sig(sig.get_concatenation()); @@ -112,12 +112,12 @@ bool EAC1_1_obj::check_signature(Public_Key& pub_key) const if(!dynamic_cast(&pub_key)) return false; - std::auto_ptr enc(new ECDSA_Signature_Encoder(&m_sig)); + std::unique_ptr enc(new ECDSA_Signature_Encoder(&m_sig)); SecureVector seq_sig = enc->signature_bits(); SecureVector to_sign = tbs_data(); PK_Verifying_wo_MR_Key& sig_key = dynamic_cast(pub_key); - std::auto_ptr verifier(get_pk_verifier(sig_key, padding, format)); + std::unique_ptr verifier(get_pk_verifier(sig_key, padding, format)); return verifier->verify_message(to_sign, seq_sig); } catch(...) diff --git a/src/cert/cvc/ecdsa_sig.cpp b/src/cert/cvc/ecdsa_sig.cpp index c33a4550a..1a60f7aa8 100644 --- a/src/cert/cvc/ecdsa_sig.cpp +++ b/src/cert/cvc/ecdsa_sig.cpp @@ -41,7 +41,7 @@ ECDSA_Signature const decode_seq(MemoryRegion const& seq) { ECDSA_Signature sig; - std::auto_ptr dec(new ECDSA_Signature_Decoder(&sig)); + std::unique_ptr dec(new ECDSA_Signature_Decoder(&sig)); dec->signature_bits(seq); return sig; } diff --git a/src/cert/x509/x509_ca.cpp b/src/cert/x509/x509_ca.cpp index 41e314724..05cdce411 100644 --- a/src/cert/x509/x509_ca.cpp +++ b/src/cert/x509/x509_ca.cpp @@ -51,7 +51,7 @@ X509_Certificate X509_CA::sign_request(const PKCS10_Request& req, constraints = Key_Constraints(KEY_CERT_SIGN | CRL_SIGN); else { - std::auto_ptr key(req.subject_public_key()); + std::unique_ptr key(req.subject_public_key()); constraints = X509::find_constraints(*key, req.constraints()); } @@ -269,7 +269,7 @@ PK_Signer* choose_sig_format(const Private_Key& key, sig_algo.oid = OIDS::lookup(algo_name + "/" + padding); - std::auto_ptr encoding(key.x509_encoder()); + std::unique_ptr encoding(key.x509_encoder()); if(!encoding.get()) throw Encoding_Error("Key " + algo_name + " does not support " "X.509 encoding"); diff --git a/src/cert/x509/x509_obj.cpp b/src/cert/x509/x509_obj.cpp index 31b4a309f..95a1c1cca 100644 --- a/src/cert/x509/x509_obj.cpp +++ b/src/cert/x509/x509_obj.cpp @@ -168,7 +168,7 @@ bool X509_Object::check_signature(Public_Key& pub_key) const Signature_Format format = (pub_key.message_parts() >= 2) ? DER_SEQUENCE : IEEE_1363; - std::auto_ptr verifier; + std::unique_ptr verifier; if(dynamic_cast(&pub_key)) { diff --git a/src/cert/x509/x509self.cpp b/src/cert/x509/x509self.cpp index 8afb22a7e..598d6a418 100644 --- a/src/cert/x509/x509self.cpp +++ b/src/cert/x509/x509self.cpp @@ -72,7 +72,7 @@ X509_Certificate create_self_signed_cert(const X509_Cert_Options& opts, AlternativeName subject_alt; MemoryVector pub_key = shared_setup(opts, key); - std::auto_ptr signer(choose_sig_format(key, sig_algo)); + std::unique_ptr signer(choose_sig_format(key, sig_algo)); load_info(opts, subject_dn, subject_alt); Key_Constraints constraints; @@ -110,7 +110,7 @@ PKCS10_Request create_cert_req(const X509_Cert_Options& opts, AlternativeName subject_alt; MemoryVector pub_key = shared_setup(opts, key); - std::auto_ptr signer(choose_sig_format(key, sig_algo)); + std::unique_ptr signer(choose_sig_format(key, sig_algo)); load_info(opts, subject_dn, subject_alt); const u32bit PKCS10_VERSION = 0; diff --git a/src/cert/x509/x509stor.cpp b/src/cert/x509/x509stor.cpp index cb61bc2d2..f91da890b 100644 --- a/src/cert/x509/x509stor.cpp +++ b/src/cert/x509/x509stor.cpp @@ -380,8 +380,8 @@ X509_Code X509_Store::check_sig(const Cert_Info& cert_info, */ X509_Code X509_Store::check_sig(const X509_Object& object, Public_Key* key) { - std::auto_ptr pub_key(key); - std::auto_ptr verifier; + std::unique_ptr pub_key(key); + std::unique_ptr verifier; try { std::vector sig_info = diff --git a/src/math/numbertheory/dsa_gen.cpp b/src/math/numbertheory/dsa_gen.cpp index 83646e50e..d5f6dc792 100644 --- a/src/math/numbertheory/dsa_gen.cpp +++ b/src/math/numbertheory/dsa_gen.cpp @@ -54,7 +54,7 @@ bool generate_dsa_primes(RandomNumberGenerator& rng, "Generating a DSA parameter set with a " + to_string(qbits) + "long q requires a seed at least as many bits long"); - std::auto_ptr hash( + std::unique_ptr hash( af.make_hash_function("SHA-" + to_string(qbits))); const u32bit HASH_SIZE = hash->OUTPUT_LENGTH; diff --git a/src/pubkey/ec_dompar/ec_dompar.cpp b/src/pubkey/ec_dompar/ec_dompar.cpp index 6cfcc0619..c4634877e 100644 --- a/src/pubkey/ec_dompar/ec_dompar.cpp +++ b/src/pubkey/ec_dompar/ec_dompar.cpp @@ -545,7 +545,7 @@ EC_Domain_Params decode_ber_ec_dompar(SecureVector const& encoded) BER_Decoder dec(encoded); BER_Object obj = dec.get_next_object(); ASN1_Tag tag = obj.type_tag; - std::auto_ptr p_result; + std::unique_ptr p_result; if(tag == OBJECT_ID) { diff --git a/src/pubkey/ecc_key/ecc_key.cpp b/src/pubkey/ecc_key/ecc_key.cpp index 9af63bdcd..bebfc3705 100644 --- a/src/pubkey/ecc_key/ecc_key.cpp +++ b/src/pubkey/ecc_key/ecc_key.cpp @@ -166,7 +166,7 @@ void EC_PrivateKey::generate_private_key(RandomNumberGenerator& rng) BigInt tmp_private_value(0); tmp_private_value = BigInt::random_integer(rng, 1, mp_dom_pars->get_order()); - mp_public_point = std::auto_ptr( new PointGFp (mp_dom_pars->get_base_point())); + mp_public_point = std::unique_ptr( new PointGFp (mp_dom_pars->get_base_point())); mp_public_point->mult_this_secure(tmp_private_value, mp_dom_pars->get_order(), mp_dom_pars->get_order()-1); diff --git a/src/pubkey/ecc_key/ecc_key.h b/src/pubkey/ecc_key/ecc_key.h index 0ca9a0e75..9d5f57d9f 100644 --- a/src/pubkey/ecc_key/ecc_key.h +++ b/src/pubkey/ecc_key/ecc_key.h @@ -103,8 +103,8 @@ class BOTAN_DLL EC_PublicKey : public virtual Public_Key SecureVector m_enc_public_point; // stores the public point - std::auto_ptr mp_dom_pars; - std::auto_ptr mp_public_point; + std::unique_ptr mp_dom_pars; + std::unique_ptr mp_public_point; EC_dompar_enc m_param_enc; }; diff --git a/src/pubkey/ecdsa/ecdsa.cpp b/src/pubkey/ecdsa/ecdsa.cpp index 9640c6397..3e3bbf38a 100644 --- a/src/pubkey/ecdsa/ecdsa.cpp +++ b/src/pubkey/ecdsa/ecdsa.cpp @@ -20,7 +20,7 @@ namespace Botan { ECDSA_PrivateKey::ECDSA_PrivateKey(RandomNumberGenerator& rng, const EC_Domain_Params& dom_pars) { - mp_dom_pars = std::auto_ptr(new EC_Domain_Params(dom_pars)); + mp_dom_pars = std::unique_ptr(new EC_Domain_Params(dom_pars)); generate_private_key(rng); try @@ -68,11 +68,10 @@ void ECDSA_PublicKey::set_domain_parameters(const EC_Domain_Params& dom_pars) throw Invalid_State("EC_PublicKey::set_domain_parameters(): point does not lie on provided curve"); } - std::auto_ptr p_tmp_pars(new EC_Domain_Params(dom_pars)); - ECDSA_Core tmp_ecdsa_core(*p_tmp_pars, BigInt(0), tmp_pp); + mp_dom_pars.reset(new EC_Domain_Params(dom_pars)); + ECDSA_Core tmp_ecdsa_core(*mp_dom_pars, BigInt(0), tmp_pp); mp_public_point.reset(new PointGFp(tmp_pp)); m_ecdsa_core = tmp_ecdsa_core; - mp_dom_pars = p_tmp_pars; } void ECDSA_PublicKey::set_all_values(const ECDSA_PublicKey& other) @@ -131,8 +130,8 @@ bool ECDSA_PublicKey::verify(const byte message[], ECDSA_PublicKey::ECDSA_PublicKey(const EC_Domain_Params& dom_par, const PointGFp& public_point) { - mp_dom_pars = std::auto_ptr(new EC_Domain_Params(dom_par)); - mp_public_point = std::auto_ptr(new PointGFp(public_point)); + mp_dom_pars = std::unique_ptr(new EC_Domain_Params(dom_par)); + mp_public_point = std::unique_ptr(new PointGFp(public_point)); m_param_enc = ENC_EXPLICIT; m_ecdsa_core = ECDSA_Core(*mp_dom_pars, BigInt(0), *mp_public_point); } diff --git a/src/pubkey/eckaeg/eckaeg.cpp b/src/pubkey/eckaeg/eckaeg.cpp index 0d094e2e1..1b315d101 100644 --- a/src/pubkey/eckaeg/eckaeg.cpp +++ b/src/pubkey/eckaeg/eckaeg.cpp @@ -63,8 +63,8 @@ void ECKAEG_PublicKey::X509_load_hook() ECKAEG_PublicKey::ECKAEG_PublicKey(EC_Domain_Params const& dom_par, PointGFp const& public_point) { - mp_dom_pars = std::auto_ptr(new EC_Domain_Params(dom_par)); - mp_public_point = std::auto_ptr(new PointGFp(public_point)); + mp_dom_pars = std::unique_ptr(new EC_Domain_Params(dom_par)); + mp_public_point = std::unique_ptr(new PointGFp(public_point)); if(mp_public_point->get_curve() != mp_dom_pars->get_curve()) { throw Invalid_Argument("ECKAEG_PublicKey(): curve of arg. point and curve of arg. domain parameters are different"); diff --git a/src/pubkey/eckaeg/eckaeg.h b/src/pubkey/eckaeg/eckaeg.h index 31b65740c..053a40e4f 100644 --- a/src/pubkey/eckaeg/eckaeg.h +++ b/src/pubkey/eckaeg/eckaeg.h @@ -89,7 +89,7 @@ class BOTAN_DLL ECKAEG_PrivateKey : public ECKAEG_PublicKey, ECKAEG_PrivateKey(RandomNumberGenerator& rng, const EC_Domain_Params& dom_pars) { - mp_dom_pars = std::auto_ptr(new EC_Domain_Params(dom_pars)); + mp_dom_pars = std::unique_ptr(new EC_Domain_Params(dom_pars)); generate_private_key(rng); mp_public_point->check_invariants(); m_eckaeg_core = ECKAEG_Core(*mp_dom_pars, m_private_value, *mp_public_point); diff --git a/src/pubkey/keypair/keypair.cpp b/src/pubkey/keypair/keypair.cpp index 486577fc5..7eaa33395 100644 --- a/src/pubkey/keypair/keypair.cpp +++ b/src/pubkey/keypair/keypair.cpp @@ -22,8 +22,8 @@ void check_key(RandomNumberGenerator& rng, if(encryptor->maximum_input_size() == 0) return; - std::auto_ptr enc(encryptor); - std::auto_ptr dec(decryptor); + std::unique_ptr enc(encryptor); + std::unique_ptr dec(decryptor); SecureVector message(enc->maximum_input_size() - 1); rng.randomize(message, message.size()); @@ -43,8 +43,8 @@ void check_key(RandomNumberGenerator& rng, void check_key(RandomNumberGenerator& rng, PK_Signer* signer, PK_Verifier* verifier) { - std::auto_ptr sig(signer); - std::auto_ptr ver(verifier); + std::unique_ptr sig(signer); + std::unique_ptr ver(verifier); SecureVector message(16); rng.randomize(message, message.size()); diff --git a/src/pubkey/pubkey/pkcs8.cpp b/src/pubkey/pubkey/pkcs8.cpp index 8a464ecfe..87f05da92 100644 --- a/src/pubkey/pubkey/pkcs8.cpp +++ b/src/pubkey/pubkey/pkcs8.cpp @@ -89,7 +89,7 @@ SecureVector PKCS8_decode(DataSource& source, const User_Interface& ui, if(is_encrypted) { DataSource_Memory params(pbe_alg_id.parameters); - std::auto_ptr pbe(get_pbe(pbe_alg_id.oid, params)); + std::unique_ptr pbe(get_pbe(pbe_alg_id.oid, params)); User_Interface::UI_Result result = User_Interface::OK; const std::string passphrase = @@ -138,7 +138,7 @@ SecureVector PKCS8_decode(DataSource& source, const User_Interface& ui, */ void encode(const Private_Key& key, Pipe& pipe, X509_Encoding encoding) { - std::auto_ptr encoder(key.pkcs8_encoder()); + std::unique_ptr encoder(key.pkcs8_encoder()); if(!encoder.get()) throw Encoding_Error("PKCS8::encode: Key does not support encoding"); @@ -175,7 +175,7 @@ void encrypt_key(const Private_Key& key, encode(key, raw_key, RAW_BER); raw_key.end_msg(); - std::auto_ptr pbe(get_pbe(((pbe_algo != "") ? pbe_algo : DEFAULT_PBE))); + std::unique_ptr pbe(get_pbe(((pbe_algo != "") ? pbe_algo : DEFAULT_PBE))); pbe->new_params(rng); pbe->set_key(pass); @@ -244,13 +244,13 @@ Private_Key* load_key(DataSource& source, throw PKCS8_Exception("Unknown algorithm OID: " + alg_id.oid.as_string()); - std::auto_ptr key(get_private_key(alg_name)); + std::unique_ptr key(get_private_key(alg_name)); if(!key.get()) throw PKCS8_Exception("Unknown PK algorithm/OID: " + alg_name + ", " + alg_id.oid.as_string()); - std::auto_ptr decoder(key->pkcs8_decoder(rng)); + std::unique_ptr decoder(key->pkcs8_decoder(rng)); if(!decoder.get()) throw Decoding_Error("Key does not support PKCS #8 decoding"); diff --git a/src/pubkey/pubkey/x509_key.cpp b/src/pubkey/pubkey/x509_key.cpp index 455e627f3..f1fc59410 100644 --- a/src/pubkey/pubkey/x509_key.cpp +++ b/src/pubkey/pubkey/x509_key.cpp @@ -24,7 +24,7 @@ namespace X509 { */ void encode(const Public_Key& key, Pipe& pipe, X509_Encoding encoding) { - std::auto_ptr encoder(key.x509_encoder()); + std::unique_ptr encoder(key.x509_encoder()); if(!encoder.get()) throw Encoding_Error("X509::encode: Key does not support encoding"); @@ -94,12 +94,12 @@ Public_Key* load_key(DataSource& source) throw Decoding_Error("Unknown algorithm OID: " + alg_id.oid.as_string()); - std::auto_ptr key_obj(get_public_key(alg_name)); + std::unique_ptr key_obj(get_public_key(alg_name)); if(!key_obj.get()) throw Decoding_Error("Unknown PK algorithm/OID: " + alg_name + ", " + alg_id.oid.as_string()); - std::auto_ptr decoder(key_obj->x509_decoder()); + std::unique_ptr decoder(key_obj->x509_decoder()); if(!decoder.get()) throw Decoding_Error("Key does not support X.509 decoding"); -- cgit v1.2.3 From 3afb86663583b982e1eab8f46d07fc3d51260602 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 1 Apr 2009 16:42:38 +0000 Subject: Use C++0x std::shared_ptr<> instead of TR1's --- checks/ec_tests.cpp | 6 +++--- checks/gfpmath.cpp | 14 +++++++------- src/cert/cvc/cvc_ado.cpp | 6 +++--- src/cert/cvc/cvc_ado.h | 2 +- src/cert/cvc/cvc_ca.cpp | 2 +- src/cert/cvc/cvc_cert.cpp | 4 ++-- src/cert/cvc/cvc_cert.h | 2 +- src/cert/cvc/cvc_req.cpp | 4 ++-- src/cert/cvc/cvc_req.h | 2 +- src/cert/cvc/cvc_self.cpp | 4 ++-- src/cert/cvc/freestore.h | 11 ++--------- src/math/gfpmath/curve_gfp.cpp | 28 ++++++++++++++-------------- src/math/gfpmath/curve_gfp.h | 16 ++++++++-------- src/math/gfpmath/gfp_element.cpp | 6 +++--- src/math/gfpmath/gfp_element.h | 17 +++++------------ src/math/gfpmath/point_gfp.cpp | 16 ++++++++-------- src/math/gfpmath/point_gfp.h | 10 +++++----- 17 files changed, 68 insertions(+), 82 deletions(-) (limited to 'src') diff --git a/checks/ec_tests.cpp b/checks/ec_tests.cpp index b079ebd47..5ee2002f3 100644 --- a/checks/ec_tests.cpp +++ b/checks/ec_tests.cpp @@ -80,8 +80,8 @@ void test_point_turn_on_sp_red_mul() CHECK_MESSAGE(r1 == r2, "error with point mul after extra turn on sp red mul"); CHECK(r1.get_affine_x().get_value() != BigInt("0")); - std::tr1::shared_ptr p_r1(new PointGFp(r1)); - std::tr1::shared_ptr p_r2(new PointGFp(r2)); + std::shared_ptr p_r1(new PointGFp(r1)); + std::shared_ptr p_r2(new PointGFp(r2)); p_r1->mult2_in_place(); // wird fĂ¼r Fehler nicht gebraucht p_r2->turn_on_sp_red_mul(); // 1. t_o() macht nur p_r2 kaputt @@ -981,7 +981,7 @@ void test_point_worksp() { EC_Domain_Params dom_pars(get_EC_Dom_Pars_by_oid("1.3.132.0.8")); - std::tr1::shared_ptr > worksp1; + std::shared_ptr > worksp1; assert(worksp1.get() == 0); { PointGFp p = dom_pars.get_base_point(); diff --git a/checks/gfpmath.cpp b/checks/gfpmath.cpp index 2352bba7e..6d8e406e3 100644 --- a/checks/gfpmath.cpp +++ b/checks/gfpmath.cpp @@ -484,13 +484,13 @@ bool test_gfp_shared_vals() GFpElement a(p, BigInt("234090")); GFpElement shcpy_a(1,0); shcpy_a.share_assign(a); - std::tr1::shared_ptr ptr1 = a.get_ptr_mod(); - std::tr1::shared_ptr ptr2 = shcpy_a.get_ptr_mod(); + std::shared_ptr ptr1 = a.get_ptr_mod(); + std::shared_ptr ptr2 = shcpy_a.get_ptr_mod(); CHECK_MESSAGE(ptr1.get() == ptr2.get(), "shared pointers for moduli aren´t equal"); GFpElement b(1,0); b = a; // create a non shared copy - std::tr1::shared_ptr ptr_b_p = b.get_ptr_mod(); + std::shared_ptr ptr_b_p = b.get_ptr_mod(); CHECK_MESSAGE(ptr1.get() != ptr_b_p.get(), "non shared pointers for moduli are equal"); a.turn_on_sp_red_mul(); @@ -513,15 +513,15 @@ bool test_gfp_shared_vals() } swap(a,shcpy_a); - std::tr1::shared_ptr ptr3 = a.get_ptr_mod(); - std::tr1::shared_ptr ptr4 = shcpy_a.get_ptr_mod(); + std::shared_ptr ptr3 = a.get_ptr_mod(); + std::shared_ptr ptr4 = shcpy_a.get_ptr_mod(); CHECK_MESSAGE(ptr3.get() == ptr4.get(), "shared pointers for moduli aren´t equal after swap"); CHECK(ptr1.get() == ptr4.get()); CHECK(ptr2.get() == ptr3.get()); swap(a,b); - std::tr1::shared_ptr ptr_a = a.get_ptr_mod(); - std::tr1::shared_ptr ptr_b = shcpy_a.get_ptr_mod(); + std::shared_ptr ptr_a = a.get_ptr_mod(); + std::shared_ptr ptr_b = shcpy_a.get_ptr_mod(); CHECK(ptr_a.get() == ptr_b_p.get()); CHECK(ptr_b.get() == ptr3.get()); return pass; diff --git a/src/cert/cvc/cvc_ado.cpp b/src/cert/cvc/cvc_ado.cpp index 19d76fe7f..47c972c72 100644 --- a/src/cert/cvc/cvc_ado.cpp +++ b/src/cert/cvc/cvc_ado.cpp @@ -12,7 +12,7 @@ namespace Botan { -EAC1_1_ADO::EAC1_1_ADO(std::tr1::shared_ptr in) +EAC1_1_ADO::EAC1_1_ADO(std::shared_ptr in) { init(in); do_decode(); @@ -20,7 +20,7 @@ EAC1_1_ADO::EAC1_1_ADO(std::tr1::shared_ptr in) EAC1_1_ADO::EAC1_1_ADO(const std::string& in) { - std::tr1::shared_ptr stream(new DataSource_Stream(in, true)); + std::shared_ptr stream(new DataSource_Stream(in, true)); init(stream); do_decode(); } @@ -41,7 +41,7 @@ void EAC1_1_ADO::force_decode() .end_cons() .get_contents(); - std::tr1::shared_ptr req_source(new DataSource_Memory(req_bits)); + std::shared_ptr req_source(new DataSource_Memory(req_bits)); m_req = EAC1_1_Req(req_source); sig_algo = m_req.sig_algo; } diff --git a/src/cert/cvc/cvc_ado.h b/src/cert/cvc/cvc_ado.h index ef469cc09..dbb4a3f47 100644 --- a/src/cert/cvc/cvc_ado.h +++ b/src/cert/cvc/cvc_ado.h @@ -39,7 +39,7 @@ class BOTAN_DLL EAC1_1_ADO : public EAC1_1_obj * Construct a CVC ADO request from a data source * @param source the data source */ - EAC1_1_ADO(std::tr1::shared_ptr source); + EAC1_1_ADO(std::shared_ptr source); /** * Create a signed CVC ADO request from to be signed (TBS) data diff --git a/src/cert/cvc/cvc_ca.cpp b/src/cert/cvc/cvc_ca.cpp index 7b1c5fcba..20cea9104 100644 --- a/src/cert/cvc/cvc_ca.cpp +++ b/src/cert/cvc/cvc_ca.cpp @@ -38,7 +38,7 @@ EAC1_1_CVC EAC1_1_CVC_CA::make_cert(PK_Signer& signer, EAC1_1_CVC::build_cert_body(tbs), rng); - std::tr1::shared_ptr source(new DataSource_Memory(signed_cert)); + std::shared_ptr source(new DataSource_Memory(signed_cert)); return EAC1_1_CVC(source); } diff --git a/src/cert/cvc/cvc_cert.cpp b/src/cert/cvc/cvc_cert.cpp index 7964b8900..352178fd2 100644 --- a/src/cert/cvc/cvc_cert.cpp +++ b/src/cert/cvc/cvc_cert.cpp @@ -78,7 +78,7 @@ void EAC1_1_CVC::force_decode() /* * CVC Certificate Constructor */ -EAC1_1_CVC::EAC1_1_CVC(std::tr1::shared_ptr& in) +EAC1_1_CVC::EAC1_1_CVC(std::shared_ptr& in) { init(in); self_signed = false; @@ -87,7 +87,7 @@ EAC1_1_CVC::EAC1_1_CVC(std::tr1::shared_ptr& in) EAC1_1_CVC::EAC1_1_CVC(const std::string& in) { - std::tr1::shared_ptr stream(new DataSource_Stream(in, true)); + std::shared_ptr stream(new DataSource_Stream(in, true)); init(stream); self_signed = false; do_decode(); diff --git a/src/cert/cvc/cvc_cert.h b/src/cert/cvc/cvc_cert.h index 17671d332..0bc162c0c 100644 --- a/src/cert/cvc/cvc_cert.h +++ b/src/cert/cvc/cvc_cert.h @@ -59,7 +59,7 @@ class BOTAN_DLL EAC1_1_CVC : public EAC1_1_gen_CVC//Signed_Object * Construct a CVC from a data source * @param source the data source */ - EAC1_1_CVC(std::tr1::shared_ptr& source); + EAC1_1_CVC(std::shared_ptr& source); /** * Construct a CVC from a file diff --git a/src/cert/cvc/cvc_req.cpp b/src/cert/cvc/cvc_req.cpp index c2318dc1b..5b2a2c4d4 100644 --- a/src/cert/cvc/cvc_req.cpp +++ b/src/cert/cvc/cvc_req.cpp @@ -50,7 +50,7 @@ void EAC1_1_Req::force_decode() #endif } -EAC1_1_Req::EAC1_1_Req(std::tr1::shared_ptr in) +EAC1_1_Req::EAC1_1_Req(std::shared_ptr in) { init(in); self_signed = true; @@ -59,7 +59,7 @@ EAC1_1_Req::EAC1_1_Req(std::tr1::shared_ptr in) EAC1_1_Req::EAC1_1_Req(const std::string& in) { - std::tr1::shared_ptr stream(new DataSource_Stream(in, true)); + std::shared_ptr stream(new DataSource_Stream(in, true)); init(stream); self_signed = true; do_decode(); diff --git a/src/cert/cvc/cvc_req.h b/src/cert/cvc/cvc_req.h index 8599f539d..4999c332f 100644 --- a/src/cert/cvc/cvc_req.h +++ b/src/cert/cvc/cvc_req.h @@ -36,7 +36,7 @@ class BOTAN_DLL EAC1_1_Req : public EAC1_1_gen_CVC * Construct a CVC request from a data source. * @param source the data source */ - EAC1_1_Req(std::tr1::shared_ptr source); + EAC1_1_Req(std::shared_ptr source); /** * Construct a CVC request from a DER encoded CVC reqeust file. diff --git a/src/cert/cvc/cvc_self.cpp b/src/cert/cvc/cvc_self.cpp index c31741956..47c46ca1c 100644 --- a/src/cert/cvc/cvc_self.cpp +++ b/src/cert/cvc/cvc_self.cpp @@ -136,7 +136,7 @@ EAC1_1_Req create_cvc_req(Private_Key const& key, EAC1_1_gen_CVC::make_signed(*signer.get(), EAC1_1_gen_CVC::build_cert_body(tbs), rng); - std::tr1::shared_ptr source(new DataSource_Memory(signed_cert)); + std::shared_ptr source(new DataSource_Memory(signed_cert)); return EAC1_1_Req(source); } @@ -160,7 +160,7 @@ EAC1_1_ADO create_ado_req(Private_Key const& key, tbs_bits.append(DER_Encoder().encode(car).get_contents()); MemoryVector signed_cert = EAC1_1_ADO::make_signed(*signer.get(), tbs_bits, rng); - std::tr1::shared_ptr source(new DataSource_Memory(signed_cert)); + std::shared_ptr source(new DataSource_Memory(signed_cert)); return EAC1_1_ADO(source); } diff --git a/src/cert/cvc/freestore.h b/src/cert/cvc/freestore.h index f95afa802..a6f779c78 100644 --- a/src/cert/cvc/freestore.h +++ b/src/cert/cvc/freestore.h @@ -7,14 +7,7 @@ #define BOTAN_FREESTORE_H__ #include - -#if defined(BOTAN_USE_STD_TR1) - #include -#elif defined(BOTAN_USE_BOOST_TR1) - #include -#else - #error "Please choose a TR1 implementation in build.h" -#endif +#include namespace Botan { @@ -30,7 +23,7 @@ template class BOTAN_DLL SharedPtrConverter { public: - typedef std::tr1::shared_ptr SharedPtr; + typedef std::shared_ptr SharedPtr; /** * Construct a null pointer equivalent object. diff --git a/src/math/gfpmath/curve_gfp.cpp b/src/math/gfpmath/curve_gfp.cpp index 37555ea06..54799a076 100644 --- a/src/math/gfpmath/curve_gfp.cpp +++ b/src/math/gfpmath/curve_gfp.cpp @@ -13,7 +13,7 @@ namespace Botan { -void CurveGFp::set_shrd_mod(const std::tr1::shared_ptr mod) +void CurveGFp::set_shrd_mod(const std::shared_ptr mod) { mp_mod = mod; mA.turn_off_sp_red_mul();// m.m. is not needed, must be trf. back @@ -33,7 +33,7 @@ CurveGFp::CurveGFp(const GFpElement& a, const GFpElement& b, { throw Invalid_Argument("could not construct curve: moduli of arguments differ"); } - std::tr1::shared_ptr p_mod = std::tr1::shared_ptr(new GFpModulus(p)); + std::shared_ptr p_mod = std::shared_ptr(new GFpModulus(p)); // the above is the creation of the GFpModuls object which will be shared point-wide // (in the context of a point of course) set_shrd_mod(p_mod); @@ -43,21 +43,21 @@ CurveGFp::CurveGFp(const CurveGFp& other) : mA(other.get_a()), mB(other.get_b()) { - mp_mod = std::tr1::shared_ptr(new GFpModulus(*other.mp_mod)); + mp_mod = std::shared_ptr(new GFpModulus(*other.mp_mod)); assert(mp_mod->p_equal_to(mA.get_p())); assert(mp_mod->p_equal_to(mB.get_p())); set_shrd_mod(mp_mod); if(other.mp_mres_a.get()) { - mp_mres_a = std::tr1::shared_ptr(new GFpElement(*other.mp_mres_a)); + mp_mres_a = std::shared_ptr(new GFpElement(*other.mp_mres_a)); } if(other.mp_mres_b.get()) { - mp_mres_b = std::tr1::shared_ptr(new GFpElement(*other.mp_mres_b)); + mp_mres_b = std::shared_ptr(new GFpElement(*other.mp_mres_b)); } if(other.mp_mres_one.get()) { - mp_mres_one = std::tr1::shared_ptr(new GFpElement(*other.mp_mres_one)); + mp_mres_one = std::shared_ptr(new GFpElement(*other.mp_mres_one)); } } @@ -71,21 +71,21 @@ const CurveGFp& CurveGFp::operator=(const CurveGFp& other) mA.swap(a_tmp); mB.swap(b_tmp); - std::tr1::shared_ptr p_mod = std::tr1::shared_ptr(new GFpModulus(*other.mp_mod)); + std::shared_ptr p_mod = std::shared_ptr(new GFpModulus(*other.mp_mod)); set_shrd_mod(p_mod); // exception safety note: no problem if we have a throw from here on... if(other.mp_mres_a.get()) { - mp_mres_a = std::tr1::shared_ptr(new GFpElement(*other.mp_mres_a)); + mp_mres_a = std::shared_ptr(new GFpElement(*other.mp_mres_a)); } if(other.mp_mres_b.get()) { - mp_mres_b = std::tr1::shared_ptr(new GFpElement(*other.mp_mres_b)); + mp_mres_b = std::shared_ptr(new GFpElement(*other.mp_mres_b)); } if(other.mp_mres_one.get()) { - mp_mres_one = std::tr1::shared_ptr(new GFpElement(*other.mp_mres_one)); + mp_mres_one = std::shared_ptr(new GFpElement(*other.mp_mres_one)); } return *this; } @@ -122,7 +122,7 @@ GFpElement const CurveGFp::get_mres_a() const { if(mp_mres_a.get() == 0) { - mp_mres_a = std::tr1::shared_ptr(new GFpElement(mA)); + mp_mres_a = std::shared_ptr(new GFpElement(mA)); mp_mres_a->turn_on_sp_red_mul(); mp_mres_a->get_mres(); } @@ -133,18 +133,18 @@ GFpElement const CurveGFp::get_mres_b() const { if(mp_mres_b.get() == 0) { - mp_mres_b = std::tr1::shared_ptr(new GFpElement(mB)); + mp_mres_b = std::shared_ptr(new GFpElement(mB)); mp_mres_b->turn_on_sp_red_mul(); mp_mres_b->get_mres(); } return GFpElement(*mp_mres_b); } -std::tr1::shared_ptr const CurveGFp::get_mres_one() const +std::shared_ptr const CurveGFp::get_mres_one() const { if(mp_mres_one.get() == 0) { - mp_mres_one = std::tr1::shared_ptr(new GFpElement(mp_mod->get_p(), 1)); + mp_mres_one = std::shared_ptr(new GFpElement(mp_mod->get_p(), 1)); mp_mres_one->turn_on_sp_red_mul(); mp_mres_one->get_mres(); } diff --git a/src/math/gfpmath/curve_gfp.h b/src/math/gfpmath/curve_gfp.h index 90d64b45d..2c9201560 100644 --- a/src/math/gfpmath/curve_gfp.h +++ b/src/math/gfpmath/curve_gfp.h @@ -57,7 +57,7 @@ class BOTAN_DLL CurveGFp * @param mod a shared pointer to a GFpModulus object suitable for * *this. */ - void set_shrd_mod(const std::tr1::shared_ptr mod); + void set_shrd_mod(const std::shared_ptr mod); // getters @@ -99,14 +99,14 @@ class BOTAN_DLL CurveGFp * function. * @result the GFpElement 1, transformed to its m-residue */ - std::tr1::shared_ptr const get_mres_one() const; + std::shared_ptr const get_mres_one() const; /** * Get prime modulus of the field of the curve * @result prime modulus of the field of the curve */ BigInt const get_p() const; - /*inline std::tr1::shared_ptr const get_ptr_p() const + /*inline std::shared_ptr const get_ptr_p() const { return mp_p; }*/ @@ -119,7 +119,7 @@ class BOTAN_DLL CurveGFp * Do NOT spread pointers to a GFpModulus over different threads! * @result a shared pointer to a GFpModulus object */ - inline std::tr1::shared_ptr const get_ptr_mod() const + inline std::shared_ptr const get_ptr_mod() const { return mp_mod; } @@ -131,12 +131,12 @@ class BOTAN_DLL CurveGFp void swap(CurveGFp& other); private: - std::tr1::shared_ptr mp_mod; + std::shared_ptr mp_mod; GFpElement mA; GFpElement mB; - mutable std::tr1::shared_ptr mp_mres_a; - mutable std::tr1::shared_ptr mp_mres_b; - mutable std::tr1::shared_ptr mp_mres_one; + mutable std::shared_ptr mp_mres_a; + mutable std::shared_ptr mp_mres_b; + mutable std::shared_ptr mp_mres_one; }; // relational operators diff --git a/src/math/gfpmath/gfp_element.cpp b/src/math/gfpmath/gfp_element.cpp index 183d7d4ab..7d7b7f34d 100644 --- a/src/math/gfpmath/gfp_element.cpp +++ b/src/math/gfpmath/gfp_element.cpp @@ -173,13 +173,13 @@ GFpElement::GFpElement(const BigInt& p, const BigInt& value, bool use_montgm) m_is_trf(false) { assert(mp_mod.get() == 0); - mp_mod = std::tr1::shared_ptr(new GFpModulus(p)); + mp_mod = std::shared_ptr(new GFpModulus(p)); assert(mp_mod->m_p_dash == 0); if(m_use_montgm) ensure_montgm_precomp(); } -GFpElement::GFpElement(std::tr1::shared_ptr const mod, const BigInt& value, bool use_montgm) +GFpElement::GFpElement(std::shared_ptr const mod, const BigInt& value, bool use_montgm) : mp_mod(), m_value(value % mod->m_p), m_use_montgm(use_montgm), @@ -246,7 +246,7 @@ void GFpElement::ensure_montgm_precomp() const } -void GFpElement::set_shrd_mod(std::tr1::shared_ptr const p_mod) +void GFpElement::set_shrd_mod(std::shared_ptr const p_mod) { mp_mod = p_mod; } diff --git a/src/math/gfpmath/gfp_element.h b/src/math/gfpmath/gfp_element.h index 0a1b4910c..1ee0be0ba 100644 --- a/src/math/gfpmath/gfp_element.h +++ b/src/math/gfpmath/gfp_element.h @@ -15,14 +15,7 @@ #include #include #include - -#if defined(BOTAN_USE_STD_TR1) - #include -#elif defined(BOTAN_USE_BOOST_TR1) - #include -#else - #error "Please choose a TR1 implementation in build.h" -#endif +#include namespace Botan { @@ -40,7 +33,7 @@ struct Illegal_Transformation : public Exception class BOTAN_DLL GFpElement { private: - std::tr1::shared_ptr mp_mod; + std::shared_ptr mp_mod; mutable BigInt m_value; // ordinary residue or m-residue respectively mutable BigInt workspace; @@ -79,7 +72,7 @@ class BOTAN_DLL GFpElement * @param value the element value * @param use_montgm whether this object will use Montgomery multiplication */ - explicit GFpElement(std::tr1::shared_ptr const mod, + explicit GFpElement(std::shared_ptr const mod, const BigInt& value, bool use_mongm = false); /** @@ -190,7 +183,7 @@ class BOTAN_DLL GFpElement * the shared GFpModulus objects! * @result the shared pointer to the GFpModulus of *this */ - inline std::tr1::shared_ptr const get_ptr_mod() const + inline std::shared_ptr const get_ptr_mod() const { return mp_mod; } @@ -203,7 +196,7 @@ class BOTAN_DLL GFpElement * the shared GFpModulus objects! * @param mod a shared pointer to a GFpModulus that will be held in *this */ - void set_shrd_mod(std::tr1::shared_ptr const mod); + void set_shrd_mod(std::shared_ptr const mod); /** * Tells whether this GFpElement is currently transformed to it´ m-residue, diff --git a/src/math/gfpmath/point_gfp.cpp b/src/math/gfpmath/point_gfp.cpp index 9139c3ef9..c997ac525 100644 --- a/src/math/gfpmath/point_gfp.cpp +++ b/src/math/gfpmath/point_gfp.cpp @@ -109,7 +109,7 @@ const PointGFp& PointGFp::assign_within_same_curve(PointGFp const& other) return *this; } -void PointGFp::set_shrd_mod(std::tr1::shared_ptr p_mod) +void PointGFp::set_shrd_mod(std::shared_ptr p_mod) { mX.set_shrd_mod(p_mod); mY.set_shrd_mod(p_mod); @@ -133,7 +133,7 @@ void PointGFp::ensure_worksp() const } } - mp_worksp_gfp_el = std::tr1::shared_ptr >(new std::vector); + mp_worksp_gfp_el = std::shared_ptr >(new std::vector); mp_worksp_gfp_el->reserve(9); for (u32bit i=0; iturn_on_sp_red_mul(); - std::tr1::shared_ptr H(new PointGFp(this->mC)); - std::tr1::shared_ptr tmp; // used for AADA + std::shared_ptr H(new PointGFp(this->mC)); + std::shared_ptr tmp; // used for AADA PointGFp P(*this); BigInt m(scalar); @@ -477,15 +477,15 @@ PointGFp& PointGFp::operator*=(const BigInt& scalar) return *this; } -inline std::tr1::shared_ptr PointGFp::mult_loop(int l, +inline std::shared_ptr PointGFp::mult_loop(int l, const BigInt& m, - std::tr1::shared_ptr H, - std::tr1::shared_ptr tmp, + std::shared_ptr H, + std::shared_ptr tmp, const PointGFp& P) { //assert(l >= (int)m.bits()- 1); tmp = H; - std::tr1::shared_ptr to_add(new PointGFp(P)); // we just need some point + std::shared_ptr to_add(new PointGFp(P)); // we just need some point // so that we can use op= // inside the loop for (int i=l; i >=0; i--) diff --git a/src/math/gfpmath/point_gfp.h b/src/math/gfpmath/point_gfp.h index 771605efc..b001bbbad 100644 --- a/src/math/gfpmath/point_gfp.h +++ b/src/math/gfpmath/point_gfp.h @@ -234,7 +234,7 @@ class BOTAN_DLL PointGFp * @param mod a shared pointer to a GFpModulus that will * be held in the members *this */ - void set_shrd_mod(std::tr1::shared_ptr p_mod); + void set_shrd_mod(std::shared_ptr p_mod); static GFpElement decompress(bool yMod2, GFpElement const& x, const CurveGFp& curve); @@ -242,9 +242,9 @@ class BOTAN_DLL PointGFp static const u32bit GFPEL_WKSP_SIZE = 9; void ensure_worksp() const; - inline std::tr1::shared_ptr mult_loop(int l, const BigInt& m, - std::tr1::shared_ptr H, - std::tr1::shared_ptr tmp, + inline std::shared_ptr mult_loop(int l, const BigInt& m, + std::shared_ptr H, + std::shared_ptr tmp, const PointGFp& P); CurveGFp mC; @@ -257,7 +257,7 @@ class BOTAN_DLL PointGFp mutable bool mZpow2_set; mutable bool mZpow3_set; mutable bool mAZpow4_set; - mutable std::tr1::shared_ptr > mp_worksp_gfp_el; + mutable std::shared_ptr > mp_worksp_gfp_el; }; -- cgit v1.2.3 From 7f715b77711f55d9e30f232ff32001fe9e375a56 Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 3 Jul 2009 04:45:58 +0000 Subject: Move mutex from Attic to src to deal with merge conflict --- Attic/mutex/noop_mutex/info.txt | 10 ----- Attic/mutex/noop_mutex/mux_noop.cpp | 50 ------------------------ Attic/mutex/noop_mutex/mux_noop.h | 26 ------------- Attic/mutex/pthreads/info.txt | 29 -------------- Attic/mutex/pthreads/mux_pthr.cpp | 58 ---------------------------- Attic/mutex/pthreads/mux_pthr.h | 26 ------------- Attic/mutex/qt_mutex/info.txt | 18 --------- Attic/mutex/qt_mutex/mux_qt.cpp | 35 ----------------- Attic/mutex/qt_mutex/mux_qt.h | 27 ------------- Attic/mutex/win32_crit_section/info.txt | 17 -------- Attic/mutex/win32_crit_section/mux_win32.cpp | 34 ---------------- Attic/mutex/win32_crit_section/mux_win32.h | 26 ------------- src/mutex/noop_mutex/info.txt | 10 +++++ src/mutex/noop_mutex/mux_noop.cpp | 50 ++++++++++++++++++++++++ src/mutex/noop_mutex/mux_noop.h | 26 +++++++++++++ src/mutex/pthreads/info.txt | 29 ++++++++++++++ src/mutex/pthreads/mux_pthr.cpp | 58 ++++++++++++++++++++++++++++ src/mutex/pthreads/mux_pthr.h | 26 +++++++++++++ src/mutex/qt_mutex/info.txt | 18 +++++++++ src/mutex/qt_mutex/mux_qt.cpp | 35 +++++++++++++++++ src/mutex/qt_mutex/mux_qt.h | 27 +++++++++++++ src/mutex/win32_crit_section/info.txt | 17 ++++++++ src/mutex/win32_crit_section/mux_win32.cpp | 34 ++++++++++++++++ src/mutex/win32_crit_section/mux_win32.h | 26 +++++++++++++ 24 files changed, 356 insertions(+), 356 deletions(-) delete mode 100644 Attic/mutex/noop_mutex/info.txt delete mode 100644 Attic/mutex/noop_mutex/mux_noop.cpp delete mode 100644 Attic/mutex/noop_mutex/mux_noop.h delete mode 100644 Attic/mutex/pthreads/info.txt delete mode 100644 Attic/mutex/pthreads/mux_pthr.cpp delete mode 100644 Attic/mutex/pthreads/mux_pthr.h delete mode 100644 Attic/mutex/qt_mutex/info.txt delete mode 100644 Attic/mutex/qt_mutex/mux_qt.cpp delete mode 100644 Attic/mutex/qt_mutex/mux_qt.h delete mode 100644 Attic/mutex/win32_crit_section/info.txt delete mode 100644 Attic/mutex/win32_crit_section/mux_win32.cpp delete mode 100644 Attic/mutex/win32_crit_section/mux_win32.h create mode 100644 src/mutex/noop_mutex/info.txt create mode 100644 src/mutex/noop_mutex/mux_noop.cpp create mode 100644 src/mutex/noop_mutex/mux_noop.h create mode 100644 src/mutex/pthreads/info.txt create mode 100644 src/mutex/pthreads/mux_pthr.cpp create mode 100644 src/mutex/pthreads/mux_pthr.h create mode 100644 src/mutex/qt_mutex/info.txt create mode 100644 src/mutex/qt_mutex/mux_qt.cpp create mode 100644 src/mutex/qt_mutex/mux_qt.h create mode 100644 src/mutex/win32_crit_section/info.txt create mode 100644 src/mutex/win32_crit_section/mux_win32.cpp create mode 100644 src/mutex/win32_crit_section/mux_win32.h (limited to 'src') diff --git a/Attic/mutex/noop_mutex/info.txt b/Attic/mutex/noop_mutex/info.txt deleted file mode 100644 index 1f49f5e1c..000000000 --- a/Attic/mutex/noop_mutex/info.txt +++ /dev/null @@ -1,10 +0,0 @@ -realname "No-Op Mutex" - -load_on auto - -define MUTEX_NOOP - - -mux_noop.cpp -mux_noop.h - diff --git a/Attic/mutex/noop_mutex/mux_noop.cpp b/Attic/mutex/noop_mutex/mux_noop.cpp deleted file mode 100644 index 5c45084fe..000000000 --- a/Attic/mutex/noop_mutex/mux_noop.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* -* No-Op Mutex Factory -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include - -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 deleted file mode 100644 index 94201cb7c..000000000 --- a/Attic/mutex/noop_mutex/mux_noop.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -* 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 - -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 deleted file mode 100644 index 88de70de0..000000000 --- a/Attic/mutex/pthreads/info.txt +++ /dev/null @@ -1,29 +0,0 @@ -realname "Pthread Mutex" - -define MUTEX_PTHREAD - -load_on auto - - -mux_pthr.cpp -mux_pthr.h - - - -all!qnx,freebsd,openbsd,netbsd -> pthread - - - -aix -cygwin -darwin -freebsd -hpux -irix -linux -netbsd -openbsd -qnx -solaris -tru64 - diff --git a/Attic/mutex/pthreads/mux_pthr.cpp b/Attic/mutex/pthreads/mux_pthr.cpp deleted file mode 100644 index 9f1d9816e..000000000 --- a/Attic/mutex/pthreads/mux_pthr.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* -* Pthread Mutex -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include -#include - -#ifndef _POSIX_C_SOURCE - #define _POSIX_C_SOURCE 199506 -#endif - -#include - -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 deleted file mode 100644 index 118853947..000000000 --- a/Attic/mutex/pthreads/mux_pthr.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -* 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 - -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 deleted file mode 100644 index a21108c79..000000000 --- a/Attic/mutex/qt_mutex/info.txt +++ /dev/null @@ -1,18 +0,0 @@ -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 - - -mux_qt.cpp -mux_qt.h - - -# I think we want to always use qt-mt, not qt -- not much point in supporting -# mutexes in a single threaded application, after all. - -all -> qt-mt - diff --git a/Attic/mutex/qt_mutex/mux_qt.cpp b/Attic/mutex/qt_mutex/mux_qt.cpp deleted file mode 100644 index 0f670c8b4..000000000 --- a/Attic/mutex/qt_mutex/mux_qt.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* -* Qt Thread Mutex -* (C) 2004-2007 Justin Karneges -* 2004-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include -#include - -#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 deleted file mode 100644 index 5aed77f4b..000000000 --- a/Attic/mutex/qt_mutex/mux_qt.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -* 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 - -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 deleted file mode 100644 index a2d339c3b..000000000 --- a/Attic/mutex/win32_crit_section/info.txt +++ /dev/null @@ -1,17 +0,0 @@ -realname "Win32 Mutex" - -define MUTEX_WIN32 -modset win32 - -load_on auto - - -mux_win32.cpp -mux_win32.h - - - -cygwin -windows -mingw - diff --git a/Attic/mutex/win32_crit_section/mux_win32.cpp b/Attic/mutex/win32_crit_section/mux_win32.cpp deleted file mode 100644 index 2a967892b..000000000 --- a/Attic/mutex/win32_crit_section/mux_win32.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* -* Win32 Mutex -* (C) 2006 Luca Piccarreta -* 2006-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include -#include - -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 deleted file mode 100644 index a91850e71..000000000 --- a/Attic/mutex/win32_crit_section/mux_win32.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -* 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 - -namespace Botan { - -/* -* Win32 Mutex Factory -*/ -class BOTAN_DLL Win32_Mutex_Factory : public Mutex_Factory - { - public: - Mutex* make(); - }; -} - -#endif diff --git a/src/mutex/noop_mutex/info.txt b/src/mutex/noop_mutex/info.txt new file mode 100644 index 000000000..1f49f5e1c --- /dev/null +++ b/src/mutex/noop_mutex/info.txt @@ -0,0 +1,10 @@ +realname "No-Op Mutex" + +load_on auto + +define MUTEX_NOOP + + +mux_noop.cpp +mux_noop.h + diff --git a/src/mutex/noop_mutex/mux_noop.cpp b/src/mutex/noop_mutex/mux_noop.cpp new file mode 100644 index 000000000..5c45084fe --- /dev/null +++ b/src/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 + +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/mutex/noop_mutex/mux_noop.h b/src/mutex/noop_mutex/mux_noop.h new file mode 100644 index 000000000..94201cb7c --- /dev/null +++ b/src/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 + +namespace Botan { + +/* +* No-Op Mutex Factory +*/ +class BOTAN_DLL Noop_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; + +} + +#endif diff --git a/src/mutex/pthreads/info.txt b/src/mutex/pthreads/info.txt new file mode 100644 index 000000000..88de70de0 --- /dev/null +++ b/src/mutex/pthreads/info.txt @@ -0,0 +1,29 @@ +realname "Pthread Mutex" + +define MUTEX_PTHREAD + +load_on auto + + +mux_pthr.cpp +mux_pthr.h + + + +all!qnx,freebsd,openbsd,netbsd -> pthread + + + +aix +cygwin +darwin +freebsd +hpux +irix +linux +netbsd +openbsd +qnx +solaris +tru64 + diff --git a/src/mutex/pthreads/mux_pthr.cpp b/src/mutex/pthreads/mux_pthr.cpp new file mode 100644 index 000000000..9f1d9816e --- /dev/null +++ b/src/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 +#include + +#ifndef _POSIX_C_SOURCE + #define _POSIX_C_SOURCE 199506 +#endif + +#include + +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/mutex/pthreads/mux_pthr.h b/src/mutex/pthreads/mux_pthr.h new file mode 100644 index 000000000..118853947 --- /dev/null +++ b/src/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 + +namespace Botan { + +/* +* Pthread Mutex Factory +*/ +class BOTAN_DLL Pthread_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; + +} + +#endif diff --git a/src/mutex/qt_mutex/info.txt b/src/mutex/qt_mutex/info.txt new file mode 100644 index 000000000..a21108c79 --- /dev/null +++ b/src/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 + + +mux_qt.cpp +mux_qt.h + + +# I think we want to always use qt-mt, not qt -- not much point in supporting +# mutexes in a single threaded application, after all. + +all -> qt-mt + diff --git a/src/mutex/qt_mutex/mux_qt.cpp b/src/mutex/qt_mutex/mux_qt.cpp new file mode 100644 index 000000000..0f670c8b4 --- /dev/null +++ b/src/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 +#include + +#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/mutex/qt_mutex/mux_qt.h b/src/mutex/qt_mutex/mux_qt.h new file mode 100644 index 000000000..5aed77f4b --- /dev/null +++ b/src/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 + +namespace Botan { + +/* +* Qt Mutex +*/ +class BOTAN_DLL Qt_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; + +} + +#endif diff --git a/src/mutex/win32_crit_section/info.txt b/src/mutex/win32_crit_section/info.txt new file mode 100644 index 000000000..a2d339c3b --- /dev/null +++ b/src/mutex/win32_crit_section/info.txt @@ -0,0 +1,17 @@ +realname "Win32 Mutex" + +define MUTEX_WIN32 +modset win32 + +load_on auto + + +mux_win32.cpp +mux_win32.h + + + +cygwin +windows +mingw + diff --git a/src/mutex/win32_crit_section/mux_win32.cpp b/src/mutex/win32_crit_section/mux_win32.cpp new file mode 100644 index 000000000..2a967892b --- /dev/null +++ b/src/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 +#include + +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/mutex/win32_crit_section/mux_win32.h b/src/mutex/win32_crit_section/mux_win32.h new file mode 100644 index 000000000..a91850e71 --- /dev/null +++ b/src/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 + +namespace Botan { + +/* +* Win32 Mutex Factory +*/ +class BOTAN_DLL Win32_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; +} + +#endif -- cgit v1.2.3 From ce5cab439b617800f48c94ebaeeb7cd3bd786cfe Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 3 Jul 2009 04:46:44 +0000 Subject: Move mutex.h to src/mutex (from Attic) --- Attic/mutex.h | 56 ------------------------------------------------------- src/mutex/mutex.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 56 deletions(-) delete mode 100644 Attic/mutex.h create mode 100644 src/mutex/mutex.h (limited to 'src') diff --git a/Attic/mutex.h b/Attic/mutex.h deleted file mode 100644 index a04ff83c9..000000000 --- a/Attic/mutex.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -* Mutex -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_MUTEX_H__ -#define BOTAN_MUTEX_H__ - -#include - -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/src/mutex/mutex.h b/src/mutex/mutex.h new file mode 100644 index 000000000..a04ff83c9 --- /dev/null +++ b/src/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 + +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 -- cgit v1.2.3 From b438a3c6d08893ca77a1d18baef1b02e955eccf8 Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 3 Jul 2009 04:47:49 +0000 Subject: Move mutex directory back to the Attic --- Attic/mutex/info.txt | 9 +++++ Attic/mutex/mutex.h | 56 +++++++++++++++++++++++++++ Attic/mutex/noop_mutex/info.txt | 10 +++++ Attic/mutex/noop_mutex/mux_noop.cpp | 50 ++++++++++++++++++++++++ Attic/mutex/noop_mutex/mux_noop.h | 26 +++++++++++++ Attic/mutex/pthreads/info.txt | 29 ++++++++++++++ Attic/mutex/pthreads/mux_pthr.cpp | 58 ++++++++++++++++++++++++++++ Attic/mutex/pthreads/mux_pthr.h | 26 +++++++++++++ Attic/mutex/qt_mutex/info.txt | 18 +++++++++ Attic/mutex/qt_mutex/mux_qt.cpp | 35 +++++++++++++++++ Attic/mutex/qt_mutex/mux_qt.h | 27 +++++++++++++ Attic/mutex/win32_crit_section/info.txt | 17 ++++++++ Attic/mutex/win32_crit_section/mux_win32.cpp | 34 ++++++++++++++++ Attic/mutex/win32_crit_section/mux_win32.h | 26 +++++++++++++ src/mutex/info.txt | 9 ----- src/mutex/mutex.h | 56 --------------------------- src/mutex/noop_mutex/info.txt | 10 ----- src/mutex/noop_mutex/mux_noop.cpp | 50 ------------------------ src/mutex/noop_mutex/mux_noop.h | 26 ------------- src/mutex/pthreads/info.txt | 29 -------------- src/mutex/pthreads/mux_pthr.cpp | 58 ---------------------------- src/mutex/pthreads/mux_pthr.h | 26 ------------- src/mutex/qt_mutex/info.txt | 18 --------- src/mutex/qt_mutex/mux_qt.cpp | 35 ----------------- src/mutex/qt_mutex/mux_qt.h | 27 ------------- src/mutex/win32_crit_section/info.txt | 17 -------- src/mutex/win32_crit_section/mux_win32.cpp | 34 ---------------- src/mutex/win32_crit_section/mux_win32.h | 26 ------------- 28 files changed, 421 insertions(+), 421 deletions(-) create mode 100644 Attic/mutex/info.txt create mode 100644 Attic/mutex/mutex.h create mode 100644 Attic/mutex/noop_mutex/info.txt create mode 100644 Attic/mutex/noop_mutex/mux_noop.cpp create mode 100644 Attic/mutex/noop_mutex/mux_noop.h create mode 100644 Attic/mutex/pthreads/info.txt create mode 100644 Attic/mutex/pthreads/mux_pthr.cpp create mode 100644 Attic/mutex/pthreads/mux_pthr.h create mode 100644 Attic/mutex/qt_mutex/info.txt create mode 100644 Attic/mutex/qt_mutex/mux_qt.cpp create mode 100644 Attic/mutex/qt_mutex/mux_qt.h create mode 100644 Attic/mutex/win32_crit_section/info.txt create mode 100644 Attic/mutex/win32_crit_section/mux_win32.cpp create mode 100644 Attic/mutex/win32_crit_section/mux_win32.h delete mode 100644 src/mutex/info.txt delete mode 100644 src/mutex/mutex.h delete mode 100644 src/mutex/noop_mutex/info.txt delete mode 100644 src/mutex/noop_mutex/mux_noop.cpp delete mode 100644 src/mutex/noop_mutex/mux_noop.h delete mode 100644 src/mutex/pthreads/info.txt delete mode 100644 src/mutex/pthreads/mux_pthr.cpp delete mode 100644 src/mutex/pthreads/mux_pthr.h delete mode 100644 src/mutex/qt_mutex/info.txt delete mode 100644 src/mutex/qt_mutex/mux_qt.cpp delete mode 100644 src/mutex/qt_mutex/mux_qt.h delete mode 100644 src/mutex/win32_crit_section/info.txt delete mode 100644 src/mutex/win32_crit_section/mux_win32.cpp delete mode 100644 src/mutex/win32_crit_section/mux_win32.h (limited to 'src') diff --git a/Attic/mutex/info.txt b/Attic/mutex/info.txt new file mode 100644 index 000000000..ff79bf753 --- /dev/null +++ b/Attic/mutex/info.txt @@ -0,0 +1,9 @@ +realname "Mutex Wrappers" + +define MUTEX_WRAPPERS + +load_on auto + + +mutex.h + 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 + +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..1f49f5e1c --- /dev/null +++ b/Attic/mutex/noop_mutex/info.txt @@ -0,0 +1,10 @@ +realname "No-Op Mutex" + +load_on auto + +define MUTEX_NOOP + + +mux_noop.cpp +mux_noop.h + 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 + +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 + +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..88de70de0 --- /dev/null +++ b/Attic/mutex/pthreads/info.txt @@ -0,0 +1,29 @@ +realname "Pthread Mutex" + +define MUTEX_PTHREAD + +load_on auto + + +mux_pthr.cpp +mux_pthr.h + + + +all!qnx,freebsd,openbsd,netbsd -> pthread + + + +aix +cygwin +darwin +freebsd +hpux +irix +linux +netbsd +openbsd +qnx +solaris +tru64 + 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 +#include + +#ifndef _POSIX_C_SOURCE + #define _POSIX_C_SOURCE 199506 +#endif + +#include + +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 + +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..a21108c79 --- /dev/null +++ b/Attic/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 + + +mux_qt.cpp +mux_qt.h + + +# I think we want to always use qt-mt, not qt -- not much point in supporting +# mutexes in a single threaded application, after all. + +all -> qt-mt + 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 +#include + +#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 + +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..a2d339c3b --- /dev/null +++ b/Attic/mutex/win32_crit_section/info.txt @@ -0,0 +1,17 @@ +realname "Win32 Mutex" + +define MUTEX_WIN32 +modset win32 + +load_on auto + + +mux_win32.cpp +mux_win32.h + + + +cygwin +windows +mingw + 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 +#include + +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 + +namespace Botan { + +/* +* Win32 Mutex Factory +*/ +class BOTAN_DLL Win32_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; +} + +#endif diff --git a/src/mutex/info.txt b/src/mutex/info.txt deleted file mode 100644 index ff79bf753..000000000 --- a/src/mutex/info.txt +++ /dev/null @@ -1,9 +0,0 @@ -realname "Mutex Wrappers" - -define MUTEX_WRAPPERS - -load_on auto - - -mutex.h - diff --git a/src/mutex/mutex.h b/src/mutex/mutex.h deleted file mode 100644 index a04ff83c9..000000000 --- a/src/mutex/mutex.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -* Mutex -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_MUTEX_H__ -#define BOTAN_MUTEX_H__ - -#include - -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/src/mutex/noop_mutex/info.txt b/src/mutex/noop_mutex/info.txt deleted file mode 100644 index 1f49f5e1c..000000000 --- a/src/mutex/noop_mutex/info.txt +++ /dev/null @@ -1,10 +0,0 @@ -realname "No-Op Mutex" - -load_on auto - -define MUTEX_NOOP - - -mux_noop.cpp -mux_noop.h - diff --git a/src/mutex/noop_mutex/mux_noop.cpp b/src/mutex/noop_mutex/mux_noop.cpp deleted file mode 100644 index 5c45084fe..000000000 --- a/src/mutex/noop_mutex/mux_noop.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* -* No-Op Mutex Factory -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include - -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/mutex/noop_mutex/mux_noop.h b/src/mutex/noop_mutex/mux_noop.h deleted file mode 100644 index 94201cb7c..000000000 --- a/src/mutex/noop_mutex/mux_noop.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -* 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 - -namespace Botan { - -/* -* No-Op Mutex Factory -*/ -class BOTAN_DLL Noop_Mutex_Factory : public Mutex_Factory - { - public: - Mutex* make(); - }; - -} - -#endif diff --git a/src/mutex/pthreads/info.txt b/src/mutex/pthreads/info.txt deleted file mode 100644 index 88de70de0..000000000 --- a/src/mutex/pthreads/info.txt +++ /dev/null @@ -1,29 +0,0 @@ -realname "Pthread Mutex" - -define MUTEX_PTHREAD - -load_on auto - - -mux_pthr.cpp -mux_pthr.h - - - -all!qnx,freebsd,openbsd,netbsd -> pthread - - - -aix -cygwin -darwin -freebsd -hpux -irix -linux -netbsd -openbsd -qnx -solaris -tru64 - diff --git a/src/mutex/pthreads/mux_pthr.cpp b/src/mutex/pthreads/mux_pthr.cpp deleted file mode 100644 index 9f1d9816e..000000000 --- a/src/mutex/pthreads/mux_pthr.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* -* Pthread Mutex -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include -#include - -#ifndef _POSIX_C_SOURCE - #define _POSIX_C_SOURCE 199506 -#endif - -#include - -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/mutex/pthreads/mux_pthr.h b/src/mutex/pthreads/mux_pthr.h deleted file mode 100644 index 118853947..000000000 --- a/src/mutex/pthreads/mux_pthr.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -* 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 - -namespace Botan { - -/* -* Pthread Mutex Factory -*/ -class BOTAN_DLL Pthread_Mutex_Factory : public Mutex_Factory - { - public: - Mutex* make(); - }; - -} - -#endif diff --git a/src/mutex/qt_mutex/info.txt b/src/mutex/qt_mutex/info.txt deleted file mode 100644 index a21108c79..000000000 --- a/src/mutex/qt_mutex/info.txt +++ /dev/null @@ -1,18 +0,0 @@ -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 - - -mux_qt.cpp -mux_qt.h - - -# I think we want to always use qt-mt, not qt -- not much point in supporting -# mutexes in a single threaded application, after all. - -all -> qt-mt - diff --git a/src/mutex/qt_mutex/mux_qt.cpp b/src/mutex/qt_mutex/mux_qt.cpp deleted file mode 100644 index 0f670c8b4..000000000 --- a/src/mutex/qt_mutex/mux_qt.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* -* Qt Thread Mutex -* (C) 2004-2007 Justin Karneges -* 2004-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include -#include - -#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/mutex/qt_mutex/mux_qt.h b/src/mutex/qt_mutex/mux_qt.h deleted file mode 100644 index 5aed77f4b..000000000 --- a/src/mutex/qt_mutex/mux_qt.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -* 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 - -namespace Botan { - -/* -* Qt Mutex -*/ -class BOTAN_DLL Qt_Mutex_Factory : public Mutex_Factory - { - public: - Mutex* make(); - }; - -} - -#endif diff --git a/src/mutex/win32_crit_section/info.txt b/src/mutex/win32_crit_section/info.txt deleted file mode 100644 index a2d339c3b..000000000 --- a/src/mutex/win32_crit_section/info.txt +++ /dev/null @@ -1,17 +0,0 @@ -realname "Win32 Mutex" - -define MUTEX_WIN32 -modset win32 - -load_on auto - - -mux_win32.cpp -mux_win32.h - - - -cygwin -windows -mingw - diff --git a/src/mutex/win32_crit_section/mux_win32.cpp b/src/mutex/win32_crit_section/mux_win32.cpp deleted file mode 100644 index 2a967892b..000000000 --- a/src/mutex/win32_crit_section/mux_win32.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* -* Win32 Mutex -* (C) 2006 Luca Piccarreta -* 2006-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include -#include - -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/mutex/win32_crit_section/mux_win32.h b/src/mutex/win32_crit_section/mux_win32.h deleted file mode 100644 index a91850e71..000000000 --- a/src/mutex/win32_crit_section/mux_win32.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -* 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 - -namespace Botan { - -/* -* Win32 Mutex Factory -*/ -class BOTAN_DLL Win32_Mutex_Factory : public Mutex_Factory - { - public: - Mutex* make(); - }; -} - -#endif -- cgit v1.2.3 From aa7beddcc30d256dbcaea55a951ca75c5361b2b4 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 9 Sep 2009 00:03:55 +0000 Subject: Use GCC 4.4.1-release for C++0x testing --- src/build-data/cc/gcc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/build-data/cc/gcc b/src/build-data/cc/gcc index 7ab80b6ca..23671efce 100644 --- a/src/build-data/cc/gcc +++ b/src/build-data/cc/gcc @@ -1,6 +1,6 @@ realname "GNU C++" -binary_name "g++-4.4-20090331" +binary_name "g++-4.4.1" compiler_has_tr1 yes -- cgit v1.2.3 From cc8b60c7f5ea6be28848498367645cbccba035e8 Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 11 Sep 2009 19:26:44 +0000 Subject: Remove dep on mutex module (doesn't exist here). Use initializer list in libstate.cpp --- src/algo_factory/info.txt | 1 - src/alloc/mem_pool/info.txt | 4 ---- src/libstate/info.txt | 2 -- src/libstate/libstate.cpp | 22 +++++++++++----------- 4 files changed, 11 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/algo_factory/info.txt b/src/algo_factory/info.txt index dfc42230a..fc248523d 100644 --- a/src/algo_factory/info.txt +++ b/src/algo_factory/info.txt @@ -16,6 +16,5 @@ block engine hash mac -mutex stream diff --git a/src/alloc/mem_pool/info.txt b/src/alloc/mem_pool/info.txt index 0a762ccc4..b1c7a091f 100644 --- a/src/alloc/mem_pool/info.txt +++ b/src/alloc/mem_pool/info.txt @@ -6,7 +6,3 @@ load_on auto mem_pool.cpp mem_pool.h - - -mutex - diff --git a/src/libstate/info.txt b/src/libstate/info.txt index 6eaa2f70b..fcf386e6d 100644 --- a/src/libstate/info.txt +++ b/src/libstate/info.txt @@ -34,8 +34,6 @@ hash kdf mac mode_pad -mutex -noop_mutex pk_pad pubkey rng diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp index 839d71d60..676c2a949 100644 --- a/src/libstate/libstate.cpp +++ b/src/libstate/libstate.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -77,7 +76,7 @@ void set_global_state(Library_State* new_state) */ Library_State* swap_global_state(Library_State* new_state) { - Library_State* old_state = global_lib_state; + auto old_state = global_lib_state; global_lib_state = new_state; return old_state; } @@ -124,11 +123,11 @@ void Library_State::add_allocator(Allocator* allocator) */ void Library_State::set_default_allocator(const std::string& type) { - std::lock_guard lock(allocator_lock); - if(type == "") return; + std::lock_guard lock(allocator_lock); + this->set("conf", "base/default_allocator", type); cached_default_allocator = 0; } @@ -240,29 +239,30 @@ void Library_State::initialize() load_default_config(); - std::vector engines; + std::vector engines = { #if defined(BOTAN_HAS_ENGINE_GNU_MP) - engines.push_back(new GMP_Engine); + new GMP_Engine, #endif #if defined(BOTAN_HAS_ENGINE_OPENSSL) - engines.push_back(new OpenSSL_Engine); + new OpenSSL_Engine, #endif #if defined(BOTAN_HAS_ENGINE_SSE2_ASSEMBLER) - engines.push_back(new SSE2_Assembler_Engine); + new SSE2_Assembler_Engine, #endif #if defined(BOTAN_HAS_ENGINE_AMD64_ASSEMBLER) - engines.push_back(new AMD64_Assembler_Engine); + new AMD64_Assembler_Engine, #endif #if defined(BOTAN_HAS_ENGINE_IA32_ASSEMBLER) - engines.push_back(new IA32_Assembler_Engine); + new IA32_Assembler_Engine, #endif - engines.push_back(new Default_Engine); + new Default_Engine + }; m_algorithm_factory = new Algorithm_Factory(engines); } -- cgit v1.2.3 From 69e8cc40848b95a644fb952c73788e825c1683ba Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 16 Sep 2009 15:56:55 +0000 Subject: Use in the runtime benchmarking code instead of the local timers. --- doc/examples/bench.cpp | 3 +- src/benchmark/benchmark.cpp | 76 +++++++++++++++++++++++++++------------------ src/benchmark/benchmark.h | 26 +--------------- src/benchmark/info.txt | 1 - 4 files changed, 48 insertions(+), 58 deletions(-) (limited to 'src') diff --git a/doc/examples/bench.cpp b/doc/examples/bench.cpp index 0aedc699d..7d53e0557 100644 --- a/doc/examples/bench.cpp +++ b/doc/examples/bench.cpp @@ -66,7 +66,6 @@ int main() u32bit milliseconds = 1000; AutoSeeded_RNG rng; - Default_Benchmark_Timer timer; Algorithm_Factory& af = global_state().algorithm_factory(); @@ -75,7 +74,7 @@ int main() std::string algo = algos[i]; std::map speeds = - algorithm_benchmark(algos[i], milliseconds, timer, rng, af); + algorithm_benchmark(algos[i], milliseconds, rng, af); std::cout << algo << ":"; diff --git a/src/benchmark/benchmark.cpp b/src/benchmark/benchmark.cpp index 3bbc1f883..ff7519c09 100644 --- a/src/benchmark/benchmark.cpp +++ b/src/benchmark/benchmark.cpp @@ -1,6 +1,6 @@ /** * Runtime benchmarking -* (C) 2008 Jack Lloyd +* (C) 2008-2009 Jack Lloyd * * Distributed under the terms of the Botan license */ @@ -13,31 +13,40 @@ #include #include #include +#include +#include namespace Botan { namespace { +typedef std::chrono::high_resolution_clock benchmark_clock; + /** * Benchmark BufferedComputation (hash or MAC) */ std::pair bench_buf_comp(BufferedComputation* buf_comp, - Timer& timer, u64bit nanoseconds_max, const byte buf[], u32bit buf_len) { - const u64bit start = timer.clock(); - u64bit nanoseconds_used = 0; u64bit reps = 0; - while(nanoseconds_used < nanoseconds_max) + std::chrono::nanoseconds max_time(nanoseconds_max); + std::chrono::nanoseconds time_used(0); + + auto start = benchmark_clock::now(); + + while(time_used < max_time) { buf_comp->update(buf, buf_len); ++reps; - nanoseconds_used = timer.clock() - start; + time_used = benchmark_clock::now() - start; } - return std::make_pair(reps * buf_len, nanoseconds_used); + u64bit ns_taken = + std::chrono::duration_cast(time_used).count(); + + return std::make_pair(reps * buf_len, ns_taken); } /** @@ -45,26 +54,30 @@ std::pair bench_buf_comp(BufferedComputation* buf_comp, */ std::pair bench_block_cipher(BlockCipher* block_cipher, - Timer& timer, u64bit nanoseconds_max, byte buf[], u32bit buf_len) { - const u64bit start = timer.clock(); - u64bit nanoseconds_used = 0; + const u32bit in_blocks = buf_len / block_cipher->BLOCK_SIZE; + u64bit reps = 0; - const u32bit in_blocks = buf_len / block_cipher->BLOCK_SIZE; + std::chrono::nanoseconds max_time(nanoseconds_max); + std::chrono::nanoseconds time_used(0); - while(nanoseconds_used < nanoseconds_max) + auto start = benchmark_clock::now(); + + while(time_used < max_time) { block_cipher->encrypt_n(buf, buf, in_blocks); - ++reps; - nanoseconds_used = timer.clock() - start; + time_used = benchmark_clock::now() - start; } + u64bit ns_taken = + std::chrono::duration_cast(time_used).count(); + return std::make_pair(reps * in_blocks * block_cipher->BLOCK_SIZE, - nanoseconds_used); + ns_taken); } /** @@ -72,33 +85,38 @@ bench_block_cipher(BlockCipher* block_cipher, */ std::pair bench_stream_cipher(StreamCipher* stream_cipher, - Timer& timer, u64bit nanoseconds_max, byte buf[], u32bit buf_len) { - const u64bit start = timer.clock(); - u64bit nanoseconds_used = 0; u64bit reps = 0; - while(nanoseconds_used < nanoseconds_max) + std::chrono::nanoseconds max_time(nanoseconds_max); + std::chrono::nanoseconds time_used(0); + + auto start = benchmark_clock::now(); + + while(time_used < max_time) { stream_cipher->encrypt(buf, buf_len); ++reps; - nanoseconds_used = timer.clock() - start; + time_used = benchmark_clock::now() - start; } - return std::make_pair(reps * buf_len, nanoseconds_used); + u64bit ns_taken = + std::chrono::duration_cast(time_used).count(); + + return std::make_pair(reps * buf_len, ns_taken); } /** * Benchmark hash */ std::pair -bench_hash(HashFunction* hash, Timer& timer, +bench_hash(HashFunction* hash, u64bit nanoseconds_max, const byte buf[], u32bit buf_len) { - return bench_buf_comp(hash, timer, nanoseconds_max, buf, buf_len); + return bench_buf_comp(hash, nanoseconds_max, buf, buf_len); } /** @@ -106,12 +124,11 @@ bench_hash(HashFunction* hash, Timer& timer, */ std::pair bench_mac(MessageAuthenticationCode* mac, - Timer& timer, u64bit nanoseconds_max, const byte buf[], u32bit buf_len) { mac->set_key(buf, mac->MAXIMUM_KEYLENGTH); - return bench_buf_comp(mac, timer, nanoseconds_max, buf, buf_len); + return bench_buf_comp(mac, nanoseconds_max, buf, buf_len); } } @@ -119,7 +136,6 @@ bench_mac(MessageAuthenticationCode* mac, std::map algorithm_benchmark(const std::string& name, u32bit milliseconds, - Timer& timer, RandomNumberGenerator& rng, Algorithm_Factory& af) { @@ -145,7 +161,7 @@ algorithm_benchmark(const std::string& name, af.prototype_block_cipher(name, provider)) { std::auto_ptr block_cipher(proto->clone()); - results = bench_block_cipher(block_cipher.get(), timer, + results = bench_block_cipher(block_cipher.get(), ns_per_provider, &buf[0], buf.size()); } @@ -153,7 +169,7 @@ algorithm_benchmark(const std::string& name, af.prototype_stream_cipher(name, provider)) { std::auto_ptr stream_cipher(proto->clone()); - results = bench_stream_cipher(stream_cipher.get(), timer, + results = bench_stream_cipher(stream_cipher.get(), ns_per_provider, &buf[0], buf.size()); } @@ -161,14 +177,14 @@ algorithm_benchmark(const std::string& name, af.prototype_hash_function(name, provider)) { std::auto_ptr hash(proto->clone()); - results = bench_hash(hash.get(), timer, ns_per_provider, + results = bench_hash(hash.get(), ns_per_provider, &buf[0], buf.size()); } else if(const MessageAuthenticationCode* proto = af.prototype_mac(name, provider)) { std::auto_ptr mac(proto->clone()); - results = bench_mac(mac.get(), timer, ns_per_provider, + results = bench_mac(mac.get(), ns_per_provider, &buf[0], buf.size()); } diff --git a/src/benchmark/benchmark.h b/src/benchmark/benchmark.h index 272cfdfa2..a9c3fc01e 100644 --- a/src/benchmark/benchmark.h +++ b/src/benchmark/benchmark.h @@ -1,6 +1,6 @@ /** * Runtime benchmarking -* (C) 2008 Jack Lloyd +* (C) 2008-2009 Jack Lloyd * * Distributed under the terms of the Botan license */ @@ -9,35 +9,12 @@ #define BOTAN_RUNTIME_BENCHMARK_H__ #include -#include #include #include #include -/** -* Choose some sort of default timer implementation to use, since some -* (like hardware tick counters and current Win32 timer) are not -* reliable for benchmarking. -*/ -#if defined(BOTAN_HAS_TIMER_POSIX) - #include -#elif defined(BOTAN_HAS_TIMER_UNIX) - #include -#endif - namespace Botan { -#if defined(BOTAN_HAS_TIMER_POSIX) - typedef POSIX_Timer Default_Benchmark_Timer; -#elif defined(BOTAN_HAS_TIMER_UNIX) - typedef Unix_Timer Default_Benchmark_Timer; -#else - /* I have not had good success using clock(), the results seem - * pretty bogus, but as a last resort it works. - */ - typedef ANSI_Clock_Timer Default_Benchmark_Timer; -#endif - /** * Algorithm benchmark * @param name the name of the algorithm to test (cipher, hash, or MAC) @@ -50,7 +27,6 @@ namespace Botan { std::map algorithm_benchmark(const std::string& name, u32bit milliseconds, - Timer& timer, RandomNumberGenerator& rng, Algorithm_Factory& af); diff --git a/src/benchmark/info.txt b/src/benchmark/info.txt index 0fbcdb2de..03d5aac50 100644 --- a/src/benchmark/info.txt +++ b/src/benchmark/info.txt @@ -17,5 +17,4 @@ hash mac rng stream -timer -- cgit v1.2.3 From 1b0448fae6652a2da7f0de1fdcd2bbcda9836ca9 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 30 Sep 2009 18:06:12 +0000 Subject: Change call to system_time to use std::chrono --- src/rng/randpool/randpool.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/rng/randpool/randpool.cpp b/src/rng/randpool/randpool.cpp index fe83f4361..b018a0d17 100644 --- a/src/rng/randpool/randpool.cpp +++ b/src/rng/randpool/randpool.cpp @@ -8,9 +8,9 @@ #include #include #include -#include #include #include +#include namespace Botan { @@ -51,7 +51,9 @@ void Randpool::randomize(byte out[], u32bit length) */ void Randpool::update_buffer() { - const u64bit timestamp = system_time(); + const u64bit timestamp = + std::chrono::duration_cast( + std::chrono::high_resolution_clock::now().time_since_epoch()).count(); for(u32bit i = 0; i != counter.size(); ++i) if(++counter[i]) -- cgit v1.2.3 From 07cfdf3f06f35735483d4cdde9efdba558131337 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 13 Oct 2009 19:49:13 +0000 Subject: Fixup post-merge breakage --- src/libstate/libstate.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp index 4d915973c..66e606880 100644 --- a/src/libstate/libstate.cpp +++ b/src/libstate/libstate.cpp @@ -85,7 +85,7 @@ Library_State* swap_global_state(Library_State* new_state) /* * Get an allocator by its name */ -Allocator* Library_State::get_allocator(const std::string& type) const +Allocator* Library_State::get_allocator(const std::string& type) { std::lock_guard lock(allocator_lock); @@ -137,7 +137,7 @@ void Library_State::set_default_allocator(const std::string& type) * Get a configuration value */ std::string Library_State::get(const std::string& section, - const std::string& key) const + const std::string& key) { std::lock_guard lock(config_lock); @@ -149,7 +149,7 @@ std::string Library_State::get(const std::string& section, * See if a particular option has been set */ bool Library_State::is_set(const std::string& section, - const std::string& key) const + const std::string& key) { std::lock_guard lock(config_lock); @@ -184,7 +184,7 @@ void Library_State::add_alias(const std::string& key, const std::string& value) /* * Dereference an alias to a fixed name */ -std::string Library_State::deref_alias(const std::string& key) const +std::string Library_State::deref_alias(const std::string& key) { std::string result = key; while(is_set("alias", result)) @@ -204,7 +204,7 @@ void Library_State::set_option(const std::string& key, /* * Get an option value */ -std::string Library_State::option(const std::string& key) const +std::string Library_State::option(const std::string& key) { return get("conf", key); } -- cgit v1.2.3 From 1860316d9832cc0f93d93ff6fcb0059c92c07383 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 13 Oct 2009 19:49:23 +0000 Subject: Fixup post-merge breakage --- src/utils/parsing.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/utils/parsing.cpp b/src/utils/parsing.cpp index 7bd81b5d1..63dfce64f 100644 --- a/src/utils/parsing.cpp +++ b/src/utils/parsing.cpp @@ -23,7 +23,7 @@ u32bit to_u32bit(const std::string& number) { const u32bit OVERFLOW_MARK = 0xFFFFFFFF / 10; - if(*j == ' ') + if(*i == ' ') continue; byte digit = Charset::char2digit(*i); -- cgit v1.2.3 From 92f31b22dfe2aa1b2bde84cbaf4ce7365fa4ec68 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 13 Oct 2009 21:27:28 +0000 Subject: Attic-ize all of src/timer, except for time_t_to_tm and system_time (which will go later) which will live in the new time.h --- Attic/timer/cpu_counter/info.txt | 36 +++++++++++++++ Attic/timer/cpu_counter/tm_hard.cpp | 51 +++++++++++++++++++++ Attic/timer/cpu_counter/tm_hard.h | 33 ++++++++++++++ Attic/timer/gettimeofday/info.txt | 33 ++++++++++++++ Attic/timer/gettimeofday/tm_unix.cpp | 23 ++++++++++ Attic/timer/gettimeofday/tm_unix.h | 27 +++++++++++ Attic/timer/info.txt | 14 ++++++ Attic/timer/posix_rt/info.txt | 29 ++++++++++++ Attic/timer/posix_rt/tm_posix.cpp | 32 ++++++++++++++ Attic/timer/posix_rt/tm_posix.h | 27 +++++++++++ Attic/timer/timer.cpp | 64 +++++++++++++++++++++++++++ Attic/timer/timer.h | 53 ++++++++++++++++++++++ Attic/timer/win32_query_perf_ctr/info.txt | 26 +++++++++++ Attic/timer/win32_query_perf_ctr/tm_win32.cpp | 23 ++++++++++ Attic/timer/win32_query_perf_ctr/tm_win32.h | 27 +++++++++++ checks/cvc_tests.cpp | 2 +- src/asn1/asn1_tm.cpp | 2 +- src/cert/cvc/asn1_eac_tm.cpp | 2 +- src/cert/cvc/cvc_self.cpp | 2 +- src/cert/x509/crl_ent.cpp | 2 +- src/cert/x509/x509_ca.cpp | 2 +- src/cert/x509/x509opt.cpp | 2 +- src/cert/x509/x509stor.cpp | 2 +- src/rng/auto_rng/info.txt | 1 - src/timer/cpu_counter/info.txt | 36 --------------- src/timer/cpu_counter/tm_hard.cpp | 51 --------------------- src/timer/cpu_counter/tm_hard.h | 33 -------------- src/timer/gettimeofday/info.txt | 33 -------------- src/timer/gettimeofday/tm_unix.cpp | 23 ---------- src/timer/gettimeofday/tm_unix.h | 27 ----------- src/timer/info.txt | 14 ------ src/timer/posix_rt/info.txt | 29 ------------ src/timer/posix_rt/tm_posix.cpp | 32 -------------- src/timer/posix_rt/tm_posix.h | 27 ----------- src/timer/timer.cpp | 64 --------------------------- src/timer/timer.h | 53 ---------------------- src/timer/win32_query_perf_ctr/info.txt | 26 ----------- src/timer/win32_query_perf_ctr/tm_win32.cpp | 23 ---------- src/timer/win32_query_perf_ctr/tm_win32.h | 27 ----------- src/utils/time.h | 39 ++++++++++++++++ 40 files changed, 545 insertions(+), 507 deletions(-) create mode 100644 Attic/timer/cpu_counter/info.txt create mode 100644 Attic/timer/cpu_counter/tm_hard.cpp create mode 100644 Attic/timer/cpu_counter/tm_hard.h create mode 100644 Attic/timer/gettimeofday/info.txt create mode 100644 Attic/timer/gettimeofday/tm_unix.cpp create mode 100644 Attic/timer/gettimeofday/tm_unix.h create mode 100644 Attic/timer/info.txt create mode 100644 Attic/timer/posix_rt/info.txt create mode 100644 Attic/timer/posix_rt/tm_posix.cpp create mode 100644 Attic/timer/posix_rt/tm_posix.h create mode 100644 Attic/timer/timer.cpp create mode 100644 Attic/timer/timer.h create mode 100644 Attic/timer/win32_query_perf_ctr/info.txt create mode 100644 Attic/timer/win32_query_perf_ctr/tm_win32.cpp create mode 100644 Attic/timer/win32_query_perf_ctr/tm_win32.h delete mode 100644 src/timer/cpu_counter/info.txt delete mode 100644 src/timer/cpu_counter/tm_hard.cpp delete mode 100644 src/timer/cpu_counter/tm_hard.h delete mode 100644 src/timer/gettimeofday/info.txt delete mode 100644 src/timer/gettimeofday/tm_unix.cpp delete mode 100644 src/timer/gettimeofday/tm_unix.h delete mode 100644 src/timer/info.txt delete mode 100644 src/timer/posix_rt/info.txt delete mode 100644 src/timer/posix_rt/tm_posix.cpp delete mode 100644 src/timer/posix_rt/tm_posix.h delete mode 100644 src/timer/timer.cpp delete mode 100644 src/timer/timer.h delete mode 100644 src/timer/win32_query_perf_ctr/info.txt delete mode 100644 src/timer/win32_query_perf_ctr/tm_win32.cpp delete mode 100644 src/timer/win32_query_perf_ctr/tm_win32.h create mode 100644 src/utils/time.h (limited to 'src') diff --git a/Attic/timer/cpu_counter/info.txt b/Attic/timer/cpu_counter/info.txt new file mode 100644 index 000000000..025663a84 --- /dev/null +++ b/Attic/timer/cpu_counter/info.txt @@ -0,0 +1,36 @@ +realname "Hardware Timer" + +define TIMER_HARDWARE + +load_on asm_ok + + +tm_hard.cpp +tm_hard.h + + + +gcc + + + +# 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 + + + +timer + 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 + +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(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(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 + +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..a58e8088d --- /dev/null +++ b/Attic/timer/gettimeofday/info.txt @@ -0,0 +1,33 @@ +realname "Unix Timer" + +define TIMER_UNIX + +load_on auto +modset unix,beos + + +tm_unix.cpp +tm_unix.h + + + +aix +beos +cygwin +darwin +freebsd +dragonfly +hpux +irix +linux +netbsd +openbsd +qnx +solaris +tru64 + + + +timer + + 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 +#include + +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 + +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..6408dca45 --- /dev/null +++ b/Attic/timer/info.txt @@ -0,0 +1,14 @@ +realname "Timer Base Class" + +define TIMER + +load_on auto + + +timer.cpp +timer.h + + + +rng + diff --git a/Attic/timer/posix_rt/info.txt b/Attic/timer/posix_rt/info.txt new file mode 100644 index 000000000..fa530ea1a --- /dev/null +++ b/Attic/timer/posix_rt/info.txt @@ -0,0 +1,29 @@ +realname "POSIX Timer" + +define TIMER_POSIX + +load_on auto + + +tm_posix.cpp +tm_posix.h + + + +linux -> rt + + +# The *BSDs put clock_gettime in sys/time.h, not time.h like POSIX says + +cygwin +linux +#freebsd +dragonfly +#netbsd +#openbsd + + + +timer + + 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 + +#ifndef _POSIX_C_SOURCE + #define _POSIX_C_SOURCE 199309 +#endif + +#include + +#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 + +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 +#include +#include + +namespace Botan { + +/** +* Get the system clock +*/ +u64bit system_time() + { + return static_cast(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(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 +#include + +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..4bb1ddb34 --- /dev/null +++ b/Attic/timer/win32_query_perf_ctr/info.txt @@ -0,0 +1,26 @@ +realname "Win32 Timer" + +define TIMER_WIN32 +modset win32 + +load_on auto + + +tm_win32.cpp +tm_win32.h + + + +cygwin +windows +mingw + + + +windows -> user32.lib + + + +timer + + 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 +#include + +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 + +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/checks/cvc_tests.cpp b/checks/cvc_tests.cpp index 369da4a8c..4b2ffa9a6 100644 --- a/checks/cvc_tests.cpp +++ b/checks/cvc_tests.cpp @@ -27,8 +27,8 @@ #include #include #include -#include #include +#include #define TEST_DATA_DIR "checks/ecc_testdata" diff --git a/src/asn1/asn1_tm.cpp b/src/asn1/asn1_tm.cpp index 09bc4d347..c57d1bc73 100644 --- a/src/asn1/asn1_tm.cpp +++ b/src/asn1/asn1_tm.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include namespace Botan { diff --git a/src/cert/cvc/asn1_eac_tm.cpp b/src/cert/cvc/asn1_eac_tm.cpp index 947b9e66d..f361e6098 100644 --- a/src/cert/cvc/asn1_eac_tm.cpp +++ b/src/cert/cvc/asn1_eac_tm.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include namespace Botan { diff --git a/src/cert/cvc/cvc_self.cpp b/src/cert/cvc/cvc_self.cpp index 46bf145fc..98d90d0af 100644 --- a/src/cert/cvc/cvc_self.cpp +++ b/src/cert/cvc/cvc_self.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include namespace Botan { diff --git a/src/cert/x509/crl_ent.cpp b/src/cert/x509/crl_ent.cpp index a8a989c24..42a742ebb 100644 --- a/src/cert/x509/crl_ent.cpp +++ b/src/cert/x509/crl_ent.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include namespace Botan { diff --git a/src/cert/x509/x509_ca.cpp b/src/cert/x509/x509_ca.cpp index c3ab2a739..4c4748065 100644 --- a/src/cert/x509/x509_ca.cpp +++ b/src/cert/x509/x509_ca.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/cert/x509/x509opt.cpp b/src/cert/x509/x509opt.cpp index 03bcd20f4..c6421d9ca 100644 --- a/src/cert/x509/x509opt.cpp +++ b/src/cert/x509/x509opt.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include namespace Botan { diff --git a/src/cert/x509/x509stor.cpp b/src/cert/x509/x509stor.cpp index 9c6dced25..515215a21 100644 --- a/src/cert/x509/x509stor.cpp +++ b/src/cert/x509/x509stor.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/rng/auto_rng/info.txt b/src/rng/auto_rng/info.txt index 7d5d5ddcc..3c83bfb5e 100644 --- a/src/rng/auto_rng/info.txt +++ b/src/rng/auto_rng/info.txt @@ -12,5 +12,4 @@ auto_rng.cpp hmac sha2 -timer diff --git a/src/timer/cpu_counter/info.txt b/src/timer/cpu_counter/info.txt deleted file mode 100644 index 025663a84..000000000 --- a/src/timer/cpu_counter/info.txt +++ /dev/null @@ -1,36 +0,0 @@ -realname "Hardware Timer" - -define TIMER_HARDWARE - -load_on asm_ok - - -tm_hard.cpp -tm_hard.h - - - -gcc - - - -# 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 - - - -timer - diff --git a/src/timer/cpu_counter/tm_hard.cpp b/src/timer/cpu_counter/tm_hard.cpp deleted file mode 100644 index 9e31aee39..000000000 --- a/src/timer/cpu_counter/tm_hard.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* -* Hardware Timer -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include - -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(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(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/timer/cpu_counter/tm_hard.h b/src/timer/cpu_counter/tm_hard.h deleted file mode 100644 index 2e338eca8..000000000 --- a/src/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 - -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/src/timer/gettimeofday/info.txt b/src/timer/gettimeofday/info.txt deleted file mode 100644 index a58e8088d..000000000 --- a/src/timer/gettimeofday/info.txt +++ /dev/null @@ -1,33 +0,0 @@ -realname "Unix Timer" - -define TIMER_UNIX - -load_on auto -modset unix,beos - - -tm_unix.cpp -tm_unix.h - - - -aix -beos -cygwin -darwin -freebsd -dragonfly -hpux -irix -linux -netbsd -openbsd -qnx -solaris -tru64 - - - -timer - - diff --git a/src/timer/gettimeofday/tm_unix.cpp b/src/timer/gettimeofday/tm_unix.cpp deleted file mode 100644 index 9d8ac4a04..000000000 --- a/src/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 -#include - -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/timer/gettimeofday/tm_unix.h b/src/timer/gettimeofday/tm_unix.h deleted file mode 100644 index c304dbb5c..000000000 --- a/src/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 - -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/src/timer/info.txt b/src/timer/info.txt deleted file mode 100644 index 6408dca45..000000000 --- a/src/timer/info.txt +++ /dev/null @@ -1,14 +0,0 @@ -realname "Timer Base Class" - -define TIMER - -load_on auto - - -timer.cpp -timer.h - - - -rng - diff --git a/src/timer/posix_rt/info.txt b/src/timer/posix_rt/info.txt deleted file mode 100644 index fa530ea1a..000000000 --- a/src/timer/posix_rt/info.txt +++ /dev/null @@ -1,29 +0,0 @@ -realname "POSIX Timer" - -define TIMER_POSIX - -load_on auto - - -tm_posix.cpp -tm_posix.h - - - -linux -> rt - - -# The *BSDs put clock_gettime in sys/time.h, not time.h like POSIX says - -cygwin -linux -#freebsd -dragonfly -#netbsd -#openbsd - - - -timer - - diff --git a/src/timer/posix_rt/tm_posix.cpp b/src/timer/posix_rt/tm_posix.cpp deleted file mode 100644 index 96182025c..000000000 --- a/src/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 - -#ifndef _POSIX_C_SOURCE - #define _POSIX_C_SOURCE 199309 -#endif - -#include - -#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/timer/posix_rt/tm_posix.h b/src/timer/posix_rt/tm_posix.h deleted file mode 100644 index 8bedccfa2..000000000 --- a/src/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 - -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/src/timer/timer.cpp b/src/timer/timer.cpp deleted file mode 100644 index 16d7dc368..000000000 --- a/src/timer/timer.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/** -* Timestamp Functions -* (C) 1999-2009 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include -#include -#include - -namespace Botan { - -/** -* Get the system clock -*/ -u64bit system_time() - { - return static_cast(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(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/src/timer/timer.h b/src/timer/timer.h deleted file mode 100644 index 603027f6d..000000000 --- a/src/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 -#include - -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/src/timer/win32_query_perf_ctr/info.txt b/src/timer/win32_query_perf_ctr/info.txt deleted file mode 100644 index 4bb1ddb34..000000000 --- a/src/timer/win32_query_perf_ctr/info.txt +++ /dev/null @@ -1,26 +0,0 @@ -realname "Win32 Timer" - -define TIMER_WIN32 -modset win32 - -load_on auto - - -tm_win32.cpp -tm_win32.h - - - -cygwin -windows -mingw - - - -windows -> user32.lib - - - -timer - - diff --git a/src/timer/win32_query_perf_ctr/tm_win32.cpp b/src/timer/win32_query_perf_ctr/tm_win32.cpp deleted file mode 100644 index 6b878e6e2..000000000 --- a/src/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 -#include - -namespace Botan { - -/* -* Get the timestamp -*/ -u64bit Win32_Timer::clock() const - { - LARGE_INTEGER tv; - ::QueryPerformanceCounter(&tv); - return tv.QuadPart; - } - -} diff --git a/src/timer/win32_query_perf_ctr/tm_win32.h b/src/timer/win32_query_perf_ctr/tm_win32.h deleted file mode 100644 index 5bcb720ab..000000000 --- a/src/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 - -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/src/utils/time.h b/src/utils/time.h new file mode 100644 index 000000000..3052aec44 --- /dev/null +++ b/src/utils/time.h @@ -0,0 +1,39 @@ +/* +* Time Functions +* (C) 2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_TIME_OPS_H__ +#define BOTAN_TIME_OPS_H__ + +#include + +namespace Botan { + +/* +* Convert a time_t value to a struct tm +*/ +inline std::tm time_t_to_tm(u64bit time_int) + { + std::time_t time_val = static_cast(time_int); + + 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); + } + +/** +* Get the system clock +*/ +inline u64bit system_time() + { + return static_cast(std::time(0)); + } + +} + + +#endif -- cgit v1.2.3 From d9dd962ed735285a259c7f44e704932f3ddb74b4 Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 13 Nov 2009 23:34:24 +0000 Subject: Post-merge fix --- src/cert/x509/x509self.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/cert/x509/x509self.cpp b/src/cert/x509/x509self.cpp index 8db2f37a6..df31897bb 100644 --- a/src/cert/x509/x509self.cpp +++ b/src/cert/x509/x509self.cpp @@ -73,7 +73,7 @@ X509_Certificate create_self_signed_cert(const X509_Cert_Options& opts, AlternativeName subject_alt; MemoryVector pub_key = shared_setup(opts, key); - std::unique_ptr signer(choose_sig_format(key, sig_algo)); + std::unique_ptr signer(choose_sig_format(key, hash_fn, sig_algo)); load_info(opts, subject_dn, subject_alt); Key_Constraints constraints; -- cgit v1.2.3 From 9ea67516fc88984c865582622de3bea0cd5cbc8b Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 13 Nov 2009 23:35:05 +0000 Subject: Make `struct mapping tests[]` non-static in miller_rabin_test_iterations to work around gcc bug 42010 --- src/math/numbertheory/numthry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/math/numbertheory/numthry.cpp b/src/math/numbertheory/numthry.cpp index 448681333..5e36288ff 100644 --- a/src/math/numbertheory/numthry.cpp +++ b/src/math/numbertheory/numthry.cpp @@ -20,7 +20,7 @@ u32bit miller_rabin_test_iterations(u32bit bits, bool verify) { struct mapping { u32bit bits; u32bit verify_iter; u32bit check_iter; }; - static const mapping tests[] = { + const mapping tests[] = { { 50, 55, 25 }, { 100, 38, 22 }, { 160, 32, 18 }, -- cgit v1.2.3 From 75ce98125baa42cb8f5a64c1329f946061a28c9b Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 13 Nov 2009 23:35:16 +0000 Subject: Use GCC 4.5 snapshot for C++0x build --- src/build-data/cc/gcc.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/build-data/cc/gcc.txt b/src/build-data/cc/gcc.txt index c4b5b9fbc..82c1a983d 100644 --- a/src/build-data/cc/gcc.txt +++ b/src/build-data/cc/gcc.txt @@ -1,6 +1,6 @@ macro_name "GCC" -binary_name "g++-4.4.1" +binary_name "g++-4.5-20091112" compiler_has_tr1 yes -- cgit v1.2.3 From 5ef971f34aced376e385a7ac301e0db96fbef0d4 Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 13 Nov 2009 23:38:01 +0000 Subject: Remove TR1 hooks - can be assumed to exist under a C++0x compiler --- configure.py | 44 ++++++-------------------------------------- src/build-data/cc/gcc.txt | 2 -- src/build-data/cc/icc.txt | 2 -- src/cert/cvc/info.txt | 2 -- src/math/gfpmath/info.txt | 4 +--- 5 files changed, 7 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/configure.py b/configure.py index 5e2e4004d..d48396c8a 100755 --- a/configure.py +++ b/configure.py @@ -174,10 +174,6 @@ def process_command_line(args): default=False, action='store_true', help='enable Boost.Python wrapper') - build_group.add_option('--with-tr1-implementation', metavar='WHICH', - dest='with_tr1', default=None, - help='enable TR1 (options: none, system, boost)') - build_group.add_option('--with-build-dir', metavar='DIR', default='', help='setup the build in DIR') @@ -368,7 +364,6 @@ class ModuleInfo(object): { 'load_on': 'auto', 'define': None, 'modset': None, - 'uses_tr1': 'false', 'need_isa': None, 'note': '', 'mp_bits': 0 }) @@ -399,11 +394,6 @@ class ModuleInfo(object): self.mp_bits = int(self.mp_bits) - if self.uses_tr1 == 'yes': - self.uses_tr1 = True - else: - self.uses_tr1 = False - def compatible_cpu(self, archinfo, options): arch_name = archinfo.basename @@ -423,9 +413,7 @@ class ModuleInfo(object): def compatible_os(self, os): return self.os == [] or os in self.os - def compatible_compiler(self, cc, with_tr1): - if self.uses_tr1 and with_tr1 not in ['boost', 'system']: - return False + def compatible_compiler(self, cc): return self.cc == [] or cc in self.cc def dependencies(self): @@ -538,8 +526,7 @@ class CompilerInfo(object): 'dll_import_flags': '', 'dll_export_flags': '', 'ar_command': None, - 'makefile_style': '', - 'compiler_has_tr1': False, + 'makefile_style': '' }) self.so_link_flags = force_to_dict(self.so_link_flags) @@ -617,19 +604,8 @@ class CompilerInfo(object): """ Return defines for build.h """ - def defines(self, with_tr1): - - def tr1_macro(): - if with_tr1: - if with_tr1 == 'boost': - return ['USE_BOOST_TR1'] - elif with_tr1 == 'system': - return ['USE_STD_TR1'] - elif self.compiler_has_tr1: - return ['USE_STD_TR1'] - return [] - - return ['BUILD_COMPILER_IS_' + self.macro_name] + tr1_macro() + def defines(self): + return ['BUILD_COMPILER_IS_' + self.macro_name] class OsInfo(object): def __init__(self, infofile): @@ -843,8 +819,7 @@ def create_template_vars(build_config, options, modules, cc, arch, osinfo): 'target_os_defines': make_cpp_macros(osinfo.defines()), - 'target_compiler_defines': make_cpp_macros( - cc.defines(options.with_tr1)), + 'target_compiler_defines': make_cpp_macros(cc.defines()), 'target_cpu_defines': make_cpp_macros(arch.defines(options)), @@ -920,8 +895,7 @@ def choose_modules_to_use(modules, archinfo, options): cannot_use_because(modname, 'CPU incompatible') elif not module.compatible_os(options.os): cannot_use_because(modname, 'OS incompatible') - elif not module.compatible_compiler(options.compiler, - options.with_tr1): + elif not module.compatible_compiler(options.compiler): cannot_use_because(modname, 'compiler incompatible') else: @@ -1220,12 +1194,6 @@ def main(argv = None): logging.info('Setting -fpermissive to work around gcc bug') options.extra_flags = ' -fpermissive' - if options.with_tr1 == None: - if ccinfo[options.compiler].compiler_has_tr1: - options.with_tr1 = 'system' - else: - options.with_tr1 = 'none' - modules_to_use = choose_modules_to_use(modules, archinfo[options.arch], options) diff --git a/src/build-data/cc/gcc.txt b/src/build-data/cc/gcc.txt index 82c1a983d..d1b76edec 100644 --- a/src/build-data/cc/gcc.txt +++ b/src/build-data/cc/gcc.txt @@ -2,8 +2,6 @@ macro_name "GCC" binary_name "g++-4.5-20091112" -compiler_has_tr1 yes - compile_option "-c " output_to_option "-o " add_include_dir_option "-I" diff --git a/src/build-data/cc/icc.txt b/src/build-data/cc/icc.txt index b5cad542c..7187cae56 100644 --- a/src/build-data/cc/icc.txt +++ b/src/build-data/cc/icc.txt @@ -2,8 +2,6 @@ macro_name "INTEL" binary_name "icpc" -compiler_has_tr1 yes - compile_option "-c " output_to_option "-o " add_include_dir_option "-I" diff --git a/src/cert/cvc/info.txt b/src/cert/cvc/info.txt index bdd496614..ff7e04c07 100644 --- a/src/cert/cvc/info.txt +++ b/src/cert/cvc/info.txt @@ -1,7 +1,5 @@ define CARD_VERIFIABLE_CERTIFICATES -uses_tr1 yes - load_on auto diff --git a/src/math/gfpmath/info.txt b/src/math/gfpmath/info.txt index abbdb0a47..e1bf892c7 100644 --- a/src/math/gfpmath/info.txt +++ b/src/math/gfpmath/info.txt @@ -1,9 +1,7 @@ -uses_tr1 yes +define BIGINT_GFP load_on auto -define BIGINT_GFP - curve_gfp.cpp curve_gfp.h -- cgit v1.2.3 From fc5fadb281c509855a0ae20ecc70bfe9d681a1af Mon Sep 17 00:00:00 2001 From: lloyd Date: Mon, 16 Nov 2009 16:25:44 +0000 Subject: Replace X509_Store::Search_Func with std::function and lambdas --- src/cert/x509/x509find.cpp | 95 ++++++++++++++++++++++------------------------ src/cert/x509/x509find.h | 58 ++++++++++++---------------- src/cert/x509/x509stor.cpp | 4 +- src/cert/x509/x509stor.h | 16 ++++---- src/cms/cms_dalg.cpp | 5 ++- 5 files changed, 84 insertions(+), 94 deletions(-) (limited to 'src') diff --git a/src/cert/x509/x509find.cpp b/src/cert/x509/x509find.cpp index 257367da9..41643a94a 100644 --- a/src/cert/x509/x509find.cpp +++ b/src/cert/x509/x509find.cpp @@ -11,6 +11,8 @@ namespace Botan { +namespace X509_Store_Search { + namespace { /* @@ -42,70 +44,65 @@ bool ignore_case(const std::string& searching_for, const std::string& found) /* * Search based on the contents of a DN entry */ -bool DN_Check::match(const X509_Certificate& cert) const +std::function +by_dn(const std::string& dn_entry, + const std::string& to_find, + DN_Search_Type method) { - std::vector info = cert.subject_info(dn_entry); - - for(u32bit j = 0; j != info.size(); ++j) - if(compare(info[j], looking_for)) - return true; - return false; - } + if(method == SUBSTRING_MATCHING) + return by_dn(dn_entry, to_find, substring_match); + else if(method == IGNORE_CASE) + return by_dn(dn_entry, to_find, ignore_case); -/* -* DN_Check Constructor -*/ -DN_Check::DN_Check(const std::string& dn_entry, const std::string& looking_for, - compare_fn func) - { - this->dn_entry = dn_entry; - this->looking_for = looking_for; - compare = func; + throw Invalid_Argument("Unknown method argument to by_dn"); } -/* -* DN_Check Constructor -*/ -DN_Check::DN_Check(const std::string& dn_entry, const std::string& looking_for, - Search_Type method) +std::function +by_dn(const std::string& dn_entry, + const std::string& to_find, + std::function compare) { - this->dn_entry = dn_entry; - this->looking_for = looking_for; + return [&](const X509_Certificate& cert) + { + std::vector info = cert.subject_info(dn_entry); - if(method == SUBSTRING_MATCHING) - compare = &substring_match; - else if(method == IGNORE_CASE) - compare = &ignore_case; - else - throw Invalid_Argument("Unknown method argument to DN_Check()"); + for(u32bit i = 0; i != info.size(); ++i) + if(compare(info[i], to_find)) + return true; + return false; + }; } -/* -* Match by issuer and serial number -*/ -bool IandS_Match::match(const X509_Certificate& cert) const +std::function +by_issuer_and_serial(const X509_DN& issuer, const MemoryRegion& serial) { - if(cert.serial_number() != serial) - return false; - return (cert.issuer_dn() == issuer); + /* Serial number compare is much faster than X.509 DN, and unlikely + to collide even across issuers, so do that first to fail fast + */ + + return [&](const X509_Certificate& cert) + { + if(cert.serial_number() != serial) + return false; + return (cert.issuer_dn() == issuer); + }; } -/* -* IandS_Match Constructor -*/ -IandS_Match::IandS_Match(const X509_DN& issuer, - const MemoryRegion& serial) +std::function +by_issuer_and_serial(const X509_DN& issuer, const BigInt& serial) { - this->issuer = issuer; - this->serial = serial; + return by_issuer_and_serial(issuer, BigInt::encode(serial)); } -/* -* Match by subject key identifier -*/ -bool SKID_Match::match(const X509_Certificate& cert) const +std::function +by_skid(const MemoryRegion& subject_key_id) { - return (cert.subject_key_id() == skid); + return [&](const X509_Certificate& cert) + { + return (cert.subject_key_id() == subject_key_id); + }; } } + +} diff --git a/src/cert/x509/x509find.h b/src/cert/x509/x509find.h index a7a84c7a5..1bf29dfbc 100644 --- a/src/cert/x509/x509find.h +++ b/src/cert/x509/x509find.h @@ -9,51 +9,43 @@ #define BOTAN_X509_CERT_STORE_SEARCH_H__ #include +#include namespace Botan { +namespace X509_Store_Search { + /* * Search based on the contents of a DN entry */ -class BOTAN_DLL DN_Check : public X509_Store::Search_Func - { - public: - typedef bool (*compare_fn)(const std::string&, const std::string&); - enum Search_Type { SUBSTRING_MATCHING, IGNORE_CASE }; +enum DN_Search_Type { SUBSTRING_MATCHING, IGNORE_CASE }; - bool match(const X509_Certificate& cert) const; +std::function +by_dn(const std::string& dn_entry, + const std::string& to_find, + DN_Search_Type method); - DN_Check(const std::string&, const std::string&, compare_fn); - DN_Check(const std::string&, const std::string&, Search_Type); - private: - std::string dn_entry, looking_for; - compare_fn compare; - }; +std::function +by_dn(const std::string& dn_entry, + const std::string& to_find, + std::function method); -/* -* Search for a certificate by issuer/serial +/** +* Search for certs by issuer + serial number */ -class BOTAN_DLL IandS_Match : public X509_Store::Search_Func - { - public: - bool match(const X509_Certificate& cert) const; - IandS_Match(const X509_DN&, const MemoryRegion&); - private: - X509_DN issuer; - MemoryVector serial; - }; +std::function +by_issuer_and_serial(const X509_DN& issuer, const MemoryRegion& serial); -/* -* Search for a certificate by subject keyid +std::function +by_issuer_and_serial(const X509_DN& issuer, const BigInt& serial); + +/** +* Search for certs by subject key identifier */ -class BOTAN_DLL SKID_Match : public X509_Store::Search_Func - { - public: - bool match(const X509_Certificate& cert) const; - SKID_Match(const MemoryRegion& s) : skid(s) {} - private: - MemoryVector skid; - }; +std::function +by_skid(const MemoryRegion& subject_key_id); + +} } diff --git a/src/cert/x509/x509stor.cpp b/src/cert/x509/x509stor.cpp index 515215a21..364bbac7b 100644 --- a/src/cert/x509/x509stor.cpp +++ b/src/cert/x509/x509stor.cpp @@ -464,12 +464,12 @@ bool X509_Store::is_revoked(const X509_Certificate& cert) const * Retrieve all the certificates in the store */ std::vector -X509_Store::get_certs(const Search_Func& search) const +X509_Store::get_certs(std::function pred) const { std::vector found_certs; for(u32bit j = 0; j != certs.size(); ++j) { - if(search.match(certs[j].cert)) + if(pred(certs[j].cert)) found_certs.push_back(certs[j].cert); } return found_certs; diff --git a/src/cert/x509/x509stor.h b/src/cert/x509/x509stor.h index 4e6037883..ab31663ed 100644 --- a/src/cert/x509/x509stor.h +++ b/src/cert/x509/x509stor.h @@ -11,6 +11,7 @@ #include #include #include +#include namespace Botan { @@ -48,13 +49,6 @@ enum X509_Code { class BOTAN_DLL X509_Store { public: - class BOTAN_DLL Search_Func - { - public: - virtual bool match(const X509_Certificate&) const = 0; - virtual ~Search_Func() {} - }; - enum Cert_Usage { ANY = 0x00, TLS_SERVER = 0x01, @@ -67,7 +61,13 @@ class BOTAN_DLL X509_Store X509_Code validate_cert(const X509_Certificate&, Cert_Usage = ANY); - std::vector get_certs(const Search_Func&) const; + /** + * @param match the matching function + * @return list of certs for which match returns true + */ + std::vector + get_certs(std::function match) const; + std::vector get_cert_chain(const X509_Certificate&); std::string PEM_encode() const; diff --git a/src/cms/cms_dalg.cpp b/src/cms/cms_dalg.cpp index 7ed793f4f..3e8bdb4fa 100644 --- a/src/cms/cms_dalg.cpp +++ b/src/cms/cms_dalg.cpp @@ -52,10 +52,11 @@ std::vector get_cert(BER_Decoder& signer_info, iands.decode(issuer); iands.decode(serial); - found = store.get_certs(IandS_Match(issuer, BigInt::encode(serial))); + found = store.get_certs( + X509_Store_Search::by_issuer_and_serial(issuer, serial)); } else if(id.type_tag == 0 && id.class_tag == CONSTRUCTED) - found = store.get_certs(SKID_Match(id.value)); + found = store.get_certs(X509_Store_Search::by_skid(id.value)); else throw Decoding_Error("CMS: Unknown tag for cert identifier"); -- cgit v1.2.3 From 22a47e97f459337ff8c2b9fdcf68cb1514b19b34 Mon Sep 17 00:00:00 2001 From: lloyd Date: Mon, 16 Nov 2009 17:07:38 +0000 Subject: Use auto for long iterator names, etc. It will be nice to convert to the range-based for loop once that's available. --- src/algo_factory/algo_cache.h | 30 ++++++++++++------------------ src/algo_factory/algo_factory.cpp | 3 ++- src/alloc/mem_pool/mem_pool.cpp | 6 +++--- src/asn1/asn1_alt.cpp | 27 +++++++++++---------------- src/cert/x509/x509_ca.cpp | 6 +----- src/cert/x509/x509cert.cpp | 16 +++++----------- src/cert/x509/x509stor.cpp | 3 +-- src/libstate/libstate.cpp | 3 +-- src/rng/hmac_rng/hmac_rng.cpp | 5 ++--- src/rng/randpool/randpool.cpp | 5 ++--- src/selftest/selftest.cpp | 3 +-- src/utils/datastor/datastor.cpp | 7 ++----- src/utils/stl_util.h | 19 ------------------- 13 files changed, 43 insertions(+), 90 deletions(-) (limited to 'src') diff --git a/src/algo_factory/algo_cache.h b/src/algo_factory/algo_cache.h index 4b264dcc1..09bbc4b5a 100644 --- a/src/algo_factory/algo_cache.h +++ b/src/algo_factory/algo_cache.h @@ -53,12 +53,8 @@ class Algorithm_Cache ~Algorithm_Cache(); private: - typedef typename std::map >::iterator - algorithms_iterator; - - typedef typename std::map::iterator provider_iterator; - - algorithms_iterator find_algorithm(const std::string& algo_spec); + typename std::map >::const_iterator + find_algorithm(const std::string& algo_spec); std::mutex mutex; std::map aliases; @@ -71,16 +67,15 @@ class Algorithm_Cache * Assumes object lock is held */ template -typename Algorithm_Cache::algorithms_iterator +typename std::map >::const_iterator Algorithm_Cache::find_algorithm(const std::string& algo_spec) { - algorithms_iterator algo = algorithms.find(algo_spec); + auto algo = algorithms.find(algo_spec); // Not found? Check if a known alias if(algo == algorithms.end()) { - std::map::const_iterator alias = - aliases.find(algo_spec); + auto alias = aliases.find(algo_spec); if(alias != aliases.end()) algo = algorithms.find(alias->second); @@ -98,14 +93,14 @@ const T* Algorithm_Cache::get(const std::string& algo_spec, { std::lock_guard lock(mutex); - algorithms_iterator algo = find_algorithm(algo_spec); + auto algo = find_algorithm(algo_spec); if(algo == algorithms.end()) // algo not found at all (no providers) return 0; // If a provider is requested specifically, return it or fail entirely if(requested_provider != "") { - provider_iterator prov = algo->second.find(requested_provider); + auto prov = algo->second.find(requested_provider); if(prov != algo->second.end()) return prov->second; return 0; @@ -117,7 +112,7 @@ const T* Algorithm_Cache::get(const std::string& algo_spec, const std::string pref_provider = search_map(pref_providers, algo_spec); - for(provider_iterator i = algo->second.begin(); i != algo->second.end(); ++i) + for(auto i = algo->second.begin(); i != algo->second.end(); ++i) { const std::string prov_name = i->first; const u32bit prov_weight = static_provider_weight(prov_name); @@ -170,11 +165,10 @@ Algorithm_Cache::providers_of(const std::string& algo_name) std::vector providers; - algorithms_iterator algo = find_algorithm(algo_name); - + auto algo = find_algorithm(algo_name); if(algo != algorithms.end()) { - provider_iterator provider = algo->second.begin(); + auto provider = algo->second.begin(); while(provider != algo->second.end()) { @@ -204,11 +198,11 @@ void Algorithm_Cache::set_preferred_provider(const std::string& algo_spec, template Algorithm_Cache::~Algorithm_Cache() { - algorithms_iterator algo = algorithms.begin(); + auto algo = algorithms.begin(); while(algo != algorithms.end()) { - provider_iterator provider = algo->second.begin(); + auto provider = algo->second.begin(); while(provider != algo->second.end()) { diff --git a/src/algo_factory/algo_factory.cpp b/src/algo_factory/algo_factory.cpp index 192d5ecdd..0b8422bcb 100644 --- a/src/algo_factory/algo_factory.cpp +++ b/src/algo_factory/algo_factory.cpp @@ -99,7 +99,8 @@ Algorithm_Factory::Algorithm_Factory(const std::vector& engines_in) */ Algorithm_Factory::~Algorithm_Factory() { - std::for_each(engines.begin(), engines.end(), del_fun()); + for(auto i = engines.begin(); i != engines.end(); ++i) + delete *i; delete block_cipher_cache; delete stream_cipher_cache; diff --git a/src/alloc/mem_pool/mem_pool.cpp b/src/alloc/mem_pool/mem_pool.cpp index 02a12d6a5..820355678 100644 --- a/src/alloc/mem_pool/mem_pool.cpp +++ b/src/alloc/mem_pool/mem_pool.cpp @@ -190,8 +190,8 @@ void Pooling_Allocator::deallocate(void* ptr, u32bit n) { const u32bit block_no = round_up(n, BLOCK_SIZE) / BLOCK_SIZE; - std::vector::iterator i = - std::lower_bound(blocks.begin(), blocks.end(), Memory_Block(ptr)); + auto i = std::lower_bound(blocks.begin(), blocks.end(), + Memory_Block(ptr)); if(i == blocks.end() || !i->contains(ptr, block_no)) throw Invalid_State("Pointer released to the wrong allocator"); @@ -208,7 +208,7 @@ byte* Pooling_Allocator::allocate_blocks(u32bit n) if(blocks.empty()) return 0; - std::vector::iterator i = last_used; + auto i = last_used; do { diff --git a/src/asn1/asn1_alt.cpp b/src/asn1/asn1_alt.cpp index 41974eef6..401eb54e9 100644 --- a/src/asn1/asn1_alt.cpp +++ b/src/asn1/asn1_alt.cpp @@ -40,9 +40,8 @@ void AlternativeName::add_attribute(const std::string& type, if(type == "" || str == "") return; - typedef std::multimap::iterator iter; - std::pair range = alt_info.equal_range(type); - for(iter j = range.first; j != range.second; ++j) + auto range = alt_info.equal_range(type); + for(auto j = range.first; j != range.second; ++j) if(j->second == str) return; @@ -83,13 +82,11 @@ std::multimap AlternativeName::contents() const { std::multimap names; - typedef std::multimap::const_iterator rdn_iter; - for(rdn_iter j = alt_info.begin(); j != alt_info.end(); ++j) - multimap_insert(names, j->first, j->second); + for(auto i = alt_info.begin(); i != alt_info.end(); ++i) + multimap_insert(names, i->first, i->second); - typedef std::multimap::const_iterator on_iter; - for(on_iter j = othernames.begin(); j != othernames.end(); ++j) - multimap_insert(names, OIDS::lookup(j->first), j->second.value()); + for(auto i = othernames.begin(); i != othernames.end(); ++i) + multimap_insert(names, OIDS::lookup(i->first), i->second.value()); return names; } @@ -111,19 +108,18 @@ void encode_entries(DER_Encoder& encoder, const std::multimap& attr, const std::string& type, ASN1_Tag tagging) { - typedef std::multimap::const_iterator iter; + auto range = attr.equal_range(type); - std::pair range = attr.equal_range(type); - for(iter j = range.first; j != range.second; ++j) + for(auto i = range.first; i != range.second; ++i) { if(type == "RFC822" || type == "DNS" || type == "URI") { - ASN1_String asn1_string(j->second, IA5_STRING); + ASN1_String asn1_string(i->second, IA5_STRING); encoder.add_object(tagging, CONTEXT_SPECIFIC, asn1_string.iso_8859()); } else if(type == "IP") { - u32bit ip = string_to_ipv4(j->second); + u32bit ip = string_to_ipv4(i->second); byte ip_buf[4] = { 0 }; store_be(ip, ip_buf); encoder.add_object(tagging, CONTEXT_SPECIFIC, ip_buf, 4); @@ -145,8 +141,7 @@ void AlternativeName::encode_into(DER_Encoder& der) const encode_entries(der, alt_info, "URI", ASN1_Tag(6)); encode_entries(der, alt_info, "IP", ASN1_Tag(7)); - std::multimap::const_iterator i; - for(i = othernames.begin(); i != othernames.end(); ++i) + for(auto i = othernames.begin(); i != othernames.end(); ++i) { der.start_explicit(0) .encode(i->first) diff --git a/src/cert/x509/x509_ca.cpp b/src/cert/x509/x509_ca.cpp index 3ba18e50e..6aba7e5a0 100644 --- a/src/cert/x509/x509_ca.cpp +++ b/src/cert/x509/x509_ca.cpp @@ -15,9 +15,6 @@ #include #include #include -#include -#include -#include #include #include @@ -175,8 +172,7 @@ X509_CRL X509_CA::update_crl(const X509_CRL& crl, for(u32bit j = 0; j != already_revoked.size(); ++j) { - std::set >::const_iterator i; - i = removed_from_crl.find(already_revoked[j].serial_number()); + auto i = removed_from_crl.find(already_revoked[j].serial_number()); if(i == removed_from_crl.end()) all_revoked.push_back(already_revoked[j]); diff --git a/src/cert/x509/x509cert.cpp b/src/cert/x509/x509cert.cpp index ac5839fb6..9be645dce 100644 --- a/src/cert/x509/x509cert.cpp +++ b/src/cert/x509/x509cert.cpp @@ -27,12 +27,8 @@ std::vector lookup_oids(const std::vector& in) { std::vector out; - std::vector::const_iterator i = in.begin(); - while(i != in.end()) - { + for(auto i = in.begin(); i != in.end(); ++i) out.push_back(OIDS::lookup(OID(*i))); - ++i; - } return out; } @@ -320,9 +316,8 @@ X509_DN create_dn(const Data_Store& info) X509_DN dn; - std::multimap::iterator j; - for(j = names.begin(); j != names.end(); ++j) - dn.add_attribute(j->first, j->second); + for(auto i = names.begin(); i != names.end(); ++i) + dn.add_attribute(i->first, i->second); return dn; } @@ -356,9 +351,8 @@ AlternativeName create_alt_name(const Data_Store& info) AlternativeName alt_name; - std::multimap::iterator j; - for(j = names.begin(); j != names.end(); ++j) - alt_name.add_attribute(j->first, j->second); + for(auto i = names.begin(); i != names.end(); ++i) + alt_name.add_attribute(i->first, i->second); return alt_name; } diff --git a/src/cert/x509/x509stor.cpp b/src/cert/x509/x509stor.cpp index 364bbac7b..323890f2d 100644 --- a/src/cert/x509/x509stor.cpp +++ b/src/cert/x509/x509stor.cpp @@ -603,8 +603,7 @@ X509_Code X509_Store::add_crl(const X509_CRL& crl) revoked_info.serial = revoked_certs[j].serial_number(); revoked_info.auth_key_id = crl.authority_key_id(); - std::vector::iterator p = - std::find(revoked.begin(), revoked.end(), revoked_info); + auto p = std::find(revoked.begin(), revoked.end(), revoked_info); if(revoked_certs[j].reason_code() == REMOVE_FROM_CRL) { diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp index 80f694094..dd7fe7eaf 100644 --- a/src/libstate/libstate.cpp +++ b/src/libstate/libstate.cpp @@ -170,8 +170,7 @@ void Library_State::set(const std::string& section, const std::string& key, std::string full_key = section + "/" + key; - std::map::const_iterator i = - config.find(full_key); + auto i = config.find(full_key); if(overwrite || i == config.end() || i->second == "") config[full_key] = value; diff --git a/src/rng/hmac_rng/hmac_rng.cpp b/src/rng/hmac_rng/hmac_rng.cpp index 9d5ee97e4..213373657 100644 --- a/src/rng/hmac_rng/hmac_rng.cpp +++ b/src/rng/hmac_rng/hmac_rng.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include namespace Botan { @@ -213,8 +212,8 @@ HMAC_RNG::~HMAC_RNG() delete extractor; delete prf; - std::for_each(entropy_sources.begin(), entropy_sources.end(), - del_fun()); + for(auto i = entropy_sources.begin(); i != entropy_sources.end(); ++i) + delete *i; counter = 0; } diff --git a/src/rng/randpool/randpool.cpp b/src/rng/randpool/randpool.cpp index af1706466..b04da7358 100644 --- a/src/rng/randpool/randpool.cpp +++ b/src/rng/randpool/randpool.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include @@ -208,8 +207,8 @@ Randpool::~Randpool() delete cipher; delete mac; - std::for_each(entropy_sources.begin(), entropy_sources.end(), - del_fun()); + for(auto i = entropy_sources.begin(); i != entropy_sources.end(); ++i) + delete *i; } } diff --git a/src/selftest/selftest.cpp b/src/selftest/selftest.cpp index 660be36e4..d5b184f8f 100644 --- a/src/selftest/selftest.cpp +++ b/src/selftest/selftest.cpp @@ -114,8 +114,7 @@ namespace { void verify_results(const std::string& algo, const std::map& results) { - for(std::map::const_iterator i = results.begin(); - i != results.end(); ++i) + for(auto i = results.begin(); i != results.end(); ++i) { if(!i->second) throw Self_Test_Failure(algo + " self-test failed, provider "+ diff --git a/src/utils/datastor/datastor.cpp b/src/utils/datastor/datastor.cpp index 129dad9bf..9f8ba2c24 100644 --- a/src/utils/datastor/datastor.cpp +++ b/src/utils/datastor/datastor.cpp @@ -65,12 +65,9 @@ Data_Store::search_with(const Matcher& matcher) const */ std::vector Data_Store::get(const std::string& looking_for) const { - typedef std::multimap::const_iterator iter; - - std::pair range = contents.equal_range(looking_for); - std::vector out; - for(iter i = range.first; i != range.second; ++i) + auto range = contents.equal_range(looking_for); + for(auto i = range.first; i != range.second; ++i) out.push_back(i->second); return out; } diff --git a/src/utils/stl_util.h b/src/utils/stl_util.h index fc4d4effe..4cc081733 100644 --- a/src/utils/stl_util.h +++ b/src/utils/stl_util.h @@ -36,25 +36,6 @@ inline R search_map(const std::map& mapping, const K& key, return found_result; } -/* -* Function adaptor for delete operation -*/ -template -class del_fun : public std::unary_function - { - public: - void operator()(T* ptr) { delete ptr; } - }; - -/* -* Delete the second half of a pair of objects -*/ -template -void delete2nd(Pair& pair) - { - delete pair.second; - } - /* * Insert a key/value pair into a multimap */ -- cgit v1.2.3 From b4b6bc090035e2cd0e4354fcb17de8f6d0babb6d Mon Sep 17 00:00:00 2001 From: lloyd Date: Mon, 16 Nov 2009 17:31:00 +0000 Subject: Convert Data_Store::Matcher to using lambdas --- src/cert/x509/x509cert.cpp | 43 +++++++++++------------------------------ src/utils/datastor/datastor.cpp | 26 +++++-------------------- src/utils/datastor/datastor.h | 17 +++------------- 3 files changed, 19 insertions(+), 67 deletions(-) (limited to 'src') diff --git a/src/cert/x509/x509cert.cpp b/src/cert/x509/x509cert.cpp index 9be645dce..6a062b7ce 100644 --- a/src/cert/x509/x509cert.cpp +++ b/src/cert/x509/x509cert.cpp @@ -300,19 +300,11 @@ bool operator!=(const X509_Certificate& cert1, const X509_Certificate& cert2) */ X509_DN create_dn(const Data_Store& info) { - class DN_Matcher : public Data_Store::Matcher + auto names = info.search_for( + [](const std::string& key, const std::string&) { - public: - bool operator()(const std::string& key, const std::string&) const - { - if(key.find("X520.") != std::string::npos) - return true; - return false; - } - }; - - std::multimap names = - info.search_with(DN_Matcher()); + return (key.find("X520.") != std::string::npos); + }); X509_DN dn; @@ -327,27 +319,14 @@ X509_DN create_dn(const Data_Store& info) */ AlternativeName create_alt_name(const Data_Store& info) { - class AltName_Matcher : public Data_Store::Matcher + auto names = info.search_for( + [](const std::string& key, const std::string&) { - public: - bool operator()(const std::string& key, const std::string&) const - { - for(u32bit j = 0; j != matches.size(); ++j) - if(key.compare(matches[j]) == 0) - return true; - return false; - } - - AltName_Matcher(const std::string& match_any_of) - { - matches = split_on(match_any_of, '/'); - } - private: - std::vector matches; - }; - - std::multimap names = - info.search_with(AltName_Matcher("RFC822/DNS/URI/IP")); + return (key == "RFC822" || + key == "DNS" || + key == "URI" || + key == "IP"); + }); AlternativeName alt_name; diff --git a/src/utils/datastor/datastor.cpp b/src/utils/datastor/datastor.cpp index 9f8ba2c24..5e7c94634 100644 --- a/src/utils/datastor/datastor.cpp +++ b/src/utils/datastor/datastor.cpp @@ -13,16 +13,6 @@ namespace Botan { -/* -* Default Matcher transform operation (identity) -*/ -std::pair -Data_Store::Matcher::transform(const std::string& key, - const std::string& value) const - { - return std::make_pair(key, value); - } - /* * Data_Store Equality Comparison */ @@ -42,20 +32,14 @@ bool Data_Store::has_value(const std::string& key) const /* * Search based on an arbitrary predicate */ -std::multimap -Data_Store::search_with(const Matcher& matcher) const +std::multimap Data_Store::search_for( + std::function predicate) const { std::multimap out; - std::multimap::const_iterator i = - contents.begin(); - - while(i != contents.end()) - { - if(matcher(i->first, i->second)) - out.insert(matcher.transform(i->first, i->second)); - ++i; - } + for(auto i = contents.begin(); i != contents.end(); ++i) + if(predicate(i->first, i->second)) + out.insert(std::make_pair(i->first, i->second)); return out; } diff --git a/src/utils/datastor/datastor.h b/src/utils/datastor/datastor.h index 7ee626fda..516d0a16b 100644 --- a/src/utils/datastor/datastor.h +++ b/src/utils/datastor/datastor.h @@ -9,6 +9,7 @@ #define BOTAN_DATA_STORE_H__ #include +#include #include #include #include @@ -22,22 +23,10 @@ namespace Botan { class BOTAN_DLL Data_Store { public: - class BOTAN_DLL Matcher - { - public: - virtual bool operator()(const std::string&, - const std::string&) const = 0; - - virtual std::pair - transform(const std::string&, const std::string&) const; - - virtual ~Matcher() {} - }; - bool operator==(const Data_Store&) const; - std::multimap - search_with(const Matcher&) const; + std::multimap search_for( + std::function predicate) const; std::vector get(const std::string&) const; -- cgit v1.2.3 From 435965ac3b199d31b799ebefc012d928bc415621 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 17 Nov 2009 00:08:44 +0000 Subject: Use -pthread on all platforms. This is necessary to get functioning support for std::thread, and to ensure that std::mutex actually maps to a real mutex and not a no-op. Don't explicitly define _REENTRANT; -pthread will handle that if necessary. --- src/build-data/cc/gcc.txt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/build-data/cc/gcc.txt b/src/build-data/cc/gcc.txt index d1b76edec..0b1668908 100644 --- a/src/build-data/cc/gcc.txt +++ b/src/build-data/cc/gcc.txt @@ -8,7 +8,7 @@ add_include_dir_option "-I" add_lib_dir_option "-L" add_lib_option "-l" -lang_flags "-D_REENTRANT -ansi -Wno-long-long -std=c++0x" +lang_flags "-ansi -Wno-long-long -std=c++0x" warning_flags "-W -Wall" #warning_flags "-Wextra -Wall -Wstrict-aliasing -Wstrict-overflow=5 -Wcast-align -Wmissing-declarations -Wno-unused-parameter" @@ -70,6 +70,8 @@ ppc64 -> "-mcpu=SUBMODEL" ppc # Note that the 'linking' bit means "use this for both compiling *and* linking" +all -> "-pthread" + amd64 -> "-m64" mips64 -> "-mabi=64" s390 -> "-m31" @@ -78,10 +80,6 @@ sparc32 -> "-m32 -mno-app-regs" sparc64 -> "-m64 -mno-app-regs" ppc64 -> "-m64" -# This should probably be used on most/all targets, but the docs are incomplete -openbsd -> "-pthread" -freebsd -> "-pthread" -dragonfly -> "-pthread" -netbsd -> "-pthread -D_NETBSD_SOURCE" +netbsd -> "-D_NETBSD_SOURCE" qnx -> "-fexceptions -D_QNX_SOURCE" -- cgit v1.2.3 From 57199e2a8ec339c9cccb5c837416f91119936213 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 17 Nov 2009 15:54:50 +0000 Subject: Replace the Pipe constructor taking a Filter*[] and a length with one taking a initializer_list --- src/filters/pipe.cpp | 7 ++++--- src/filters/pipe.h | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/filters/pipe.cpp b/src/filters/pipe.cpp index 33824be24..d43868e3f 100644 --- a/src/filters/pipe.cpp +++ b/src/filters/pipe.cpp @@ -51,11 +51,12 @@ Pipe::Pipe(Filter* f1, Filter* f2, Filter* f3, Filter* f4) /* * Pipe Constructor */ -Pipe::Pipe(Filter* filter_array[], u32bit count) +Pipe::Pipe(std::initializer_list args) { init(); - for(u32bit j = 0; j != count; ++j) - append(filter_array[j]); + + for(auto i = args.begin(); i != args.end(); ++i) + append(*i); } /* diff --git a/src/filters/pipe.h b/src/filters/pipe.h index 120f2fbdd..7cf7d6df2 100644 --- a/src/filters/pipe.h +++ b/src/filters/pipe.h @@ -11,6 +11,7 @@ #include #include #include +#include #include namespace Botan { @@ -238,11 +239,11 @@ class BOTAN_DLL Pipe : public DataSource Pipe(Filter* = 0, Filter* = 0, Filter* = 0, Filter* = 0); /** - * Construct a Pipe from range of filters passed as an array + * Construct a Pipe from a list of filters * @param filters the set of filters to use - * @param count the number of elements in filters */ - Pipe(Filter* filters[], u32bit count); + Pipe(std::initializer_list filters); + ~Pipe(); private: Pipe(const Pipe&) : DataSource() {} -- cgit v1.2.3 From 49b20f4e4ff3b8e3141905871ccae9fc70e77a1d Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 17 Nov 2009 16:25:51 +0000 Subject: Use the new support for explicitly deleting functions instead of hiding them as private variables for operator= and copy constructors that shouldn't be used. --- src/asn1/ber_dec.h | 4 ++-- src/block/block_cipher.h | 15 --------------- src/cert/x509/x509_ca.h | 6 +++--- src/cert/x509/x509stor.h | 4 ++-- src/filters/data_snk.h | 6 +++--- src/filters/data_src.h | 5 ++--- src/filters/filter.h | 11 +++++------ src/filters/pipe.h | 5 +++-- src/libstate/libstate.h | 6 +++--- src/s2k/s2k.h | 7 ++++--- 10 files changed, 27 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/asn1/ber_dec.h b/src/asn1/ber_dec.h index 2e38af301..7de7f3753 100644 --- a/src/asn1/ber_dec.h +++ b/src/asn1/ber_dec.h @@ -55,14 +55,14 @@ class BOTAN_DLL BER_Decoder BER_Decoder& decode_optional_string(MemoryRegion&, ASN1_Tag, u16bit); + BER_Decoder& operator=(const BER_Decoder&) = delete; + BER_Decoder(DataSource&); BER_Decoder(const byte[], u32bit); BER_Decoder(const MemoryRegion&); BER_Decoder(const BER_Decoder&); ~BER_Decoder(); private: - BER_Decoder& operator=(const BER_Decoder&) { return (*this); } - BER_Decoder* parent; DataSource* source; BER_Object pushed; diff --git a/src/block/block_cipher.h b/src/block/block_cipher.h index 1dcdde7c7..e97eebf0f 100644 --- a/src/block/block_cipher.h +++ b/src/block/block_cipher.h @@ -14,21 +14,6 @@ namespace Botan { /** * This class represents a block cipher object. -* -* It would be very useful to extend this interface to support the -* encryption of multiple blocks at a time. This could help -* performance, wrt cache effects in the software implementations, and -* could be a big deal when supporting block ciphers implemented as -* hardware devices. It could be used by implementations of ECB, and -* more importantly counter mode (which most designs are moving to, due -* to the parallelism possible in counter mode which is not the case -* with feedback-based modes like CBC). -* -* Probable future API here: -* virtual void encrypt_n(const byte in[], byte out[], -* u32bit blocks) const = 0; -* virtual void decrypt_n(const byte in[], byte out[], -* u32bit blocks) const = 0; */ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm { diff --git a/src/cert/x509/x509_ca.h b/src/cert/x509/x509_ca.h index 6eb4bbbef..b680bd0e4 100644 --- a/src/cert/x509/x509_ca.h +++ b/src/cert/x509/x509_ca.h @@ -97,11 +97,11 @@ class BOTAN_DLL X509_CA const Private_Key& key, const std::string& hash_fn); + X509_CA(const X509_CA&) = delete; + X509_CA& operator=(const X509_CA&) = delete; + ~X509_CA(); private: - X509_CA(const X509_CA&) {} - X509_CA& operator=(const X509_CA&) { return (*this); } - X509_CRL make_crl(const std::vector& entries, u32bit crl_number, u32bit next_update, RandomNumberGenerator& rng) const; diff --git a/src/cert/x509/x509stor.h b/src/cert/x509/x509stor.h index ab31663ed..958b6da0f 100644 --- a/src/cert/x509/x509stor.h +++ b/src/cert/x509/x509stor.h @@ -94,14 +94,14 @@ class BOTAN_DLL X509_Store static X509_Code check_sig(const X509_Object&, Public_Key*); + X509_Store& operator=(const X509_Store&) = delete; + X509_Store(u32bit time_slack = 24*60*60, u32bit cache_results = 30*60); X509_Store(const X509_Store&); ~X509_Store(); private: - X509_Store& operator=(const X509_Store&) { return (*this); } - class BOTAN_DLL Cert_Info { public: diff --git a/src/filters/data_snk.h b/src/filters/data_snk.h index 61ddf6e0d..fda06e492 100644 --- a/src/filters/data_snk.h +++ b/src/filters/data_snk.h @@ -22,9 +22,9 @@ class BOTAN_DLL DataSink : public Filter bool attachable() { return false; } DataSink() {} virtual ~DataSink() {} - private: - DataSink& operator=(const DataSink&) { return (*this); } - DataSink(const DataSink&); + + DataSink& operator=(const DataSink&) = delete; + DataSink(const DataSink&) = delete; }; /** diff --git a/src/filters/data_src.h b/src/filters/data_src.h index e16217e0f..dea46584c 100644 --- a/src/filters/data_src.h +++ b/src/filters/data_src.h @@ -78,9 +78,8 @@ class BOTAN_DLL DataSource DataSource() {} virtual ~DataSource() {} - private: - DataSource& operator=(const DataSource&) { return (*this); } - DataSource(const DataSource&); + DataSource& operator=(const DataSource&) = delete; + DataSource(const DataSource&) = delete; }; /** diff --git a/src/filters/filter.h b/src/filters/filter.h index b13a36650..8fc114db7 100644 --- a/src/filters/filter.h +++ b/src/filters/filter.h @@ -19,6 +19,8 @@ namespace Botan { class BOTAN_DLL Filter { public: + friend class Pipe; + friend class Fanout_Filter; /** * Write a portion of a message to this filter. @@ -56,6 +58,9 @@ class BOTAN_DLL Filter */ void finish_msg(); + Filter(const Filter&) = delete; + Filter& operator=(const Filter&) = delete; + virtual ~Filter() {} protected: void send(const byte[], u32bit); @@ -63,12 +68,6 @@ class BOTAN_DLL Filter void send(const MemoryRegion& in) { send(in.begin(), in.size()); } Filter(); private: - Filter(const Filter&) {} - Filter& operator=(const Filter&) { return (*this); } - - friend class Pipe; - friend class Fanout_Filter; - u32bit total_ports() const; u32bit current_port() const { return port_num; } void set_port(u32bit); diff --git a/src/filters/pipe.h b/src/filters/pipe.h index 7cf7d6df2..58bb6d22a 100644 --- a/src/filters/pipe.h +++ b/src/filters/pipe.h @@ -244,10 +244,11 @@ class BOTAN_DLL Pipe : public DataSource */ Pipe(std::initializer_list filters); + Pipe(const Pipe&) = delete; + Pipe& operator=(const Pipe&) = delete; + ~Pipe(); private: - Pipe(const Pipe&) : DataSource() {} - Pipe& operator=(const Pipe&) { return (*this); } void init(); void destruct(Filter*); void find_endpoints(Filter*); diff --git a/src/libstate/libstate.h b/src/libstate/libstate.h index 91fd58dff..e9a08b74b 100644 --- a/src/libstate/libstate.h +++ b/src/libstate/libstate.h @@ -28,6 +28,9 @@ class BOTAN_DLL Library_State Library_State(); ~Library_State(); + Library_State(const Library_State&) = delete; + Library_State& operator=(const Library_State&) = delete; + void initialize(); Algorithm_Factory& algorithm_factory(); @@ -96,9 +99,6 @@ class BOTAN_DLL Library_State private: void load_default_config(); - Library_State(const Library_State&) {} - Library_State& operator=(const Library_State&) { return (*this); } - std::mutex config_lock; std::map config; diff --git a/src/s2k/s2k.h b/src/s2k/s2k.h index 7af92519b..ca86ab77a 100644 --- a/src/s2k/s2k.h +++ b/src/s2k/s2k.h @@ -87,12 +87,13 @@ class BOTAN_DLL S2K S2K() { iter = 0; } virtual ~S2K() {} - private: - S2K(const S2K&) {} - S2K& operator=(const S2K&) { return (*this); } + S2K(const S2K&) = delete; + S2K& operator=(const S2K&) = delete; + private: virtual OctetString derive(u32bit, const std::string&, const byte[], u32bit, u32bit) const = 0; + SecureVector salt; u32bit iter; }; -- cgit v1.2.3 From aa361909f881b791cdce67993f3ab0d6af47c140 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 17 Nov 2009 17:40:48 +0000 Subject: In IF decryption, two large powmods are done, one mod p and one mod q. Spawn one of them off in a new thread and compute the other on the current thread. Performance on my Core2 shows a 60 to 90% improvement in overall speed in RSA private key operations. Will probably be even better once std::async is available (not currently in GCC) since it will probably use a thread pool which will amortize the thread creation/shutdown cost. --- src/pubkey/if_algo/if_op.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/pubkey/if_algo/if_op.cpp b/src/pubkey/if_algo/if_op.cpp index 27aef453e..a59c7d5f9 100644 --- a/src/pubkey/if_algo/if_op.cpp +++ b/src/pubkey/if_algo/if_op.cpp @@ -7,6 +7,8 @@ #include #include +#include +#include namespace Botan { @@ -38,8 +40,27 @@ BigInt Default_IF_Op::private_op(const BigInt& i) const if(q == 0) throw Internal_Error("Default_IF_Op::private_op: No private key"); - BigInt j1 = powermod_d1_p(i); + /* + * A simple std::bind(powermod_d1_p, i) would work instead of a + * lambda but GCC 4.5's std::result_of doesn't use decltype and gets + * confused + * + * Todo: use std::async() once it is in GCC + * auto future_j1 = std::async(std::bind(powermod_d1_p, i)); + * BigInt j2 = powermod_d2_q(i); + * BigInt j1 = future.get(); + */ + std::packaged_task task_j1([&]() { return powermod_d1_p(i); }); + auto future_j1 = task_j1.get_future(); + + std::thread thr_j1(std::move(task_j1)); + BigInt j2 = powermod_d2_q(i); + + BigInt j1 = future_j1.get(); + + thr_j1.join(); + j1 = reducer.reduce(sub_mul(j1, j2, c)); return mul_add(j1, q, j2); } -- cgit v1.2.3 From e25d4ec4612f74bfed1ffe34cc07a798c9e7a4ce Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 17 Nov 2009 17:50:30 +0000 Subject: Use a thread to compute half of the DSA verification. 20-90% faster depending on key size on a Core2. --- src/pubkey/dsa/dsa_op.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/pubkey/dsa/dsa_op.cpp b/src/pubkey/dsa/dsa_op.cpp index 5b921441d..114731eea 100644 --- a/src/pubkey/dsa/dsa_op.cpp +++ b/src/pubkey/dsa/dsa_op.cpp @@ -6,6 +6,8 @@ */ #include +#include +#include namespace Botan { @@ -40,8 +42,23 @@ bool Default_DSA_Op::verify(const byte msg[], u32bit msg_len, return false; s = inverse_mod(s, q); - s = mod_p.multiply(powermod_g_p(mod_q.multiply(s, i)), - powermod_y_p(mod_q.multiply(s, r))); + + // Todo: use async() + + std::packaged_task task_s_i( + [&]() { return powermod_g_p(mod_q.multiply(s, i)); }); + + auto future_s_i = task_s_i.get_future(); + + std::thread thr_s_i(std::move(task_s_i)); + + BigInt s_r = powermod_y_p(mod_q.multiply(s, r)); + + BigInt s_i = future_s_i.get(); + + thr_s_i.join(); + + s = mod_p.multiply(s_i, s_r); return (mod_q.reduce(s) == r); } -- cgit v1.2.3 From 0467bf03eae3ace3412b5218210eb15b6c6bd30b Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 17 Nov 2009 18:17:47 +0000 Subject: Also parallelize DSA signature generation, though due to critical path constraints there isn't that much parallelization to extract. Slightly faster; better for smaller key sizes as once a certain point is reached one thread is doing a lot more work than the other. --- src/pubkey/dsa/dsa_op.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/pubkey/dsa/dsa_op.cpp b/src/pubkey/dsa/dsa_op.cpp index 114731eea..4c84667eb 100644 --- a/src/pubkey/dsa/dsa_op.cpp +++ b/src/pubkey/dsa/dsa_op.cpp @@ -75,8 +75,19 @@ SecureVector Default_DSA_Op::sign(const byte in[], u32bit length, const BigInt& q = group.get_q(); BigInt i(in, length); - BigInt r = mod_q.reduce(powermod_g_p(k)); - BigInt s = mod_q.multiply(inverse_mod(k, q), mul_add(x, r, i)); + std::packaged_task task_r( + [&]() { return mod_q.reduce(powermod_g_p(k)); }); + + auto future_r = task_r.get_future(); + + std::thread thr_r(std::move(task_r)); + + BigInt s = inverse_mod(k, q); + + BigInt r = future_r.get(); + thr_r.join(); + + s = mod_q.multiply(s, mul_add(x, r, i)); if(r.is_zero() || s.is_zero()) throw Internal_Error("Default_DSA_Op::sign: r or s was zero"); -- cgit v1.2.3 From d5310f79218a960fea4b8522d4529305971334ce Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 17 Nov 2009 21:45:09 +0000 Subject: Add a simple version of std::async as std_async in async.h and use it in the RSA and DSA ops. --- src/pubkey/dsa/dsa_op.cpp | 27 +++++---------------------- src/pubkey/if_algo/if_op.cpp | 21 ++++----------------- src/utils/async.h | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 39 deletions(-) create mode 100644 src/utils/async.h (limited to 'src') diff --git a/src/pubkey/dsa/dsa_op.cpp b/src/pubkey/dsa/dsa_op.cpp index 4c84667eb..03eaebfb0 100644 --- a/src/pubkey/dsa/dsa_op.cpp +++ b/src/pubkey/dsa/dsa_op.cpp @@ -1,13 +1,12 @@ /* * DSA Operations -* (C) 1999-2007 Jack Lloyd +* (C) 1999-2009 Jack Lloyd * * Distributed under the terms of the Botan license */ #include -#include -#include +#include namespace Botan { @@ -43,21 +42,12 @@ bool Default_DSA_Op::verify(const byte msg[], u32bit msg_len, s = inverse_mod(s, q); - // Todo: use async() - - std::packaged_task task_s_i( + auto future_s_i = std_async( [&]() { return powermod_g_p(mod_q.multiply(s, i)); }); - auto future_s_i = task_s_i.get_future(); - - std::thread thr_s_i(std::move(task_s_i)); - BigInt s_r = powermod_y_p(mod_q.multiply(s, r)); - BigInt s_i = future_s_i.get(); - thr_s_i.join(); - s = mod_p.multiply(s_i, s_r); return (mod_q.reduce(s) == r); @@ -72,20 +62,13 @@ SecureVector Default_DSA_Op::sign(const byte in[], u32bit length, if(x == 0) throw Internal_Error("Default_DSA_Op::sign: No private key"); + auto future_r = std_async([&]() { return mod_q.reduce(powermod_g_p(k)); }); + const BigInt& q = group.get_q(); BigInt i(in, length); - std::packaged_task task_r( - [&]() { return mod_q.reduce(powermod_g_p(k)); }); - - auto future_r = task_r.get_future(); - - std::thread thr_r(std::move(task_r)); - BigInt s = inverse_mod(k, q); - BigInt r = future_r.get(); - thr_r.join(); s = mod_q.multiply(s, mul_add(x, r, i)); diff --git a/src/pubkey/if_algo/if_op.cpp b/src/pubkey/if_algo/if_op.cpp index a59c7d5f9..7974bf4f0 100644 --- a/src/pubkey/if_algo/if_op.cpp +++ b/src/pubkey/if_algo/if_op.cpp @@ -1,14 +1,13 @@ /* -* IF (RSA/RW) Operation -* (C) 1999-2007 Jack Lloyd +* Integer Factorization Scheme (RSA/RW) Operation +* (C) 1999-2009 Jack Lloyd * * Distributed under the terms of the Botan license */ #include #include -#include -#include +#include namespace Botan { @@ -44,23 +43,11 @@ BigInt Default_IF_Op::private_op(const BigInt& i) const * A simple std::bind(powermod_d1_p, i) would work instead of a * lambda but GCC 4.5's std::result_of doesn't use decltype and gets * confused - * - * Todo: use std::async() once it is in GCC - * auto future_j1 = std::async(std::bind(powermod_d1_p, i)); - * BigInt j2 = powermod_d2_q(i); - * BigInt j1 = future.get(); */ - std::packaged_task task_j1([&]() { return powermod_d1_p(i); }); - auto future_j1 = task_j1.get_future(); - - std::thread thr_j1(std::move(task_j1)); - + auto future_j1 = std_async([&]() { return powermod_d1_p(i); }); BigInt j2 = powermod_d2_q(i); - BigInt j1 = future_j1.get(); - thr_j1.join(); - j1 = reducer.reduce(sub_mul(j1, j2, c)); return mul_add(j1, q, j2); } diff --git a/src/utils/async.h b/src/utils/async.h new file mode 100644 index 000000000..85702c114 --- /dev/null +++ b/src/utils/async.h @@ -0,0 +1,33 @@ +/** +* Standin for C++0x's std::async +* (C) 2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ASYNC_H__ +#define BOTAN_ASYNC_H__ + +#include +#include + +namespace Botan { + +/** +* A simple version of std::async (as it is not in GCC 4.5) +* Will be removed once GCC supports it natively +*/ +template +auto std_async(F f) -> std::unique_future + { + typedef decltype(f()) result_type; + std::packaged_task task(std::move(f)); + std::unique_future future = task.get_future(); + std::thread thread(std::move(task)); + thread.detach(); + return future; + } + +} + +#endif -- cgit v1.2.3 From 061733a4f765a4a40ae12108bc8e61a9bcf3a4d8 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 18 Nov 2009 01:41:31 +0000 Subject: Use async in ElGamal encryption and Nyberg-Rueppel verification --- src/math/numbertheory/powm_fw.cpp | 35 +++++++++++++++++++++++++++++------ src/pubkey/elgamal/elg_op.cpp | 6 ++++-- src/pubkey/nr/nr_op.cpp | 8 ++++++-- 3 files changed, 39 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/math/numbertheory/powm_fw.cpp b/src/math/numbertheory/powm_fw.cpp index b764ee7aa..e4272f20d 100644 --- a/src/math/numbertheory/powm_fw.cpp +++ b/src/math/numbertheory/powm_fw.cpp @@ -77,17 +77,40 @@ BigInt Fixed_Window_Exponentiator::execute() const { const u32bit exp_nibbles = (exp.bits() + window_bits - 1) / window_bits; - BigInt x = 1; - for(u32bit j = exp_nibbles; j > 0; --j) + if(exp_nibbles == 0) + return 1; + + BigInt x1 = 1; + + for(u32bit j = 0; j != exp_nibbles / 2; ++j) + { + for(u32bit k = 0; k != window_bits; ++k) + x1 = reducer.square(x1); + + u32bit nibble = exp.get_substring(window_bits*(exp_nibbles-1-j), + window_bits); + + if(nibble) + x1 = reducer.multiply(x1, g[nibble-1]); + } + + for(u32bit k = 0; k != window_bits; ++k) + x1 = reducer.square(x1); + BigInt x2 = 1; + + for(u32bit j = exp_nibbles / 2; j != exp_nibbles; ++j) { for(u32bit k = 0; k != window_bits; ++k) - x = reducer.square(x); + x2 = reducer.square(x2); + + u32bit nibble = exp.get_substring(window_bits*(exp_nibbles-1-j), + window_bits); - u32bit nibble = exp.get_substring(window_bits*(j-1), window_bits); if(nibble) - x = reducer.multiply(x, g[nibble-1]); + x2 = reducer.multiply(x2, g[nibble-1]); } - return x; + + return reducer.multiply(x1, x2); } /* diff --git a/src/pubkey/elgamal/elg_op.cpp b/src/pubkey/elgamal/elg_op.cpp index 1e476ab7a..db828a300 100644 --- a/src/pubkey/elgamal/elg_op.cpp +++ b/src/pubkey/elgamal/elg_op.cpp @@ -1,11 +1,12 @@ /* * ElGamal Operations -* (C) 1999-2007 Jack Lloyd +* (C) 1999-2009 Jack Lloyd * * Distributed under the terms of the Botan license */ #include +#include namespace Botan { @@ -33,8 +34,9 @@ SecureVector Default_ELG_Op::encrypt(const byte in[], u32bit length, if(m >= p) throw Invalid_Argument("Default_ELG_Op::encrypt: Input is too large"); - BigInt a = powermod_g_p(k); + auto future_a = std_async([&]() { return powermod_g_p(k); }); BigInt b = mod_p.multiply(m, powermod_y_p(k)); + BigInt a = future_a.get(); SecureVector output(2*p.bytes()); a.binary_encode(output + (p.bytes() - a.bytes())); diff --git a/src/pubkey/nr/nr_op.cpp b/src/pubkey/nr/nr_op.cpp index b5efa3d37..49aa9fc00 100644 --- a/src/pubkey/nr/nr_op.cpp +++ b/src/pubkey/nr/nr_op.cpp @@ -1,11 +1,12 @@ /* * NR Operations -* (C) 1999-2007 Jack Lloyd +* (C) 1999-2009 Jack Lloyd * * Distributed under the terms of the Botan license */ #include +#include namespace Botan { @@ -37,7 +38,10 @@ SecureVector Default_NR_Op::verify(const byte in[], u32bit length) const if(c.is_zero() || c >= q || d >= q) throw Invalid_Argument("Default_NR_Op::verify: Invalid signature"); - BigInt i = mod_p.multiply(powermod_g_p(d), powermod_y_p(c)); + auto future_y_c = std_async([&]() { return powermod_y_p(c); }); + BigInt g_d = powermod_g_p(d); + + BigInt i = mod_p.multiply(g_d, future_y_c.get()); return BigInt::encode(mod_q.reduce(c - i)); } -- cgit v1.2.3 From 866a1be9b5a0136c600c463a140bd0aaa69173ff Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 18 Nov 2009 01:44:04 +0000 Subject: Remove accidentally checked in change to powm_fw.cpp --- src/math/numbertheory/powm_fw.cpp | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/math/numbertheory/powm_fw.cpp b/src/math/numbertheory/powm_fw.cpp index e4272f20d..b764ee7aa 100644 --- a/src/math/numbertheory/powm_fw.cpp +++ b/src/math/numbertheory/powm_fw.cpp @@ -77,40 +77,17 @@ BigInt Fixed_Window_Exponentiator::execute() const { const u32bit exp_nibbles = (exp.bits() + window_bits - 1) / window_bits; - if(exp_nibbles == 0) - return 1; - - BigInt x1 = 1; - - for(u32bit j = 0; j != exp_nibbles / 2; ++j) - { - for(u32bit k = 0; k != window_bits; ++k) - x1 = reducer.square(x1); - - u32bit nibble = exp.get_substring(window_bits*(exp_nibbles-1-j), - window_bits); - - if(nibble) - x1 = reducer.multiply(x1, g[nibble-1]); - } - - for(u32bit k = 0; k != window_bits; ++k) - x1 = reducer.square(x1); - BigInt x2 = 1; - - for(u32bit j = exp_nibbles / 2; j != exp_nibbles; ++j) + BigInt x = 1; + for(u32bit j = exp_nibbles; j > 0; --j) { for(u32bit k = 0; k != window_bits; ++k) - x2 = reducer.square(x2); - - u32bit nibble = exp.get_substring(window_bits*(exp_nibbles-1-j), - window_bits); + x = reducer.square(x); + u32bit nibble = exp.get_substring(window_bits*(j-1), window_bits); if(nibble) - x2 = reducer.multiply(x2, g[nibble-1]); + x = reducer.multiply(x, g[nibble-1]); } - - return reducer.multiply(x1, x2); + return x; } /* -- cgit v1.2.3 From 6e45f118d112ee55b980a262b8b9ec67e66e9268 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 18 Nov 2009 07:20:44 +0000 Subject: auto_ptr is unique_ptr in C++0x --- src/pubkey/ecdsa/ecdsa.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/pubkey/ecdsa/ecdsa.cpp b/src/pubkey/ecdsa/ecdsa.cpp index aba571eb6..ea90010b1 100644 --- a/src/pubkey/ecdsa/ecdsa.cpp +++ b/src/pubkey/ecdsa/ecdsa.cpp @@ -37,10 +37,10 @@ ECDSA_PrivateKey::ECDSA_PrivateKey(RandomNumberGenerator& rng, ECDSA_PrivateKey::ECDSA_PrivateKey(const EC_Domain_Params& domain, const BigInt& x) { - mp_dom_pars = std::auto_ptr(new EC_Domain_Params(domain)); + mp_dom_pars = std::unique_ptr(new EC_Domain_Params(domain)); m_private_value = x; - mp_public_point = std::auto_ptr(new PointGFp (mp_dom_pars->get_base_point())); + mp_public_point = std::unique_ptr(new PointGFp (mp_dom_pars->get_base_point())); mp_public_point->mult_this_secure(m_private_value, mp_dom_pars->get_order(), mp_dom_pars->get_order()-1); -- cgit v1.2.3 From 7a62a8c05ddf02073108f4117a80065d2d8ae7ec Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 18 Nov 2009 08:54:45 +0000 Subject: Remove to_string, replacing with std::to_string Convert to_u32bit to use the new C++0x library func stoul instead of hand-written code. --- checks/pk_bench.cpp | 16 ++++----- src/asn1/asn1_int.cpp | 4 +-- src/asn1/asn1_oid.cpp | 2 +- src/asn1/asn1_str.cpp | 2 +- src/asn1/asn1_tm.cpp | 47 +++++++++++++++----------- src/asn1/der_enc.cpp | 2 +- src/block/lion/lion.cpp | 2 +- src/block/misty1/misty1.cpp | 2 +- src/block/rc5/rc5.cpp | 2 +- src/block/safer/safer_sk.cpp | 2 +- src/cert/cvc/asn1_eac_tm.cpp | 66 ++++++++++++++++++------------------- src/cert/x509/pkcs10.cpp | 2 +- src/cert/x509/x509_crl.cpp | 2 +- src/cert/x509/x509cert.cpp | 2 +- src/engine/openssl/arc4_openssl.cpp | 2 +- src/filters/hex/hex.cpp | 2 +- src/filters/modes/cfb/cfb.cpp | 2 +- src/filters/modes/eax/eax.cpp | 2 +- src/filters/pipe.cpp | 2 +- src/hash/skein/skein_512.cpp | 2 +- src/hash/tiger/tiger.cpp | 6 ++-- src/math/numbertheory/dsa_gen.cpp | 6 ++-- src/math/numbertheory/make_prm.cpp | 4 +-- src/pubkey/dl_group/dl_group.cpp | 8 ++--- src/pubkey/pubkey.cpp | 4 +-- src/pubkey/rsa/rsa.cpp | 2 +- src/pubkey/rw/rw.cpp | 2 +- src/stream/arc4/arc4.cpp | 2 +- src/utils/charset.cpp | 2 +- src/utils/datastor/datastor.cpp | 2 +- src/utils/exceptn.cpp | 6 ++-- src/utils/parsing.cpp | 49 +-------------------------- src/utils/parsing.h | 6 ++-- src/utils/version.cpp | 6 ++-- 34 files changed, 115 insertions(+), 155 deletions(-) (limited to 'src') diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp index 43d15010a..72c5f53f6 100644 --- a/checks/pk_bench.cpp +++ b/checks/pk_bench.cpp @@ -215,7 +215,7 @@ void benchmark_rsa(RandomNumberGenerator& rng, sig_timer, rng, 10000, seconds); } - const std::string rsa_keylen = "RSA-" + to_string(keylen); + const std::string rsa_keylen = "RSA-" + std::to_string(keylen); report.report(rsa_keylen, keygen_timer); report.report(rsa_keylen, verify_timer); @@ -266,7 +266,7 @@ void benchmark_rw(RandomNumberGenerator& rng, benchmark_sig_ver(*ver, *sig, verify_timer, sig_timer, rng, 10000, seconds); } - const std::string nm = "RW-" + to_string(keylen); + const std::string nm = "RW-" + std::to_string(keylen); report.report(nm, keygen_timer); report.report(nm, verify_timer); report.report(nm, sig_timer); @@ -301,7 +301,7 @@ void benchmark_ecdsa(RandomNumberGenerator& rng, if(hashbits == 521) hashbits = 512; - const std::string padding = "EMSA1(SHA-" + to_string(hashbits) + ")"; + const std::string padding = "EMSA1(SHA-" + std::to_string(hashbits) + ")"; Timer keygen_timer("keygen"); Timer verify_timer(padding + " verify"); @@ -321,7 +321,7 @@ void benchmark_ecdsa(RandomNumberGenerator& rng, sig_timer, rng, 1000, seconds); } - const std::string nm = "ECDSA-" + to_string(pbits); + const std::string nm = "ECDSA-" + std::to_string(pbits); report.report(nm, keygen_timer); report.report(nm, verify_timer); @@ -387,7 +387,7 @@ void benchmark_eckaeg(RandomNumberGenerator& rng, } } - const std::string nm = "ECKAEG-" + to_string(pbits); + const std::string nm = "ECKAEG-" + std::to_string(pbits); report.report(nm, keygen_timer); report.report(nm, kex_timer); } @@ -415,7 +415,7 @@ void benchmark_dsa_nr(RandomNumberGenerator& rng, u32bit pbits = to_u32bit(split_on(domains[j], '/')[2]); u32bit qbits = (pbits <= 1024) ? 160 : 256; - const std::string padding = "EMSA1(SHA-" + to_string(qbits) + ")"; + const std::string padding = "EMSA1(SHA-" + std::to_string(qbits) + ")"; Timer keygen_timer("keygen"); Timer verify_timer(padding + " verify"); @@ -437,7 +437,7 @@ void benchmark_dsa_nr(RandomNumberGenerator& rng, sig_timer, rng, 1000, seconds); } - const std::string nm = algo_name + "-" + to_string(pbits); + const std::string nm = algo_name + "-" + std::to_string(pbits); report.report(nm, keygen_timer); report.report(nm, verify_timer); report.report(nm, sig_timer); @@ -606,7 +606,7 @@ void benchmark_elg(RandomNumberGenerator& rng, benchmark_enc_dec(*enc, *dec, enc_timer, dec_timer, rng, 1000, seconds); } - const std::string nm = algo_name + "-" + to_string(pbits); + const std::string nm = algo_name + "-" + std::to_string(pbits); report.report(nm, keygen_timer); report.report(nm, enc_timer); report.report(nm, dec_timer); diff --git a/src/asn1/asn1_int.cpp b/src/asn1/asn1_int.cpp index 5e18f3961..af01d8fa3 100644 --- a/src/asn1/asn1_int.cpp +++ b/src/asn1/asn1_int.cpp @@ -20,11 +20,11 @@ BER_Decoding_Error::BER_Decoding_Error(const std::string& str) : Decoding_Error("BER: " + str) {} BER_Bad_Tag::BER_Bad_Tag(const std::string& str, ASN1_Tag tag) : - BER_Decoding_Error(str + ": " + to_string(tag)) {} + BER_Decoding_Error(str + ": " + std::to_string(tag)) {} BER_Bad_Tag::BER_Bad_Tag(const std::string& str, ASN1_Tag tag1, ASN1_Tag tag2) : - BER_Decoding_Error(str + ": " + to_string(tag1) + "/" + to_string(tag2)) {} + BER_Decoding_Error(str + ": " + std::to_string(tag1) + "/" + std::to_string(tag2)) {} namespace ASN1 { diff --git a/src/asn1/asn1_oid.cpp b/src/asn1/asn1_oid.cpp index 531ceb9b2..c72ee7a1a 100644 --- a/src/asn1/asn1_oid.cpp +++ b/src/asn1/asn1_oid.cpp @@ -44,7 +44,7 @@ std::string OID::as_string() const std::string oid_str; for(u32bit j = 0; j != id.size(); ++j) { - oid_str += to_string(id[j]); + oid_str += std::to_string(id[j]); if(j != id.size() - 1) oid_str += '.'; } diff --git a/src/asn1/asn1_str.cpp b/src/asn1/asn1_str.cpp index 25782e239..892a44472 100644 --- a/src/asn1/asn1_str.cpp +++ b/src/asn1/asn1_str.cpp @@ -89,7 +89,7 @@ ASN1_String::ASN1_String(const std::string& str, ASN1_Tag t) : tag(t) tag != UTF8_STRING && tag != BMP_STRING) throw Invalid_Argument("ASN1_String: Unknown string type " + - to_string(tag)); + std::to_string(tag)); } /* diff --git a/src/asn1/asn1_tm.cpp b/src/asn1/asn1_tm.cpp index c57d1bc73..9df10f4a3 100644 --- a/src/asn1/asn1_tm.cpp +++ b/src/asn1/asn1_tm.cpp @@ -103,11 +103,13 @@ void X509_Time::set_to(const std::string& time_str) void X509_Time::set_to(const std::string& t_spec, ASN1_Tag tag) { if(tag != GENERALIZED_TIME && tag != UTC_TIME) - throw Invalid_Argument("X509_Time: Invalid tag " + to_string(tag)); + throw Invalid_Argument("X509_Time: Invalid tag " + std::to_string(tag)); + if(tag == GENERALIZED_TIME && t_spec.size() != 13 && t_spec.size() != 15) throw Invalid_Argument("Invalid GeneralizedTime: " + t_spec); if(tag == UTC_TIME && t_spec.size() != 11 && t_spec.size() != 13) throw Invalid_Argument("Invalid UTCTime: " + t_spec); + if(t_spec[t_spec.size()-1] != 'Z') throw Invalid_Argument("Invalid time encoding: " + t_spec); @@ -179,21 +181,30 @@ std::string X509_Time::as_string() const if(time_is_set() == false) throw Invalid_State("X509_Time::as_string: No time set"); - std::string asn1rep; - if(tag == GENERALIZED_TIME) - asn1rep = to_string(year, 4); - else + u32bit full_year = year; + + if(tag == UTC_TIME) { if(year < 1950 || year >= 2050) throw Encoding_Error("X509_Time: The time " + readable_string() + " cannot be encoded as a UTCTime"); - u32bit asn1year = (year >= 2000) ? (year - 2000) : (year - 1900); - asn1rep = to_string(asn1year, 2); + + full_year = (year >= 2000) ? (year - 2000) : (year - 1900); } - asn1rep += to_string(month, 2) + to_string(day, 2); - asn1rep += to_string(hour, 2) + to_string(minute, 2) + to_string(second, 2); - asn1rep += "Z"; - return asn1rep; + + std::string repr = std::to_string(full_year*10000000000 + + month*100000000 + + day*1000000 + + hour*10000 + + minute*100 + + second) + "Z"; + + u32bit desired_size = (tag == UTC_TIME) ? 13 : 15; + + while(repr.size() < desired_size) + repr = "0" + repr; + + return repr; } /* @@ -212,14 +223,12 @@ std::string X509_Time::readable_string() const if(time_is_set() == false) throw Invalid_State("X509_Time::readable_string: No time set"); - std::string readable; - readable += to_string(year, 4) + "/"; - readable += to_string(month ) + "/"; - readable += to_string(day ) + " "; - readable += to_string(hour ) + ":"; - readable += to_string(minute, 2) + ":"; - readable += to_string(second, 2) + " UTC"; - return readable; + std::string output(24, 0); + + std::sprintf(&output[0], "%04d/%02d/%02d %02d:%02d:%02d UTC", + year, month, day, hour, minute, second); + + return output; } /* diff --git a/src/asn1/der_enc.cpp b/src/asn1/der_enc.cpp index bee269431..1863e400d 100644 --- a/src/asn1/der_enc.cpp +++ b/src/asn1/der_enc.cpp @@ -24,7 +24,7 @@ SecureVector encode_tag(ASN1_Tag type_tag, ASN1_Tag class_tag) { if((class_tag | 0xE0) != 0xE0) throw Encoding_Error("DER_Encoder: Invalid class tag " + - to_string(class_tag)); + std::to_string(class_tag)); SecureVector encoded_tag; if(type_tag <= 30) diff --git a/src/block/lion/lion.cpp b/src/block/lion/lion.cpp index d8822b9f2..81252f5e3 100644 --- a/src/block/lion/lion.cpp +++ b/src/block/lion/lion.cpp @@ -81,7 +81,7 @@ std::string Lion::name() const { return "Lion(" + hash->name() + "," + cipher->name() + "," + - to_string(BLOCK_SIZE) + ")"; + std::to_string(BLOCK_SIZE) + ")"; } /* diff --git a/src/block/misty1/misty1.cpp b/src/block/misty1/misty1.cpp index 8a92824cc..56cd7446c 100644 --- a/src/block/misty1/misty1.cpp +++ b/src/block/misty1/misty1.cpp @@ -255,7 +255,7 @@ MISTY1::MISTY1(u32bit rounds) : BlockCipher(8, 16) { if(rounds != 8) throw Invalid_Argument("MISTY1: Invalid number of rounds: " - + to_string(rounds)); + + std::to_string(rounds)); } } diff --git a/src/block/rc5/rc5.cpp b/src/block/rc5/rc5.cpp index 0bd596b10..1b71de85a 100644 --- a/src/block/rc5/rc5.cpp +++ b/src/block/rc5/rc5.cpp @@ -99,7 +99,7 @@ void RC5::key_schedule(const byte key[], u32bit length) */ std::string RC5::name() const { - return "RC5(" + to_string(ROUNDS) + ")"; + return "RC5(" + std::to_string(ROUNDS) + ")"; } /* diff --git a/src/block/safer/safer_sk.cpp b/src/block/safer/safer_sk.cpp index eb5c22fc9..fcbe84c8b 100644 --- a/src/block/safer/safer_sk.cpp +++ b/src/block/safer/safer_sk.cpp @@ -112,7 +112,7 @@ void SAFER_SK::key_schedule(const byte key[], u32bit) */ std::string SAFER_SK::name() const { - return "SAFER-SK(" + to_string(ROUNDS) + ")"; + return "SAFER-SK(" + std::to_string(ROUNDS) + ")"; } /* diff --git a/src/cert/cvc/asn1_eac_tm.cpp b/src/cert/cvc/asn1_eac_tm.cpp index f361e6098..b0238ac4d 100644 --- a/src/cert/cvc/asn1_eac_tm.cpp +++ b/src/cert/cvc/asn1_eac_tm.cpp @@ -1,7 +1,7 @@ /* * EAC Time Types * (C) 2007 FlexSecure GmbH -* 2008 Jack Lloyd +* 2008-2009 Jack Lloyd * * Distributed under the terms of the Botan license */ @@ -22,7 +22,7 @@ SecureVector enc_two_digit(u32bit in) { SecureVector result; in %= 100; - if (in < 10) + if(in < 10) result.append(0x00); else { @@ -84,7 +84,7 @@ EAC_Time::EAC_Time(u32bit y, u32bit m, u32bit d, ASN1_Tag t) */ void EAC_Time::set_to(const std::string& time_str) { - if (time_str == "") + if(time_str == "") { year = month = day = 0; return; @@ -93,28 +93,28 @@ void EAC_Time::set_to(const std::string& time_str) std::vector params; std::string current; - for (u32bit j = 0; j != time_str.size(); ++j) + for(u32bit j = 0; j != time_str.size(); ++j) { - if (Charset::is_digit(time_str[j])) + if(Charset::is_digit(time_str[j])) current += time_str[j]; else { - if (current != "") + if(current != "") params.push_back(current); current.clear(); } } - if (current != "") + if(current != "") params.push_back(current); - if (params.size() != 3) + if(params.size() != 3) throw Invalid_Argument("Invalid time specification " + time_str); year = to_u32bit(params[0]); month = to_u32bit(params[1]); day = to_u32bit(params[2]); - if (!passes_sanity_check()) + if(!passes_sanity_check()) throw Invalid_Argument("Invalid time specification " + time_str); } @@ -133,15 +133,10 @@ void EAC_Time::encode_into(DER_Encoder& der) const */ std::string EAC_Time::as_string() const { - if (time_is_set() == false) + if(time_is_set() == false) throw Invalid_State("EAC_Time::as_string: No time set"); - std::string asn1rep; - asn1rep = to_string(year, 2); - - asn1rep += to_string(month, 2) + to_string(day, 2); - - return asn1rep; + return std::to_string(year * 10000 + month * 100 + day); } /* @@ -157,15 +152,14 @@ bool EAC_Time::time_is_set() const */ std::string EAC_Time::readable_string() const { - if (time_is_set() == false) + if(time_is_set() == false) throw Invalid_State("EAC_Time::readable_string: No time set"); - std::string readable; - readable += to_string(year, 2) + "/"; - readable += to_string(month, 2) + "/"; - readable += to_string(day, 2) + " "; + std::string output(11, 0); + + std::sprintf(&output[0], "%04d/%02d/%02d", year, month, day); - return readable; + return output; } /* @@ -173,11 +167,11 @@ std::string EAC_Time::readable_string() const */ bool EAC_Time::passes_sanity_check() const { - if (year < 2000 || year > 2099) + if(year < 2000 || year > 2099) return false; - if (month == 0 || month > 12) + if(month == 0 || month > 12) return false; - if (day == 0 || day > 31) + if(day == 0 || day > 31) return false; return true; @@ -186,11 +180,11 @@ bool EAC_Time::passes_sanity_check() const /****************************************** * modification functions ******************************************/ - void EAC_Time::add_years(u32bit years) { year += years; } + void EAC_Time::add_months(u32bit months) { year += months/12; @@ -202,23 +196,22 @@ void EAC_Time::add_months(u32bit months) } } - /* * Compare this time against another */ s32bit EAC_Time::cmp(const EAC_Time& other) const { - if (time_is_set() == false) + if(time_is_set() == false) throw Invalid_State("EAC_Time::cmp: No time set"); const s32bit EARLIER = -1, LATER = 1, SAME_TIME = 0; - if (year < other.year) return EARLIER; - if (year > other.year) return LATER; - if (month < other.month) return EARLIER; - if (month > other.month) return LATER; - if (day < other.day) return EARLIER; - if (day > other.day) return LATER; + if(year < other.year) return EARLIER; + if(year > other.year) return LATER; + if(month < other.month) return EARLIER; + if(month > other.month) return LATER; + if(day < other.day) return EARLIER; + if(day > other.day) return LATER; return SAME_TIME; } @@ -230,22 +223,27 @@ bool operator==(const EAC_Time& t1, const EAC_Time& t2) { return (t1.cmp(t2) == 0); } + bool operator!=(const EAC_Time& t1, const EAC_Time& t2) { return (t1.cmp(t2) != 0); } + bool operator<=(const EAC_Time& t1, const EAC_Time& t2) { return (t1.cmp(t2) <= 0); } + bool operator>=(const EAC_Time& t1, const EAC_Time& t2) { return (t1.cmp(t2) >= 0); } + bool operator>(const EAC_Time& t1, const EAC_Time& t2) { return (t1.cmp(t2) > 0); } + bool operator<(const EAC_Time& t1, const EAC_Time& t2) { return (t1.cmp(t2) < 0); diff --git a/src/cert/x509/pkcs10.cpp b/src/cert/x509/pkcs10.cpp index 5617cece4..5645552a0 100644 --- a/src/cert/x509/pkcs10.cpp +++ b/src/cert/x509/pkcs10.cpp @@ -45,7 +45,7 @@ void PKCS10_Request::force_decode() cert_req_info.decode(version); if(version != 0) throw Decoding_Error("Unknown version code in PKCS #10 request: " + - to_string(version)); + std::to_string(version)); X509_DN dn_subject; cert_req_info.decode(dn_subject); diff --git a/src/cert/x509/x509_crl.cpp b/src/cert/x509/x509_crl.cpp index f6a344dba..3613c1a91 100644 --- a/src/cert/x509/x509_crl.cpp +++ b/src/cert/x509/x509_crl.cpp @@ -44,7 +44,7 @@ void X509_CRL::force_decode() if(version != 0 && version != 1) throw X509_CRL_Error("Unknown X.509 CRL version " + - to_string(version+1)); + std::to_string(version+1)); AlgorithmIdentifier sig_algo_inner; tbs_crl.decode(sig_algo_inner); diff --git a/src/cert/x509/x509cert.cpp b/src/cert/x509/x509cert.cpp index 6a062b7ce..32c508a0c 100644 --- a/src/cert/x509/x509cert.cpp +++ b/src/cert/x509/x509cert.cpp @@ -80,7 +80,7 @@ void X509_Certificate::force_decode() .decode(dn_subject); if(version > 2) - throw Decoding_Error("Unknown X.509 cert version " + to_string(version)); + throw Decoding_Error("Unknown X.509 cert version " + std::to_string(version)); if(sig_algo != sig_algo_inner) throw Decoding_Error("Algorithm identifier mismatch"); diff --git a/src/engine/openssl/arc4_openssl.cpp b/src/engine/openssl/arc4_openssl.cpp index 793e1faff..15bb8f98e 100644 --- a/src/engine/openssl/arc4_openssl.cpp +++ b/src/engine/openssl/arc4_openssl.cpp @@ -40,7 +40,7 @@ std::string ARC4_OpenSSL::name() const { if(SKIP == 0) return "ARC4"; if(SKIP == 256) return "MARK-4"; - else return "RC4_skip(" + to_string(SKIP) + ")"; + else return "RC4_skip(" + std::to_string(SKIP) + ")"; } /* diff --git a/src/filters/hex/hex.cpp b/src/filters/hex/hex.cpp index 651899b73..56576a8a0 100644 --- a/src/filters/hex/hex.cpp +++ b/src/filters/hex/hex.cpp @@ -141,7 +141,7 @@ void Hex_Decoder::handle_bad_char(byte c) return; throw Decoding_Error("Hex_Decoder: Invalid hex character: " + - to_string(c)); + std::to_string(c)); } /* diff --git a/src/filters/modes/cfb/cfb.cpp b/src/filters/modes/cfb/cfb.cpp index a126bd995..672dbe7f5 100644 --- a/src/filters/modes/cfb/cfb.cpp +++ b/src/filters/modes/cfb/cfb.cpp @@ -22,7 +22,7 @@ void check_feedback(u32bit BLOCK_SIZE, u32bit FEEDBACK_SIZE, u32bit bits, { if(FEEDBACK_SIZE == 0 || FEEDBACK_SIZE > BLOCK_SIZE || bits % 8 != 0) throw Invalid_Argument(name + ": Invalid feedback size " + - to_string(bits)); + std::to_string(bits)); } } diff --git a/src/filters/modes/eax/eax.cpp b/src/filters/modes/eax/eax.cpp index e2ef178b6..4b712fa90 100644 --- a/src/filters/modes/eax/eax.cpp +++ b/src/filters/modes/eax/eax.cpp @@ -43,7 +43,7 @@ EAX_Base::EAX_Base(BlockCipher* ciph, mac = new CMAC(cipher->clone()); if(tag_size % 8 != 0 || TAG_SIZE == 0 || TAG_SIZE > mac->OUTPUT_LENGTH) - throw Invalid_Argument(name() + ": Bad tag size " + to_string(tag_size)); + throw Invalid_Argument(name() + ": Bad tag size " + std::to_string(tag_size)); state.resize(BLOCK_SIZE); buffer.resize(BLOCK_SIZE); diff --git a/src/filters/pipe.cpp b/src/filters/pipe.cpp index d43868e3f..ae0f6996d 100644 --- a/src/filters/pipe.cpp +++ b/src/filters/pipe.cpp @@ -19,7 +19,7 @@ Pipe::Invalid_Message_Number::Invalid_Message_Number(const std::string& where, message_id msg) { set_msg("Pipe::" + where + ": Invalid message number " + - to_string(msg)); + std::to_string(msg)); } namespace { diff --git a/src/hash/skein/skein_512.cpp b/src/hash/skein/skein_512.cpp index e1ca08c15..5ae09f621 100644 --- a/src/hash/skein/skein_512.cpp +++ b/src/hash/skein/skein_512.cpp @@ -175,7 +175,7 @@ Skein_512::Skein_512(u32bit arg_output_bits, std::string Skein_512::name() const { - return "Skein-512(" + to_string(output_bits) + ")"; + return "Skein-512(" + std::to_string(output_bits) + ")"; } HashFunction* Skein_512::clone() const diff --git a/src/hash/tiger/tiger.cpp b/src/hash/tiger/tiger.cpp index 4f4d4dc83..2d56aa1b3 100644 --- a/src/hash/tiger/tiger.cpp +++ b/src/hash/tiger/tiger.cpp @@ -143,7 +143,7 @@ void Tiger::clear() */ std::string Tiger::name() const { - return "Tiger(" + to_string(OUTPUT_LENGTH) + "," + to_string(PASS) + ")"; + return "Tiger(" + std::to_string(OUTPUT_LENGTH) + "," + std::to_string(PASS) + ")"; } /* @@ -154,10 +154,10 @@ Tiger::Tiger(u32bit hashlen, u32bit pass) : { if(OUTPUT_LENGTH != 16 && OUTPUT_LENGTH != 20 && OUTPUT_LENGTH != 24) throw Invalid_Argument("Tiger: Illegal hash output size: " + - to_string(OUTPUT_LENGTH)); + std::to_string(OUTPUT_LENGTH)); if(PASS < 3) throw Invalid_Argument("Tiger: Invalid number of passes: " - + to_string(PASS)); + + std::to_string(PASS)); clear(); } diff --git a/src/math/numbertheory/dsa_gen.cpp b/src/math/numbertheory/dsa_gen.cpp index d5f6dc792..39a7cf5fa 100644 --- a/src/math/numbertheory/dsa_gen.cpp +++ b/src/math/numbertheory/dsa_gen.cpp @@ -47,15 +47,15 @@ bool generate_dsa_primes(RandomNumberGenerator& rng, if(!fips186_3_valid_size(pbits, qbits)) throw Invalid_Argument( "FIPS 186-3 does not allow DSA domain parameters of " + - to_string(pbits) + "/" + to_string(qbits) + " bits long"); + std::to_string(pbits) + "/" + std::to_string(qbits) + " bits long"); if(seed_c.size() * 8 < qbits) throw Invalid_Argument( - "Generating a DSA parameter set with a " + to_string(qbits) + + "Generating a DSA parameter set with a " + std::to_string(qbits) + "long q requires a seed at least as many bits long"); std::unique_ptr hash( - af.make_hash_function("SHA-" + to_string(qbits))); + af.make_hash_function("SHA-" + std::to_string(qbits))); const u32bit HASH_SIZE = hash->OUTPUT_LENGTH; diff --git a/src/math/numbertheory/make_prm.cpp b/src/math/numbertheory/make_prm.cpp index b136b6d25..3eb01cd42 100644 --- a/src/math/numbertheory/make_prm.cpp +++ b/src/math/numbertheory/make_prm.cpp @@ -20,7 +20,7 @@ BigInt random_prime(RandomNumberGenerator& rng, { if(bits <= 1) throw Invalid_Argument("random_prime: Can't make a prime of " + - to_string(bits) + " bits"); + std::to_string(bits) + " bits"); else if(bits == 2) return ((rng.next_byte() % 2) ? 2 : 3); else if(bits == 3) @@ -85,7 +85,7 @@ BigInt random_safe_prime(RandomNumberGenerator& rng, u32bit bits) { if(bits <= 64) throw Invalid_Argument("random_safe_prime: Can't make a prime of " + - to_string(bits) + " bits"); + std::to_string(bits) + " bits"); BigInt p; do diff --git a/src/pubkey/dl_group/dl_group.cpp b/src/pubkey/dl_group/dl_group.cpp index 13ea03016..1c18179e2 100644 --- a/src/pubkey/dl_group/dl_group.cpp +++ b/src/pubkey/dl_group/dl_group.cpp @@ -46,7 +46,7 @@ DL_Group::DL_Group(RandomNumberGenerator& rng, PrimeType type, u32bit pbits, u32bit qbits) { if(pbits < 512) - throw Invalid_Argument("DL_Group: prime size " + to_string(pbits) + + throw Invalid_Argument("DL_Group: prime size " + std::to_string(pbits) + " is too small"); if(type == Strong) @@ -237,7 +237,7 @@ SecureVector DL_Group::DER_encode(Format format) const .get_contents(); } - throw Invalid_Argument("Unknown DL_Group encoding " + to_string(format)); + throw Invalid_Argument("Unknown DL_Group encoding " + std::to_string(format)); } /* @@ -253,7 +253,7 @@ std::string DL_Group::PEM_encode(Format format) const else if(format == ANSI_X9_42) return PEM_Code::encode(encoding, "X942 DH PARAMETERS"); else - throw Invalid_Argument("Unknown DL_Group encoding " + to_string(format)); + throw Invalid_Argument("Unknown DL_Group encoding " + std::to_string(format)); } /* @@ -287,7 +287,7 @@ void DL_Group::BER_decode(DataSource& source, Format format) .discard_remaining(); } else - throw Invalid_Argument("Unknown DL_Group encoding " + to_string(format)); + throw Invalid_Argument("Unknown DL_Group encoding " + std::to_string(format)); initialize(new_p, new_q, new_g); } diff --git a/src/pubkey/pubkey.cpp b/src/pubkey/pubkey.cpp index 4ddaa6fb6..5a5ca335e 100644 --- a/src/pubkey/pubkey.cpp +++ b/src/pubkey/pubkey.cpp @@ -216,7 +216,7 @@ SecureVector PK_Signer::signature(RandomNumberGenerator& rng) } else throw Encoding_Error("PK_Signer: Unknown signature format " + - to_string(sig_format)); + std::to_string(sig_format)); } /* @@ -328,7 +328,7 @@ bool PK_Verifier::check_signature(const byte sig[], u32bit length) } else throw Decoding_Error("PK_Verifier: Unknown signature format " + - to_string(sig_format)); + std::to_string(sig_format)); } catch(Invalid_Argument) { return false; } catch(Decoding_Error) { return false; } diff --git a/src/pubkey/rsa/rsa.cpp b/src/pubkey/rsa/rsa.cpp index 83e6e1b17..38ea1eeca 100644 --- a/src/pubkey/rsa/rsa.cpp +++ b/src/pubkey/rsa/rsa.cpp @@ -60,7 +60,7 @@ RSA_PrivateKey::RSA_PrivateKey(RandomNumberGenerator& rng, { if(bits < 512) throw Invalid_Argument(algo_name() + ": Can't make a key that is only " + - to_string(bits) + " bits long"); + std::to_string(bits) + " bits long"); if(exp < 3 || exp % 2 == 0) throw Invalid_Argument(algo_name() + ": Invalid encryption exponent"); diff --git a/src/pubkey/rw/rw.cpp b/src/pubkey/rw/rw.cpp index def0ae689..460c740ab 100644 --- a/src/pubkey/rw/rw.cpp +++ b/src/pubkey/rw/rw.cpp @@ -60,7 +60,7 @@ RW_PrivateKey::RW_PrivateKey(RandomNumberGenerator& rng, { if(bits < 512) throw Invalid_Argument(algo_name() + ": Can't make a key that is only " + - to_string(bits) + " bits long"); + std::to_string(bits) + " bits long"); if(exp < 2 || exp % 2 == 1) throw Invalid_Argument(algo_name() + ": Invalid encryption exponent"); diff --git a/src/stream/arc4/arc4.cpp b/src/stream/arc4/arc4.cpp index 293a0a336..5d0c67d3e 100644 --- a/src/stream/arc4/arc4.cpp +++ b/src/stream/arc4/arc4.cpp @@ -81,7 +81,7 @@ std::string ARC4::name() const { if(SKIP == 0) return "ARC4"; if(SKIP == 256) return "MARK-4"; - else return "RC4_skip(" + to_string(SKIP) + ")"; + else return "RC4_skip(" + std::to_string(SKIP) + ")"; } /* diff --git a/src/utils/charset.cpp b/src/utils/charset.cpp index 53125cad1..e98cf601e 100644 --- a/src/utils/charset.cpp +++ b/src/utils/charset.cpp @@ -119,7 +119,7 @@ std::string transcode(const std::string& str, return ucs2_to_latin1(str); throw Invalid_Argument("Unknown transcoding operation from " + - to_string(from) + " to " + to_string(to)); + std::to_string(from) + " to " + std::to_string(to)); } /* diff --git a/src/utils/datastor/datastor.cpp b/src/utils/datastor/datastor.cpp index 5e7c94634..634b72872 100644 --- a/src/utils/datastor/datastor.cpp +++ b/src/utils/datastor/datastor.cpp @@ -124,7 +124,7 @@ void Data_Store::add(const std::string& key, const std::string& val) */ void Data_Store::add(const std::string& key, u32bit val) { - add(key, to_string(val)); + add(key, std::to_string(val)); } /* diff --git a/src/utils/exceptn.cpp b/src/utils/exceptn.cpp index 753d63424..2fa05f59d 100644 --- a/src/utils/exceptn.cpp +++ b/src/utils/exceptn.cpp @@ -15,7 +15,7 @@ namespace Botan { */ Invalid_Key_Length::Invalid_Key_Length(const std::string& name, u32bit length) { - set_msg(name + " cannot accept a key of length " + to_string(length)); + set_msg(name + " cannot accept a key of length " + std::to_string(length)); } /* @@ -32,7 +32,7 @@ Invalid_Block_Size::Invalid_Block_Size(const std::string& mode, */ Invalid_IV_Length::Invalid_IV_Length(const std::string& mode, u32bit bad_len) { - set_msg("IV length " + to_string(bad_len) + " is invalid for " + mode); + set_msg("IV length " + std::to_string(bad_len) + " is invalid for " + mode); } /* @@ -56,7 +56,7 @@ Invalid_Algorithm_Name::Invalid_Algorithm_Name(const std::string& name) */ Config_Error::Config_Error(const std::string& err, u32bit line) { - set_msg("Config error at line " + to_string(line) + ": " + err); + set_msg("Config error at line " + std::to_string(line) + ": " + err); } } diff --git a/src/utils/parsing.cpp b/src/utils/parsing.cpp index 63dfce64f..3412cf02b 100644 --- a/src/utils/parsing.cpp +++ b/src/utils/parsing.cpp @@ -12,53 +12,6 @@ namespace Botan { -/* -* Convert a string into an integer -*/ -u32bit to_u32bit(const std::string& number) - { - u32bit n = 0; - - for(auto i = number.begin(); i != number.end(); ++i) - { - const u32bit OVERFLOW_MARK = 0xFFFFFFFF / 10; - - if(*i == ' ') - continue; - - byte digit = Charset::char2digit(*i); - - if((n > OVERFLOW_MARK) || (n == OVERFLOW_MARK && digit > 5)) - throw Decoding_Error("to_u32bit: Integer overflow"); - n *= 10; - n += digit; - } - return n; - } - -/* -* Convert an integer into a string -*/ -std::string to_string(u64bit n, u32bit min_len) - { - std::string lenstr; - if(n) - { - while(n > 0) - { - lenstr = Charset::digit2char(n % 10) + lenstr; - n /= 10; - } - } - else - lenstr = "0"; - - while(lenstr.size() < min_len) - lenstr = "0" + lenstr; - - return lenstr; - } - /* * Convert a string into a time duration */ @@ -282,7 +235,7 @@ std::string ipv4_to_string(u32bit ip) { if(i) str += "."; - str += to_string(get_byte(i, ip)); + str += std::to_string(get_byte(i, ip)); } return str; diff --git a/src/utils/parsing.h b/src/utils/parsing.h index 2c29d5b4d..cb8d61cee 100644 --- a/src/utils/parsing.h +++ b/src/utils/parsing.h @@ -23,10 +23,10 @@ BOTAN_DLL std::vector parse_asn1_oid(const std::string&); BOTAN_DLL bool x500_name_cmp(const std::string&, const std::string&); /* -* String/Integer Conversions +* Convert a string into an integer */ -BOTAN_DLL std::string to_string(u64bit, u32bit = 0); -BOTAN_DLL u32bit to_u32bit(const std::string&); +inline u32bit to_u32bit(const std::string& number) + { return stoul(number); } BOTAN_DLL u32bit timespec_to_u32bit(const std::string& timespec); diff --git a/src/utils/version.cpp b/src/utils/version.cpp index d540864b2..ef591b4d7 100644 --- a/src/utils/version.cpp +++ b/src/utils/version.cpp @@ -21,9 +21,9 @@ namespace Botan { */ std::string version_string() { - return to_string(version_major()) + "." + - to_string(version_minor()) + "." + - to_string(version_patch()); + return std::to_string(version_major()) + "." + + std::to_string(version_minor()) + "." + + std::to_string(version_patch()); } /* -- cgit v1.2.3 From 2af8cfbaf23033250a6819be9f45f82bf03e898d Mon Sep 17 00:00:00 2001 From: lloyd Date: Thu, 19 Nov 2009 17:20:46 +0000 Subject: Drop support for compilers that are no longer in active service, since there is no chance that C++0x support will be added to them at any point. --- src/build-data/cc/compaq.txt | 29 ----------------------------- src/build-data/cc/kai.txt | 30 ------------------------------ src/build-data/cc/mipspro.txt | 42 ------------------------------------------ src/build-data/cc/sgipro64.txt | 30 ------------------------------ 4 files changed, 131 deletions(-) delete mode 100644 src/build-data/cc/compaq.txt delete mode 100644 src/build-data/cc/kai.txt delete mode 100644 src/build-data/cc/mipspro.txt delete mode 100644 src/build-data/cc/sgipro64.txt (limited to 'src') diff --git a/src/build-data/cc/compaq.txt b/src/build-data/cc/compaq.txt deleted file mode 100644 index 9ad6514ab..000000000 --- a/src/build-data/cc/compaq.txt +++ /dev/null @@ -1,29 +0,0 @@ -macro_name "COMPAQ" - -binary_name "cxx" - -compile_option "-c " -output_to_option "-o " -add_include_dir_option "-I" -add_lib_dir_option "-L" -add_lib_option "-l" - -# -O3 and up seem to be unhappy with Botan -lib_opt_flags "-O2" -check_opt_flags "-O2" -debug_flags "-g" -no_debug_flags "" -lang_flags "-std ansi -D__USE_STD_IOSTREAM" - -dll_import_flags "" -dll_export_flags "" - -makefile_style unix - - -default -> "$(CXX) -shared -soname $(SONAME)" - - - -alpha -> "-arch=SUBMODEL" alpha- - diff --git a/src/build-data/cc/kai.txt b/src/build-data/cc/kai.txt deleted file mode 100644 index d0ff1c28a..000000000 --- a/src/build-data/cc/kai.txt +++ /dev/null @@ -1,30 +0,0 @@ -macro_name "KAI" - -binary_name "KCC" - -compile_option "-c " -output_to_option "-o " -add_include_dir_option "-I" -add_lib_dir_option "-L" -add_lib_option "-l" - -ar_command "KCC -o" - -lib_opt_flags "+K3 --inline_auto_space_time=65 --abstract_pointer" -check_opt_flags "+K3" -lang_flags "-D__KAI_STRICT" -debug_flags "-g" -no_debug_flags "" - -dll_import_flags "" -dll_export_flags "" - -makefile_style unix - - -default -> "$(CXX) --soname $(SONAME)" - - - -all -> "--one_per" - diff --git a/src/build-data/cc/mipspro.txt b/src/build-data/cc/mipspro.txt deleted file mode 100644 index c518f4c26..000000000 --- a/src/build-data/cc/mipspro.txt +++ /dev/null @@ -1,42 +0,0 @@ -macro_name "MIPSPRO" - -binary_name "CC" - -compile_option "-c " -output_to_option "-o " -add_include_dir_option "-I" -add_lib_dir_option "-L" -add_lib_option "-l" - -lib_opt_flags "-O3 -OPT:alias=TYPED" -check_opt_flags "-O3 -OPT:alias=TYPED" -debug_flags "-g3" -no_debug_flags "" -shared_flags "-KPIC" -lang_flags "-ansi -LANG:ansi-for-init-scope=ON" -# Disabled, because, while my code is fine, it warns about a lot of it's own -# headers -#warning_flags "-fullwarn" - -dll_import_flags "" -dll_export_flags "" - -makefile_style unix - - -default -> "$(CXX) -shared -Wl,-soname,$(SONAME)" - - - -mips32 -> "-mips1" -mips64 -> "-mips3" - -mips64-r5000 -> "-mips4 -r5000" -mips64-r8000 -> "-mips4 -r8000" -mips64-r10000 -> "-mips4 -r10000" - - - -mips32 -> "-n32" -mips64 -> "-64" - diff --git a/src/build-data/cc/sgipro64.txt b/src/build-data/cc/sgipro64.txt deleted file mode 100644 index 073f2fec0..000000000 --- a/src/build-data/cc/sgipro64.txt +++ /dev/null @@ -1,30 +0,0 @@ -macro_name "SGI_PRO64" - -binary_name "sgiCC" - -compile_option "-c " -output_to_option "-o " -add_include_dir_option "-I" -add_lib_dir_option "-L" -add_lib_option "-l" - -lib_opt_flags "-O3 -OPT:alias=TYPED" -check_opt_flags "-O3 -OPT:alias=TYPED" -debug_flags "-g3" -no_debug_flags "" -shared_flags "-KPIC" -lang_flags "-ansi -LANG:ansi-for-init-scope=ON" -warning_flags "-Wall -W" - -dll_import_flags "" -dll_export_flags "" - -makefile_style unix - - -default -> "$(CXX) -shared -Wl,-soname,$(SONAME)" - - - - - -- cgit v1.2.3 From 2ffa6f3f1616d7db3503600ac047a10b01a6bb54 Mon Sep 17 00:00:00 2001 From: lloyd Date: Thu, 19 Nov 2009 18:03:17 +0000 Subject: Add move assignment and constructor operators to BigInt. On macro benchmarks (timing the test suite) there doesn't seem to be much of a difference either way, but putting printfs in the implementations shows they are being used. Since they pretty much can't possibly hurt (right?) and might well help a lot in certain cases, it's worth including. Todo: adding overloads to binary operators taking move operations might be nice. Details in http://cpp-next.com/archive/2009/09/making-your-next-move/ --- src/math/bigint/bigint.cpp | 25 ++++++++++++++++++++++++- src/math/bigint/bigint.h | 19 ++++++++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/math/bigint/bigint.cpp b/src/math/bigint/bigint.cpp index 7592ec439..36739f047 100644 --- a/src/math/bigint/bigint.cpp +++ b/src/math/bigint/bigint.cpp @@ -40,7 +40,7 @@ BigInt::BigInt(Sign s, u32bit size) } /* -* Construct a BigInt from a "raw" BigInt +* Copy constructor */ BigInt::BigInt(const BigInt& b) { @@ -100,6 +100,29 @@ BigInt::BigInt(RandomNumberGenerator& rng, u32bit bits) randomize(rng, bits); } +/** +* Move constructor +*/ +BigInt::BigInt(BigInt&& other) + { + reg.swap(other.reg); + signedness = other.signedness; + } + +/** +* Move assignment +*/ +BigInt& BigInt::operator=(BigInt&& other) + { + if(this != &other) + { + reg.swap(other.reg); + signedness = other.signedness; + } + + return (*this); + } + /* * Swap this BigInt with another */ diff --git a/src/math/bigint/bigint.h b/src/math/bigint/bigint.h index 4f7f6f5bd..3db9a1a04 100644 --- a/src/math/bigint/bigint.h +++ b/src/math/bigint/bigint.h @@ -425,10 +425,14 @@ class BOTAN_DLL BigInt BigInt(u64bit n); /** - * Copy-Constructor: clone given BigInt - * @param bigint the BigInt to clone + * Copy constructor */ - BigInt(const BigInt& bigint); + BigInt(const BigInt& other); + + /** + * Assignment operator + */ + BigInt& operator=(const BigInt&) = default; /** * Create BigInt from a string. @@ -471,6 +475,15 @@ class BOTAN_DLL BigInt */ BigInt(NumberType type, u32bit n); + /** + * Move constructor + */ + BigInt(BigInt&& other); + + /** + * Move assignment + */ + BigInt& operator=(BigInt&& other); private: SecureVector reg; Sign signedness; -- cgit v1.2.3 From bab01ef1514266e6f23d9163e503c115147ab993 Mon Sep 17 00:00:00 2001 From: lloyd Date: Thu, 19 Nov 2009 18:12:32 +0000 Subject: Define move assignment and constructors in terms of std::swap (which boils down to BigInt::swap, which uses the memvec swap). Checking with g++ 4.5 -O3 shows it compiles down the same code as before. --- src/math/bigint/bigint.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/math/bigint/bigint.cpp b/src/math/bigint/bigint.cpp index 36739f047..c777e770b 100644 --- a/src/math/bigint/bigint.cpp +++ b/src/math/bigint/bigint.cpp @@ -105,8 +105,7 @@ BigInt::BigInt(RandomNumberGenerator& rng, u32bit bits) */ BigInt::BigInt(BigInt&& other) { - reg.swap(other.reg); - signedness = other.signedness; + std::swap(*this, other); } /** @@ -115,10 +114,7 @@ BigInt::BigInt(BigInt&& other) BigInt& BigInt::operator=(BigInt&& other) { if(this != &other) - { - reg.swap(other.reg); - signedness = other.signedness; - } + std::swap(*this, other); return (*this); } -- cgit v1.2.3 From 51cb1979c0533c52f4548d37fb00fbdc6775bba6 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 1 Dec 2009 12:02:52 +0000 Subject: Drop utils/time.h to deal with a merge conflict. --- src/utils/time.h | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 src/utils/time.h (limited to 'src') diff --git a/src/utils/time.h b/src/utils/time.h deleted file mode 100644 index 3052aec44..000000000 --- a/src/utils/time.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -* Time Functions -* (C) 2009 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_TIME_OPS_H__ -#define BOTAN_TIME_OPS_H__ - -#include - -namespace Botan { - -/* -* Convert a time_t value to a struct tm -*/ -inline std::tm time_t_to_tm(u64bit time_int) - { - std::time_t time_val = static_cast(time_int); - - 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); - } - -/** -* Get the system clock -*/ -inline u64bit system_time() - { - return static_cast(std::time(0)); - } - -} - - -#endif -- cgit v1.2.3 From fe0276ee115bb367810ac2e06833fed297eb1715 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 1 Dec 2009 13:28:16 +0000 Subject: Remove system_time(), replace entirely with std::chrono. Only remaining use of time.h/ctime is to convert from a time point to a calendar value, which still requires C's gmtime. Hide it entirely in time.cpp and return a calendar_point struct instead of a std::tm. --- checks/cvc_tests.cpp | 3 +- src/asn1/asn1_obj.h | 3 +- src/asn1/asn1_tm.cpp | 20 +++++++------- src/cert/cvc/asn1_eac_tm.cpp | 53 ++++++------------------------------ src/cert/cvc/cvc_self.cpp | 18 ++++++------ src/cert/cvc/eac_asn_obj.h | 65 +++++++++++++++++++++----------------------- src/cert/x509/crl_ent.cpp | 3 +- src/cert/x509/x509_ca.cpp | 6 ++-- src/cert/x509/x509opt.cpp | 6 ++-- src/cert/x509/x509stor.cpp | 24 +++++++++------- src/cert/x509/x509stor.h | 2 +- src/utils/time.cpp | 27 ++++++++++-------- src/utils/time.h | 22 +++++++++++---- 13 files changed, 116 insertions(+), 136 deletions(-) (limited to 'src') diff --git a/checks/cvc_tests.cpp b/checks/cvc_tests.cpp index 4b2ffa9a6..7904a2700 100644 --- a/checks/cvc_tests.cpp +++ b/checks/cvc_tests.cpp @@ -350,8 +350,7 @@ void test_eac_time(RandomNumberGenerator&) { std::cout << "." << std::flush; - const u64bit current_time = system_time(); - EAC_Time time(current_time); + EAC_Time time(std::chrono::system_clock::now()); // std::cout << "time as std::string = " << time.as_string() << std::endl; EAC_Time sooner("", ASN1_Tag(99)); //X509_Time sooner("", ASN1_Tag(99)); diff --git a/src/asn1/asn1_obj.h b/src/asn1/asn1_obj.h index ea21c475f..a640f712b 100644 --- a/src/asn1/asn1_obj.h +++ b/src/asn1/asn1_obj.h @@ -14,6 +14,7 @@ #include #include #include +#include namespace Botan { @@ -52,7 +53,7 @@ class BOTAN_DLL X509_Time : public ASN1_Object void set_to(const std::string&); void set_to(const std::string&, ASN1_Tag); - X509_Time(u64bit); + X509_Time(const std::chrono::system_clock::time_point& time); X509_Time(const std::string& = ""); X509_Time(const std::string&, ASN1_Tag); private: diff --git a/src/asn1/asn1_tm.cpp b/src/asn1/asn1_tm.cpp index 9df10f4a3..6e56bb8d1 100644 --- a/src/asn1/asn1_tm.cpp +++ b/src/asn1/asn1_tm.cpp @@ -23,18 +23,18 @@ X509_Time::X509_Time(const std::string& time_str) } /* -* Create an X509_Time +* Create a X509_Time from a time point */ -X509_Time::X509_Time(u64bit timer) +X509_Time::X509_Time(const std::chrono::system_clock::time_point& time) { - std::tm time_info = time_t_to_tm(timer); - - year = time_info.tm_year + 1900; - month = time_info.tm_mon + 1; - day = time_info.tm_mday; - hour = time_info.tm_hour; - minute = time_info.tm_min; - second = time_info.tm_sec; + calendar_point cal = calendar_value(time); + + year = cal.year; + month = cal.month; + day = cal.day; + hour = cal.hour; + minute = cal.minutes; + second = cal.seconds; if(year >= 2050) tag = GENERALIZED_TIME; diff --git a/src/cert/cvc/asn1_eac_tm.cpp b/src/cert/cvc/asn1_eac_tm.cpp index b0238ac4d..827710084 100644 --- a/src/cert/cvc/asn1_eac_tm.cpp +++ b/src/cert/cvc/asn1_eac_tm.cpp @@ -50,24 +50,24 @@ u32bit dec_two_digit(byte b1, byte b2) /* * Create an EAC_Time */ -EAC_Time::EAC_Time(u64bit timer, ASN1_Tag t) - :tag(t) +EAC_Time::EAC_Time(const std::chrono::system_clock::time_point& time, + ASN1_Tag t) : tag(t) { - std::tm time_info = time_t_to_tm(timer); + calendar_point cal = calendar_value(time); - year = time_info.tm_year + 1900; - month = time_info.tm_mon + 1; - day = time_info.tm_mday; + year = cal.year; + month = cal.month; + day = cal.day; } /* * Create an EAC_Time */ -EAC_Time::EAC_Time(const std::string& t_spec, ASN1_Tag t) - :tag(t) +EAC_Time::EAC_Time(const std::string& t_spec, ASN1_Tag t) : tag(t) { set_to(t_spec); } + /* * Create an EAC_Time */ @@ -280,19 +280,6 @@ void EAC_Time::decode_from(BER_Decoder& source) } -u32bit EAC_Time::get_year() const - { - return year; - } -u32bit EAC_Time::get_month() const - { - return month; - } -u32bit EAC_Time::get_day() const - { - return day; - } - /* * make the value an octet string for encoding */ @@ -305,28 +292,4 @@ SecureVector EAC_Time::encoded_eac_time() const return result; } -ASN1_Ced::ASN1_Ced(std::string const& str) - : EAC_Time(str, ASN1_Tag(37)) - {} - -ASN1_Ced::ASN1_Ced(u64bit val) - : EAC_Time(val, ASN1_Tag(37)) - {} - -ASN1_Ced::ASN1_Ced(EAC_Time const& other) - : EAC_Time(other.get_year(), other.get_month(), other.get_day(), ASN1_Tag(37)) - {} - -ASN1_Cex::ASN1_Cex(std::string const& str) - : EAC_Time(str, ASN1_Tag(36)) - {} - -ASN1_Cex::ASN1_Cex(u64bit val) - : EAC_Time(val, ASN1_Tag(36)) - {} - -ASN1_Cex::ASN1_Cex(EAC_Time const& other) - : EAC_Time(other.get_year(), other.get_month(), other.get_day(), ASN1_Tag(36)) - {} - } diff --git a/src/cert/cvc/cvc_self.cpp b/src/cert/cvc/cvc_self.cpp index 98d90d0af..3b764644f 100644 --- a/src/cert/cvc/cvc_self.cpp +++ b/src/cert/cvc/cvc_self.cpp @@ -181,9 +181,8 @@ EAC1_1_CVC create_cvca(Private_Key const& key, } EAC1_1_CVC_Options opts; opts.car = car; - const u64bit current_time = system_time(); - opts.ced = ASN1_Ced(current_time); + opts.ced = ASN1_Ced(std::chrono::system_clock::now()); opts.cex = ASN1_Cex(opts.ced); opts.cex.add_months(cvca_validity_months); opts.holder_auth_templ = (CVCA | (iris * IRIS) | (fingerpr * FINGERPRINT)); @@ -198,12 +197,12 @@ EAC1_1_CVC link_cvca(EAC1_1_CVC const& signer, EAC1_1_CVC const& signee, RandomNumberGenerator& rng) { - ECDSA_PrivateKey const* priv_key = dynamic_cast(&key); + const ECDSA_PrivateKey* priv_key = dynamic_cast(&key); + if (priv_key == 0) - { - throw Invalid_Argument("CVC_EAC::create_self_signed_cert(): unsupported key type"); - } - ASN1_Ced ced(system_time()); + throw Invalid_Argument("link_cvca(): unsupported key type"); + + ASN1_Ced ced(std::chrono::system_clock::now()); ASN1_Cex cex(signee.get_cex()); if (*static_cast(&ced) > *static_cast(&cex)) { @@ -278,8 +277,9 @@ EAC1_1_CVC sign_request(EAC1_1_CVC const& signer_cert, #endif AlgorithmIdentifier sig_algo(signer_cert.signature_algorithm()); - const u64bit current_time = system_time(); - ASN1_Ced ced(current_time); + + ASN1_Ced ced(std::chrono::system_clock::now()); + u32bit chat_val; u32bit chat_low = signer_cert.get_chat_value() & 0x3; // take the chat rights from signer ASN1_Cex cex(ced); diff --git a/src/cert/cvc/eac_asn_obj.h b/src/cert/cvc/eac_asn_obj.h index 3e70f6b74..a6685a8ed 100644 --- a/src/cert/cvc/eac_asn_obj.h +++ b/src/cert/cvc/eac_asn_obj.h @@ -1,7 +1,7 @@ /* * EAC ASN.1 Objects * (C) 2007-2008 FlexSecure GmbH -* 2008 Jack Lloyd +* 2008-2009 Jack Lloyd * * Distributed under the terms of the Botan license */ @@ -12,6 +12,7 @@ #include #include #include +#include namespace Botan { @@ -58,7 +59,6 @@ class BOTAN_DLL EAC_Time : public ASN1_Object * e.g. "2007 08 01" */ void set_to(const std::string& str); - //void set_to(const std::string&, ASN1_Tag); /** * Add the specified number of years to this. @@ -76,24 +76,28 @@ class BOTAN_DLL EAC_Time : public ASN1_Object * Get the year value of this objects. * @return the year value */ - u32bit get_year() const; + u32bit get_year() const { return year; } /** * Get the month value of this objects. * @return the month value */ - u32bit get_month() const; + u32bit get_month() const { return month; } /** * Get the day value of this objects. * @return the day value */ - u32bit get_day() const; + u32bit get_day() const { return day; } - EAC_Time(u64bit, ASN1_Tag t = ASN1_Tag(0)); - //EAC_Time(const std::string& = ""); - EAC_Time(const std::string&, ASN1_Tag = ASN1_Tag(0)); - EAC_Time(u32bit year, u32bit month, u32bit day, ASN1_Tag = ASN1_Tag(0)); + EAC_Time(const std::chrono::system_clock::time_point& time, + ASN1_Tag tag = ASN1_Tag(0)); + + EAC_Time(const std::string& yyyy_mm_dd, + ASN1_Tag tag = ASN1_Tag(0)); + + EAC_Time(u32bit year, u32bit month, u32bit day, + ASN1_Tag tag = ASN1_Tag(0)); virtual ~EAC_Time() {} private: @@ -115,25 +119,25 @@ class BOTAN_DLL ASN1_Ced : public EAC_Time * @param str a string in the format "yyyy mm dd", * e.g. "2007 08 01" */ - ASN1_Ced(std::string const& str = ""); + ASN1_Ced(std::string const& str = "") : + EAC_Time(str, ASN1_Tag(37)) {} /** - * Construct a CED from a timer value. - * @param time the number of seconds elapsed midnight, 1st - * January 1970 GMT (or 7pm, 31st December 1969 EST) up to the - * desired date + * Construct a CED from a time point */ - ASN1_Ced(u64bit time); + ASN1_Ced(const std::chrono::system_clock::time_point& time) : + EAC_Time(time, ASN1_Tag(37)) {} /** * Copy constructor (for general EAC_Time objects). * @param other the object to copy from */ - ASN1_Ced(EAC_Time const& other); - //ASN1_Ced(ASN1_Cex const& cex); + ASN1_Ced(EAC_Time const& other) : + EAC_Time(other.get_year(), other.get_month(), other.get_day(), + ASN1_Tag(37)) + {} }; - /** * This class represents CVC CEXs. Only limited sanity checks of * the inputted date value are performed. @@ -142,27 +146,20 @@ class BOTAN_DLL ASN1_Cex : public EAC_Time { public: /** - * Construct a CED from a string value. + * Construct a CEX from a string value. * @param str a string in the format "yyyy mm dd", * e.g. "2007 08 01" */ - ASN1_Cex(std::string const& str=""); + ASN1_Cex(std::string const& str = "") : + EAC_Time(str, ASN1_Tag(36)) {} - /** - * Construct a CED from a timer value. - * @param time the number of seconds elapsed - * midnight, 1st - * January 1970 GMT (or 7pm, 31st December 1969 EST) - * up to the desired date - */ - ASN1_Cex(u64bit time); + ASN1_Cex(const std::chrono::system_clock::time_point& time) : + EAC_Time(time, ASN1_Tag(36)) {} - /** - * Copy constructor (for general EAC_Time objects). - * @param other the object to copy from - */ - ASN1_Cex(EAC_Time const& other); - //ASN1_Cex(ASN1_Ced const& ced); + ASN1_Cex(EAC_Time const& other) : + EAC_Time(other.get_year(), other.get_month(), other.get_day(), + ASN1_Tag(36)) + {} }; /** diff --git a/src/cert/x509/crl_ent.cpp b/src/cert/x509/crl_ent.cpp index 42a742ebb..e7ce1a57a 100644 --- a/src/cert/x509/crl_ent.cpp +++ b/src/cert/x509/crl_ent.cpp @@ -11,7 +11,6 @@ #include #include #include -#include namespace Botan { @@ -31,7 +30,7 @@ CRL_Entry::CRL_Entry(const X509_Certificate& cert, CRL_Code why) : throw_on_unknown_critical(false) { serial = cert.serial_number(); - time = X509_Time(system_time()); + time = X509_Time(std::chrono::system_clock::now()); reason = why; } diff --git a/src/cert/x509/x509_ca.cpp b/src/cert/x509/x509_ca.cpp index 80e808177..59a5bbaf8 100644 --- a/src/cert/x509/x509_ca.cpp +++ b/src/cert/x509/x509_ca.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include @@ -197,7 +196,8 @@ X509_CRL X509_CA::make_crl(const std::vector& revoked, next_update = timespec_to_u32bit("7d"); // Totally stupid: ties encoding logic to the return of std::time!! - const u64bit current_time = system_time(); + auto current_time = std::chrono::system_clock::now(); + auto expire_time = current_time + std::chrono::seconds(next_update); Extensions extensions; extensions.add( @@ -210,7 +210,7 @@ X509_CRL X509_CA::make_crl(const std::vector& revoked, .encode(ca_sig_algo) .encode(cert.issuer_dn()) .encode(X509_Time(current_time)) - .encode(X509_Time(current_time + next_update)) + .encode(X509_Time(expire_time)) .encode_if(revoked.size() > 0, DER_Encoder() .start_cons(SEQUENCE) diff --git a/src/cert/x509/x509opt.cpp b/src/cert/x509/x509opt.cpp index c6421d9ca..a2547e30a 100644 --- a/src/cert/x509/x509opt.cpp +++ b/src/cert/x509/x509opt.cpp @@ -78,16 +78,16 @@ void X509_Cert_Options::sanity_check() const * Initialize the certificate options */ X509_Cert_Options::X509_Cert_Options(const std::string& initial_opts, - u32bit expiration_time_in_seconds) + u32bit expiration_time) { is_CA = false; path_limit = 0; constraints = NO_CONSTRAINTS; - const u32bit now = system_time(); + auto now = std::chrono::system_clock::now(); start = X509_Time(now); - end = X509_Time(now + expiration_time_in_seconds); + end = X509_Time(now + std::chrono::seconds(expiration_time)); if(initial_opts == "") return; diff --git a/src/cert/x509/x509stor.cpp b/src/cert/x509/x509stor.cpp index 323890f2d..336d155d3 100644 --- a/src/cert/x509/x509stor.cpp +++ b/src/cert/x509/x509stor.cpp @@ -22,13 +22,14 @@ namespace { * Do a validity check */ s32bit validity_check(const X509_Time& start, const X509_Time& end, - u64bit current_time, u32bit slack) + const std::chrono::system_clock::time_point& now, + u32bit slack) { const s32bit NOT_YET_VALID = -1, VALID_TIME = 0, EXPIRED = 1; - if(start.cmp(current_time + slack) > 0) + if(start.cmp(now + std::chrono::seconds(slack)) > 0) return NOT_YET_VALID; - if(end.cmp(current_time - slack) < 0) + if(end.cmp(now - std::chrono::seconds(slack)) < 0) return EXPIRED; return VALID_TIME; } @@ -212,10 +213,11 @@ X509_Code X509_Store::validate_cert(const X509_Certificate& cert, if(chaining_result != VERIFIED) return chaining_result; - const u64bit current_time = system_time(); + auto current_time = std::chrono::system_clock::now(); s32bit time_check = validity_check(cert.start_time(), cert.end_time(), current_time, time_slack); + if(time_check < 0) return CERT_NOT_YET_VALID; else if(time_check > 0) return CERT_HAS_EXPIRED; @@ -563,8 +565,10 @@ void X509_Store::add_trusted_certs(DataSource& source) */ X509_Code X509_Store::add_crl(const X509_CRL& crl) { + auto current_time = std::chrono::system_clock::now(); + s32bit time_check = validity_check(crl.this_update(), crl.next_update(), - system_time(), time_slack); + current_time, time_slack); if(time_check < 0) return CRL_NOT_YET_VALID; else if(time_check > 0) return CRL_HAS_EXPIRED; @@ -641,8 +645,8 @@ X509_Store::Cert_Info::Cert_Info(const X509_Certificate& c, bool t) : cert(c), trusted(t) { checked = false; + last_checked = std::chrono::system_clock::time_point::min(); result = UNKNOWN_X509_ERROR; - last_checked = 0; } /* @@ -660,9 +664,9 @@ X509_Code X509_Store::Cert_Info::verify_result() const */ void X509_Store::Cert_Info::set_result(X509_Code code) const { - result = code; - last_checked = system_time(); checked = true; + last_checked = std::chrono::system_clock::now(); + result = code; } /* @@ -683,9 +687,9 @@ bool X509_Store::Cert_Info::is_verified(u32bit timeout) const if(result != VERIFIED && result != CERT_NOT_YET_VALID) return true; - const u64bit current_time = system_time(); + auto now = std::chrono::system_clock::now(); - if(current_time > last_checked + timeout) + if(now > last_checked + std::chrono::seconds(timeout)) checked = false; return checked; diff --git a/src/cert/x509/x509stor.h b/src/cert/x509/x509stor.h index 958b6da0f..e55e36e7e 100644 --- a/src/cert/x509/x509stor.h +++ b/src/cert/x509/x509stor.h @@ -116,7 +116,7 @@ class BOTAN_DLL X509_Store private: mutable bool checked; mutable X509_Code result; - mutable u64bit last_checked; + mutable std::chrono::system_clock::time_point last_checked; }; u32bit find_cert(const X509_DN&, const MemoryRegion&) const; diff --git a/src/utils/time.cpp b/src/utils/time.cpp index 856b1c7be..1c64c820e 100644 --- a/src/utils/time.cpp +++ b/src/utils/time.cpp @@ -45,25 +45,30 @@ u64bit combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz) } -/** -* Get the system clock -*/ -u64bit system_time() - { - return static_cast(std::time(0)); - } - /* * Convert a time_t to a struct tm */ -std::tm time_t_to_tm(u64bit timer) +calendar_point calendar_value( + const std::chrono::system_clock::time_point& time_point) { - std::time_t time_val = static_cast(timer); + time_t time_val = std::chrono::system_clock::to_time_t(time_point); + + // Race condition: std::gmtime is not assured thread safe, + // and C++ does not include gmtime_r. Use a mutex here? 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); + + std::tm tm = *tm_p; + // Race is over here + + return calendar_point(tm.tm_year + 1900, + tm.tm_mon + 1, + tm.tm_mday, + tm.tm_hour, + tm.tm_min, + tm.tm_sec); } u64bit get_nanoseconds_clock() diff --git a/src/utils/time.h b/src/utils/time.h index c7f459096..28b777efe 100644 --- a/src/utils/time.h +++ b/src/utils/time.h @@ -9,16 +9,28 @@ #define BOTAN_TIME_H__ #include -#include +#include namespace Botan { /* -* Time Access/Conversion Functions +* Time Conversion Functions */ -BOTAN_DLL u64bit system_time(); - -BOTAN_DLL std::tm time_t_to_tm(u64bit); +struct BOTAN_DLL calendar_point + { + u32bit year; + byte month; + byte day; + byte hour; + byte minutes; + byte seconds; + + calendar_point(u32bit y, byte mon, byte d, byte h, byte min, byte sec) : + year(y), month(mon), day(d), hour(h), minutes(min), seconds(sec) {} + }; + +BOTAN_DLL calendar_point calendar_value( + const std::chrono::system_clock::time_point& time_point); /** @return nanoseconds resolution timestamp, unknown epoch -- cgit v1.2.3 From f3c149bce5b5ddb527a072c2f34daaa993cdba94 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 1 Dec 2009 14:58:22 +0000 Subject: Use std::chrono::duration instead of untyped u32bit values for times in X509_Store --- src/cert/x509/x509stor.cpp | 13 +++++++------ src/cert/x509/x509stor.h | 14 ++++++++++---- 2 files changed, 17 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/cert/x509/x509stor.cpp b/src/cert/x509/x509stor.cpp index 336d155d3..a055602a8 100644 --- a/src/cert/x509/x509stor.cpp +++ b/src/cert/x509/x509stor.cpp @@ -23,13 +23,13 @@ namespace { */ s32bit validity_check(const X509_Time& start, const X509_Time& end, const std::chrono::system_clock::time_point& now, - u32bit slack) + std::chrono::seconds slack) { const s32bit NOT_YET_VALID = -1, VALID_TIME = 0, EXPIRED = 1; - if(start.cmp(now + std::chrono::seconds(slack)) > 0) + if(start.cmp(now + slack) > 0) return NOT_YET_VALID; - if(end.cmp(now - std::chrono::seconds(slack)) < 0) + if(end.cmp(now - slack) < 0) return EXPIRED; return VALID_TIME; } @@ -170,7 +170,8 @@ bool X509_Store::CRL_Data::operator<(const X509_Store::CRL_Data& other) const /* * X509_Store Constructor */ -X509_Store::X509_Store(u32bit slack, u32bit cache_timeout) +X509_Store::X509_Store(std::chrono::seconds slack, + std::chrono::seconds cache_timeout) { revoked_info_valid = true; @@ -680,7 +681,7 @@ bool X509_Store::Cert_Info::is_trusted() const /* * Check if this certificate has been verified */ -bool X509_Store::Cert_Info::is_verified(u32bit timeout) const +bool X509_Store::Cert_Info::is_verified(std::chrono::seconds timeout) const { if(!checked) return false; @@ -689,7 +690,7 @@ bool X509_Store::Cert_Info::is_verified(u32bit timeout) const auto now = std::chrono::system_clock::now(); - if(now > last_checked + std::chrono::seconds(timeout)) + if(now > last_checked + timeout) checked = false; return checked; diff --git a/src/cert/x509/x509stor.h b/src/cert/x509/x509stor.h index e55e36e7e..1911c6b6a 100644 --- a/src/cert/x509/x509stor.h +++ b/src/cert/x509/x509stor.h @@ -96,8 +96,12 @@ class BOTAN_DLL X509_Store X509_Store& operator=(const X509_Store&) = delete; - X509_Store(u32bit time_slack = 24*60*60, - u32bit cache_results = 30*60); + /** + * @param slack the slack in checking validity times against current clock + * @param cache how long to cache validation results before rechecking + */ + X509_Store(std::chrono::seconds slack = std::chrono::seconds(24*60*60), + std::chrono::seconds cache = std::chrono::seconds(30*60)); X509_Store(const X509_Store&); ~X509_Store(); @@ -105,7 +109,7 @@ class BOTAN_DLL X509_Store class BOTAN_DLL Cert_Info { public: - bool is_verified(u32bit timeout) const; + bool is_verified(std::chrono::seconds cache_timeout) const; bool is_trusted() const; X509_Code verify_result() const; void set_result(X509_Code) const; @@ -131,10 +135,12 @@ class BOTAN_DLL X509_Store bool is_revoked(const X509_Certificate&) const; static const u32bit NO_CERT_FOUND = 0xFFFFFFFF; + std::vector certs; std::vector revoked; std::vector stores; - u32bit time_slack, validation_cache_timeout; + + std::chrono::seconds time_slack, validation_cache_timeout; mutable bool revoked_info_valid; }; -- cgit v1.2.3 From 29e9b23500d101f01988a33e8f1a6aaab39d5f7d Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 1 Dec 2009 15:36:30 +0000 Subject: Most files including actually just needed Clean up implementation of calendar_value() a bit --- doc/examples/ca.cpp | 2 +- doc/examples/gen_certs.cpp | 2 +- src/cert/cvc/cvc_self.cpp | 2 +- src/cert/x509/x509opt.cpp | 2 +- src/cert/x509/x509stor.cpp | 2 +- src/entropy/hres_timer/hres_timer.cpp | 1 - src/utils/time.cpp | 25 +++++++++++++------------ src/utils/time.h | 4 ++++ 8 files changed, 22 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/doc/examples/ca.cpp b/doc/examples/ca.cpp index 8be0fa527..8ca6228c2 100644 --- a/doc/examples/ca.cpp +++ b/doc/examples/ca.cpp @@ -15,11 +15,11 @@ #include #include -#include using namespace Botan; #include #include +#include int main(int argc, char* argv[]) { diff --git a/doc/examples/gen_certs.cpp b/doc/examples/gen_certs.cpp index 557c6f46e..5f943ff3a 100644 --- a/doc/examples/gen_certs.cpp +++ b/doc/examples/gen_certs.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include using namespace Botan; diff --git a/src/cert/cvc/cvc_self.cpp b/src/cert/cvc/cvc_self.cpp index 3b764644f..ae10838ac 100644 --- a/src/cert/cvc/cvc_self.cpp +++ b/src/cert/cvc/cvc_self.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include namespace Botan { diff --git a/src/cert/x509/x509opt.cpp b/src/cert/x509/x509opt.cpp index a2547e30a..8d235ad5d 100644 --- a/src/cert/x509/x509opt.cpp +++ b/src/cert/x509/x509opt.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include namespace Botan { diff --git a/src/cert/x509/x509stor.cpp b/src/cert/x509/x509stor.cpp index a055602a8..80507c1dd 100644 --- a/src/cert/x509/x509stor.cpp +++ b/src/cert/x509/x509stor.cpp @@ -10,8 +10,8 @@ #include #include #include -#include #include +#include #include namespace Botan { diff --git a/src/entropy/hres_timer/hres_timer.cpp b/src/entropy/hres_timer/hres_timer.cpp index 74ea801c4..0f75583ef 100644 --- a/src/entropy/hres_timer/hres_timer.cpp +++ b/src/entropy/hres_timer/hres_timer.cpp @@ -7,7 +7,6 @@ #include #include -#include #if defined(BOTAN_TARGET_OS_IS_WINDOWS) #include diff --git a/src/utils/time.cpp b/src/utils/time.cpp index 1c64c820e..97804813d 100644 --- a/src/utils/time.cpp +++ b/src/utils/time.cpp @@ -43,25 +43,26 @@ u64bit combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz) return res; } -} - -/* -* Convert a time_t to a struct tm -*/ -calendar_point calendar_value( - const std::chrono::system_clock::time_point& time_point) +std::tm do_gmtime(time_t time_val) { - time_t time_val = std::chrono::system_clock::to_time_t(time_point); - // Race condition: std::gmtime is not assured thread safe, // and C++ does not include gmtime_r. Use a mutex here? std::tm* tm_p = std::gmtime(&time_val); if (tm_p == 0) - throw Encoding_Error("time_t_to_tm could not convert"); + throw Encoding_Error("calendar_value could not convert with gmtime"); + return *tm_p; + } - std::tm tm = *tm_p; - // Race is over here +} + +/* +* Convert a time_point to a calendar_point +*/ +calendar_point calendar_value( + const std::chrono::system_clock::time_point& time_point) + { + std::tm tm = do_gmtime(std::chrono::system_clock::to_time_t(time_point)); return calendar_point(tm.tm_year + 1900, tm.tm_mon + 1, diff --git a/src/utils/time.h b/src/utils/time.h index 28b777efe..bd1c8fb06 100644 --- a/src/utils/time.h +++ b/src/utils/time.h @@ -29,6 +29,10 @@ struct BOTAN_DLL calendar_point year(y), month(mon), day(d), hour(h), minutes(min), seconds(sec) {} }; +/* +* @param time_point a time point from the system clock +* @returns calendar_point object representing this time point +*/ BOTAN_DLL calendar_point calendar_value( const std::chrono::system_clock::time_point& time_point); -- cgit v1.2.3 From 9559e323cb631af4e154f5fd30ff2927748817ed Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 1 Dec 2009 17:28:19 +0000 Subject: Instead of checking for Windows generically before using QueryPerformanceCounter, check a feature macro named BOTAN_OS_HAS_QUERY_PERF_COUNTER, and set the same via configure.py for Windows builds. --- src/build-data/os/windows.txt | 1 + src/entropy/hres_timer/hres_timer.cpp | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/build-data/os/windows.txt b/src/build-data/os/windows.txt index e72931c98..59e3ec072 100644 --- a/src/build-data/os/windows.txt +++ b/src/build-data/os/windows.txt @@ -12,6 +12,7 @@ install_cmd_exec "copy" win32_virtual_lock +win32_query_perf_counter diff --git a/src/entropy/hres_timer/hres_timer.cpp b/src/entropy/hres_timer/hres_timer.cpp index 0f75583ef..e6cc102ed 100644 --- a/src/entropy/hres_timer/hres_timer.cpp +++ b/src/entropy/hres_timer/hres_timer.cpp @@ -8,7 +8,7 @@ #include #include -#if defined(BOTAN_TARGET_OS_IS_WINDOWS) +#if defined(BOTAN_TARGET_OS_HAS_QUERY_PERF_COUNTER) #include #endif @@ -19,8 +19,7 @@ namespace Botan { */ 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) +#if defined(BOTAN_TARGET_OS_HAS_QUERY_PERF_COUNTER) LARGE_INTEGER tv; ::QueryPerformanceCounter(&tv); accum.add(tv.QuadPart, 0); -- cgit v1.2.3 From 85b961ff87c1d6300451538c939c99a2ff74b505 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 16 Dec 2009 05:15:42 +0000 Subject: Post-merge fixes --- src/algo_factory/algo_cache.h | 2 +- src/libstate/libstate.cpp | 4 ++-- src/math/gfpmath/info.txt | 8 -------- src/pubkey/dsa/dsa_op.cpp | 2 +- src/pubkey/elgamal/elg_op.cpp | 2 +- src/pubkey/if_algo/if_op.cpp | 2 +- src/pubkey/nr/nr_op.cpp | 2 +- src/rng/hmac_rng/hmac_rng.cpp | 10 ---------- src/rng/randpool/randpool.cpp | 4 ++-- src/utils/info.txt | 1 + 10 files changed, 10 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/algo_factory/algo_cache.h b/src/algo_factory/algo_cache.h index 09bbc4b5a..bafea45e9 100644 --- a/src/algo_factory/algo_cache.h +++ b/src/algo_factory/algo_cache.h @@ -9,7 +9,7 @@ #define BOTAN_ALGORITHM_CACHE_TEMPLATE_H__ #include -#include +#include #include #include #include diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp index 06b05276f..1ca9415e5 100644 --- a/src/libstate/libstate.cpp +++ b/src/libstate/libstate.cpp @@ -9,9 +9,9 @@ #include #include #include -#include +#include #include -#include +#include #include #include diff --git a/src/math/gfpmath/info.txt b/src/math/gfpmath/info.txt index 55ae8b5e6..b7b430805 100644 --- a/src/math/gfpmath/info.txt +++ b/src/math/gfpmath/info.txt @@ -7,15 +7,7 @@ gfp_modulus.h point_gfp.h -<<<<<<< variant A ->>>>>>> variant B - -####### Ancestor -define BIGINT_GFP - - -======= end curve_gfp.cpp gfp_element.cpp point_gfp.cpp diff --git a/src/pubkey/dsa/dsa_op.cpp b/src/pubkey/dsa/dsa_op.cpp index 03eaebfb0..5eb9e92be 100644 --- a/src/pubkey/dsa/dsa_op.cpp +++ b/src/pubkey/dsa/dsa_op.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include namespace Botan { diff --git a/src/pubkey/elgamal/elg_op.cpp b/src/pubkey/elgamal/elg_op.cpp index db828a300..49db44251 100644 --- a/src/pubkey/elgamal/elg_op.cpp +++ b/src/pubkey/elgamal/elg_op.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include namespace Botan { diff --git a/src/pubkey/if_algo/if_op.cpp b/src/pubkey/if_algo/if_op.cpp index 7974bf4f0..58618775b 100644 --- a/src/pubkey/if_algo/if_op.cpp +++ b/src/pubkey/if_algo/if_op.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include namespace Botan { diff --git a/src/pubkey/nr/nr_op.cpp b/src/pubkey/nr/nr_op.cpp index 49aa9fc00..da104802d 100644 --- a/src/pubkey/nr/nr_op.cpp +++ b/src/pubkey/nr/nr_op.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include namespace Botan { diff --git a/src/rng/hmac_rng/hmac_rng.cpp b/src/rng/hmac_rng/hmac_rng.cpp index 00a3a27d0..84cd647b7 100644 --- a/src/rng/hmac_rng/hmac_rng.cpp +++ b/src/rng/hmac_rng/hmac_rng.cpp @@ -6,18 +6,8 @@ */ #include -<<<<<<< variant A #include #include -#include ->>>>>>> variant B -#include -#include -####### Ancestor -#include -#include -#include -======= end #include namespace Botan { diff --git a/src/rng/randpool/randpool.cpp b/src/rng/randpool/randpool.cpp index 18a3b49a0..015cac491 100644 --- a/src/rng/randpool/randpool.cpp +++ b/src/rng/randpool/randpool.cpp @@ -6,8 +6,8 @@ */ #include -#include -#include +#include +#include #include #include diff --git a/src/utils/info.txt b/src/utils/info.txt index edeeb1cf9..bbfcd34be 100644 --- a/src/utils/info.txt +++ b/src/utils/info.txt @@ -14,6 +14,7 @@ version.cpp +async.h bit_ops.h bswap.h loadstor.h -- cgit v1.2.3 From 75234461be7187b1582cd80134e6d6aaeee82c3e Mon Sep 17 00:00:00 2001 From: lloyd Date: Thu, 24 Dec 2009 21:43:26 +0000 Subject: Fixup merge --- src/utils/time.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/utils/time.cpp b/src/utils/time.cpp index 39c9dd49d..77ad0eec5 100644 --- a/src/utils/time.cpp +++ b/src/utils/time.cpp @@ -47,7 +47,7 @@ u64bit combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz) return res; } -std::tm do_gmtime(time_t time_val) +std::tm do_gmtime(std::time_t time_val) { std::tm tm; @@ -75,8 +75,6 @@ calendar_point calendar_value( { std::tm tm = do_gmtime(std::chrono::system_clock::to_time_t(time_point)); - std::tm tm = do_gmtime(time_val); - return calendar_point(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, -- cgit v1.2.3 From fdc97d0ce2e7f45c07e263a1deca7a33029d33f2 Mon Sep 17 00:00:00 2001 From: lloyd Date: Mon, 28 Dec 2009 14:51:36 +0000 Subject: Switch to newly installed gcc snapshot (svn r155312). Don't need -Wno-long-long anymore, C++0x always has long long. --- src/build-data/cc/gcc.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/build-data/cc/gcc.txt b/src/build-data/cc/gcc.txt index 95340f5c0..036153e47 100644 --- a/src/build-data/cc/gcc.txt +++ b/src/build-data/cc/gcc.txt @@ -1,6 +1,6 @@ macro_name GCC -binary_name g++-4.5-20091112 +binary_name g++-4.5-r155312 compile_option "-c " output_to_option "-o " @@ -8,7 +8,7 @@ add_include_dir_option -I add_lib_dir_option -L add_lib_option -l -lang_flags "-ansi -Wno-long-long -std=c++0x" +lang_flags "-ansi -std=c++0x" warning_flags "-W -Wall" #warning_flags "-Wextra -Wall -Wstrict-aliasing -Wstrict-overflow=5 -Wcast-align -Wmissing-declarations -Wno-unused-parameter" -- cgit v1.2.3 From 9b82bb5a720f32e3e7878550310b1151cac188b8 Mon Sep 17 00:00:00 2001 From: lloyd Date: Thu, 21 Jan 2010 15:12:46 +0000 Subject: Use std::future instead of std::unique_future to match N3000 draft and recent GCC 4.5 svn --- src/utils/async.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/utils/async.h b/src/utils/async.h index 85702c114..1ffa2c4cb 100644 --- a/src/utils/async.h +++ b/src/utils/async.h @@ -18,11 +18,11 @@ namespace Botan { * Will be removed once GCC supports it natively */ template -auto std_async(F f) -> std::unique_future +auto std_async(F f) -> std::future { typedef decltype(f()) result_type; std::packaged_task task(std::move(f)); - std::unique_future future = task.get_future(); + std::future future = task.get_future(); std::thread thread(std::move(task)); thread.detach(); return future; -- cgit v1.2.3 From f263a8f1c43b065404eb1f965280a1fc860171bc Mon Sep 17 00:00:00 2001 From: lloyd Date: Thu, 21 Jan 2010 16:41:30 +0000 Subject: Post-merge fixes --- configure.py | 3 +-- src/cert/x509/x509opt.cpp | 2 +- src/filters/modes/cfb/cfb.cpp | 4 ++-- src/filters/pipe.h | 2 +- src/utils/exceptn.h | 4 ++-- 5 files changed, 7 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/configure.py b/configure.py index 39120d22a..9a566f716 100755 --- a/configure.py +++ b/configure.py @@ -1018,8 +1018,7 @@ def choose_modules_to_use(modules, archinfo, options): cannot_use_because(modname, 'incompatible CPU') elif not module.compatible_os(options.os): cannot_use_because(modname, 'incompatible OS') - elif not module.compatible_compiler(options.compiler, - options.with_tr1): + elif not module.compatible_compiler(options.compiler): cannot_use_because(modname, 'incompatible compiler') else: diff --git a/src/cert/x509/x509opt.cpp b/src/cert/x509/x509opt.cpp index fda889224..8d235ad5d 100644 --- a/src/cert/x509/x509opt.cpp +++ b/src/cert/x509/x509opt.cpp @@ -78,7 +78,7 @@ void X509_Cert_Options::sanity_check() const * Initialize the certificate options */ X509_Cert_Options::X509_Cert_Options(const std::string& initial_opts, - u32bit expiration_time_in_seconds) + u32bit expiration_time) { is_CA = false; path_limit = 0; diff --git a/src/filters/modes/cfb/cfb.cpp b/src/filters/modes/cfb/cfb.cpp index e7737e673..ff1714b81 100644 --- a/src/filters/modes/cfb/cfb.cpp +++ b/src/filters/modes/cfb/cfb.cpp @@ -103,7 +103,7 @@ CFB_Decryption::CFB_Decryption(BlockCipher* ciph, u32bit fback_bits) if(feedback == 0 || fback_bits % 8 != 0 || feedback > cipher->BLOCK_SIZE) throw Invalid_Argument("CFB_Decryption: Invalid feedback size " + - to_string(fback_bits)); + std::to_string(fback_bits)); } /* @@ -123,7 +123,7 @@ CFB_Decryption::CFB_Decryption(BlockCipher* ciph, if(feedback == 0 || fback_bits % 8 != 0 || feedback > cipher->BLOCK_SIZE) throw Invalid_Argument("CFB_Decryption: Invalid feedback size " + - to_string(fback_bits)); + std::to_string(fback_bits)); set_key(key); set_iv(iv); diff --git a/src/filters/pipe.h b/src/filters/pipe.h index 19cdd3229..a927e1a0f 100644 --- a/src/filters/pipe.h +++ b/src/filters/pipe.h @@ -33,7 +33,7 @@ class BOTAN_DLL Pipe : public DataSource { Invalid_Message_Number(const std::string& where, message_id msg) : Invalid_Argument("Pipe::" + where + ": Invalid message number " + - to_string(msg)) + std::to_string(msg)) {} }; diff --git a/src/utils/exceptn.h b/src/utils/exceptn.h index 86efebc7c..39b18cb0b 100644 --- a/src/utils/exceptn.h +++ b/src/utils/exceptn.h @@ -56,7 +56,7 @@ struct BOTAN_DLL Invalid_Key_Length : public Invalid_Argument { Invalid_Key_Length(const std::string& name, u32bit length) : Invalid_Argument(name + " cannot accept a key of length " + - to_string(length)) + std::to_string(length)) {} }; @@ -78,7 +78,7 @@ struct BOTAN_DLL Invalid_Block_Size : public Invalid_Argument struct BOTAN_DLL Invalid_IV_Length : public Invalid_Argument { Invalid_IV_Length(const std::string& mode, u32bit bad_len) : - Invalid_Argument("IV length " + to_string(bad_len) + + Invalid_Argument("IV length " + std::to_string(bad_len) + " is invalid for " + mode) {} }; -- cgit v1.2.3 From 9c92ceb2b3bcc9537b4fe572f771d7bbaf8a478a Mon Sep 17 00:00:00 2001 From: lloyd Date: Thu, 21 Jan 2010 16:41:48 +0000 Subject: Set C++0x for ICC. Use GCC-4.5 binary --- src/build-data/cc/gcc.txt | 2 +- src/build-data/cc/icc.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/build-data/cc/gcc.txt b/src/build-data/cc/gcc.txt index 036153e47..1b9f51620 100644 --- a/src/build-data/cc/gcc.txt +++ b/src/build-data/cc/gcc.txt @@ -1,6 +1,6 @@ macro_name GCC -binary_name g++-4.5-r155312 +binary_name g++-4.5 compile_option "-c " output_to_option "-o " diff --git a/src/build-data/cc/icc.txt b/src/build-data/cc/icc.txt index c3a5130bb..1aab4d111 100644 --- a/src/build-data/cc/icc.txt +++ b/src/build-data/cc/icc.txt @@ -12,7 +12,7 @@ lib_opt_flags "-O2 -ip -unroll" check_opt_flags "-O2" debug_flags -g no_debug_flags "-fomit-frame-pointer" -lang_flags "" +lang_flags "-std=c++0x" warning_flags "-w1" shared_flags "-fPIC" -- cgit v1.2.3 From 01a6b5d010f459e8eeb0ef2ce97ecaf885ae1809 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 24 Feb 2010 13:50:39 +0000 Subject: Post-merge fixups --- src/cert/cvc/cvc_ado.cpp | 2 +- src/cert/cvc/cvc_gen_cert.h | 2 +- src/cert/cvc/cvc_self.cpp | 4 ++-- src/math/gfpmath/point_gfp.cpp | 2 +- src/pubkey/gost_3410/gost_3410.cpp | 13 ++++++------- src/ssl/rec_wri.cpp | 2 +- src/ssl/tls_suites.cpp | 2 +- 7 files changed, 13 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/cert/cvc/cvc_ado.cpp b/src/cert/cvc/cvc_ado.cpp index 782922354..fd5b80f13 100644 --- a/src/cert/cvc/cvc_ado.cpp +++ b/src/cert/cvc/cvc_ado.cpp @@ -51,7 +51,7 @@ MemoryVector EAC1_1_ADO::make_signed( RandomNumberGenerator& rng) { SecureVector concat_sig = - EAC1_1_obj::make_signature(signer.get(), tbs_bits, rng); + EAC1_1_obj::make_signature(signer, tbs_bits, rng); return DER_Encoder() .start_cons(ASN1_Tag(7), APPLICATION) diff --git a/src/cert/cvc/cvc_gen_cert.h b/src/cert/cvc/cvc_gen_cert.h index d64812e1e..ab6e22ff0 100644 --- a/src/cert/cvc/cvc_gen_cert.h +++ b/src/cert/cvc/cvc_gen_cert.h @@ -107,7 +107,7 @@ template MemoryVector EAC1_1_gen_CVC::make_sign const MemoryRegion& tbs_bits, RandomNumberGenerator& rng) // static { - SecureVector concat_sig = EAC1_1_obj::make_signature(signer.get(), tbs_bits, rng); + SecureVector concat_sig = EAC1_1_obj::make_signature(signer, tbs_bits, rng); return DER_Encoder() .start_cons(ASN1_Tag(33), APPLICATION) diff --git a/src/cert/cvc/cvc_self.cpp b/src/cert/cvc/cvc_self.cpp index 8d782983d..5ec7d7d32 100644 --- a/src/cert/cvc/cvc_self.cpp +++ b/src/cert/cvc/cvc_self.cpp @@ -134,7 +134,7 @@ EAC1_1_Req create_cvc_req(Private_Key const& key, .encode(chr) .get_contents(); - MemoryVector signed_cert = EAC1_1_gen_CVC::make_signed(signer, EAC1_1_gen_CVC::build_cert_body(tbs), rng); + MemoryVector signed_cert = EAC1_1_gen_CVC::make_signed(*signer.get(), EAC1_1_gen_CVC::build_cert_body(tbs), rng); DataSource_Memory source(signed_cert); return EAC1_1_Req(source); @@ -158,7 +158,7 @@ EAC1_1_ADO create_ado_req(Private_Key const& key, SecureVector tbs_bits = req.BER_encode(); tbs_bits.append(DER_Encoder().encode(car).get_contents()); - MemoryVector signed_cert = EAC1_1_ADO::make_signed(signer, tbs_bits, rng); + MemoryVector signed_cert = EAC1_1_ADO::make_signed(*signer.get(), tbs_bits, rng); DataSource_Memory source(signed_cert); return EAC1_1_ADO(source); diff --git a/src/math/gfpmath/point_gfp.cpp b/src/math/gfpmath/point_gfp.cpp index 00331f25b..4b2de7913 100644 --- a/src/math/gfpmath/point_gfp.cpp +++ b/src/math/gfpmath/point_gfp.cpp @@ -13,7 +13,7 @@ namespace Botan { // construct the point at infinity or a random point -nPointGFp::PointGFp(const CurveGFp& curve) : +PointGFp::PointGFp(const CurveGFp& curve) : mC(curve), mX(curve.get_p(), 0), mY(curve.get_p(), 1), diff --git a/src/pubkey/gost_3410/gost_3410.cpp b/src/pubkey/gost_3410/gost_3410.cpp index c2ddabe63..21e2653c9 100644 --- a/src/pubkey/gost_3410/gost_3410.cpp +++ b/src/pubkey/gost_3410/gost_3410.cpp @@ -19,7 +19,7 @@ namespace Botan { GOST_3410_PrivateKey::GOST_3410_PrivateKey(RandomNumberGenerator& rng, const EC_Domain_Params& dom_pars) { - mp_dom_pars = std::auto_ptr(new EC_Domain_Params(dom_pars)); + mp_dom_pars = std::unique_ptr(new EC_Domain_Params(dom_pars)); generate_private_key(rng); try @@ -35,10 +35,10 @@ GOST_3410_PrivateKey::GOST_3410_PrivateKey(RandomNumberGenerator& rng, GOST_3410_PrivateKey::GOST_3410_PrivateKey(const EC_Domain_Params& domain, const BigInt& x) { - mp_dom_pars = std::auto_ptr(new EC_Domain_Params(domain)); + mp_dom_pars = std::unique_ptr(new EC_Domain_Params(domain)); m_private_value = x; - mp_public_point = std::auto_ptr(new PointGFp (mp_dom_pars->get_base_point())); + mp_public_point = std::unique_ptr(new PointGFp (mp_dom_pars->get_base_point())); mp_public_point->mult_this_secure(m_private_value, mp_dom_pars->get_order(), mp_dom_pars->get_order()-1); @@ -173,9 +173,8 @@ void GOST_3410_PublicKey::set_domain_parameters(const EC_Domain_Params& dom_pars throw Invalid_State("EC_PublicKey::set_domain_parameters(): point does not lie on provided curve"); } - std::auto_ptr p_tmp_pars(new EC_Domain_Params(dom_pars)); mp_public_point.reset(new PointGFp(tmp_pp)); - mp_dom_pars = p_tmp_pars; + mp_dom_pars.reset(new EC_Domain_Params(dom_pars)); } void GOST_3410_PublicKey::set_all_values(const GOST_3410_PublicKey& other) @@ -242,8 +241,8 @@ bool GOST_3410_PublicKey::verify(const byte msg[], u32bit msg_len, GOST_3410_PublicKey::GOST_3410_PublicKey(const EC_Domain_Params& dom_par, const PointGFp& public_point) { - mp_dom_pars = std::auto_ptr(new EC_Domain_Params(dom_par)); - mp_public_point = std::auto_ptr(new PointGFp(public_point)); + mp_dom_pars = std::unique_ptr(new EC_Domain_Params(dom_par)); + mp_public_point = std::unique_ptr(new PointGFp(public_point)); m_param_enc = ENC_EXPLICIT; } diff --git a/src/ssl/rec_wri.cpp b/src/ssl/rec_wri.cpp index 258b4ec17..842b2698c 100644 --- a/src/ssl/rec_wri.cpp +++ b/src/ssl/rec_wri.cpp @@ -250,7 +250,7 @@ void Record_Writer::send_record(byte type, byte major, byte minor, */ void Record_Writer::alert(Alert_Level level, Alert_Type type) { - byte alert[2] = { level, type }; + byte alert[2] = { (byte)level, (byte)type }; send(ALERT, alert, sizeof(alert)); flush(); } diff --git a/src/ssl/tls_suites.cpp b/src/ssl/tls_suites.cpp index 26fa75428..a168dac0a 100644 --- a/src/ssl/tls_suites.cpp +++ b/src/ssl/tls_suites.cpp @@ -51,7 +51,7 @@ CipherSuite::CipherSuite(u16bit suite_code) if(suite_string == "") throw Invalid_Argument("Unknown ciphersuite: " + - to_string(suite_code)); + std::to_string(suite_code)); std::vector suite_info = split_on(suite_string, '/'); -- cgit v1.2.3 From 3e95540b28f3d828c4578381c318545f6ad49589 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 24 Feb 2010 13:55:53 +0000 Subject: Drop async.h and switch to using std::async which was added to GCC before the 4.5 release. --- src/pubkey/dsa/dsa_op.cpp | 7 ++++--- src/pubkey/elgamal/elg_op.cpp | 4 ++-- src/pubkey/if_algo/if_op.cpp | 9 ++------- src/pubkey/nr/nr_op.cpp | 4 ++-- src/utils/async.h | 33 --------------------------------- src/utils/info.txt | 1 - 6 files changed, 10 insertions(+), 48 deletions(-) delete mode 100644 src/utils/async.h (limited to 'src') diff --git a/src/pubkey/dsa/dsa_op.cpp b/src/pubkey/dsa/dsa_op.cpp index 5eb9e92be..e83fd83b7 100644 --- a/src/pubkey/dsa/dsa_op.cpp +++ b/src/pubkey/dsa/dsa_op.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include namespace Botan { @@ -42,7 +42,7 @@ bool Default_DSA_Op::verify(const byte msg[], u32bit msg_len, s = inverse_mod(s, q); - auto future_s_i = std_async( + auto future_s_i = std::async(std::launch::async, [&]() { return powermod_g_p(mod_q.multiply(s, i)); }); BigInt s_r = powermod_y_p(mod_q.multiply(s, r)); @@ -62,7 +62,8 @@ SecureVector Default_DSA_Op::sign(const byte in[], u32bit length, if(x == 0) throw Internal_Error("Default_DSA_Op::sign: No private key"); - auto future_r = std_async([&]() { return mod_q.reduce(powermod_g_p(k)); }); + auto future_r = std::async(std::launch::async, + [&]() { return mod_q.reduce(powermod_g_p(k)); }); const BigInt& q = group.get_q(); BigInt i(in, length); diff --git a/src/pubkey/elgamal/elg_op.cpp b/src/pubkey/elgamal/elg_op.cpp index 49db44251..4bde60bee 100644 --- a/src/pubkey/elgamal/elg_op.cpp +++ b/src/pubkey/elgamal/elg_op.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include namespace Botan { @@ -34,7 +34,7 @@ SecureVector Default_ELG_Op::encrypt(const byte in[], u32bit length, if(m >= p) throw Invalid_Argument("Default_ELG_Op::encrypt: Input is too large"); - auto future_a = std_async([&]() { return powermod_g_p(k); }); + auto future_a = std::async(std::launch::async, powermod_g_p, k); BigInt b = mod_p.multiply(m, powermod_y_p(k)); BigInt a = future_a.get(); diff --git a/src/pubkey/if_algo/if_op.cpp b/src/pubkey/if_algo/if_op.cpp index 58618775b..99f68400d 100644 --- a/src/pubkey/if_algo/if_op.cpp +++ b/src/pubkey/if_algo/if_op.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include namespace Botan { @@ -39,12 +39,7 @@ BigInt Default_IF_Op::private_op(const BigInt& i) const if(q == 0) throw Internal_Error("Default_IF_Op::private_op: No private key"); - /* - * A simple std::bind(powermod_d1_p, i) would work instead of a - * lambda but GCC 4.5's std::result_of doesn't use decltype and gets - * confused - */ - auto future_j1 = std_async([&]() { return powermod_d1_p(i); }); + auto future_j1 = std::async(std::launch::async, powermod_d1_p, i); BigInt j2 = powermod_d2_q(i); BigInt j1 = future_j1.get(); diff --git a/src/pubkey/nr/nr_op.cpp b/src/pubkey/nr/nr_op.cpp index da104802d..10890a127 100644 --- a/src/pubkey/nr/nr_op.cpp +++ b/src/pubkey/nr/nr_op.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include namespace Botan { @@ -38,7 +38,7 @@ SecureVector Default_NR_Op::verify(const byte in[], u32bit length) const if(c.is_zero() || c >= q || d >= q) throw Invalid_Argument("Default_NR_Op::verify: Invalid signature"); - auto future_y_c = std_async([&]() { return powermod_y_p(c); }); + auto future_y_c = std::async(std::launch::async, powermod_y_p, c); BigInt g_d = powermod_g_p(d); BigInt i = mod_p.multiply(g_d, future_y_c.get()); diff --git a/src/utils/async.h b/src/utils/async.h deleted file mode 100644 index 1ffa2c4cb..000000000 --- a/src/utils/async.h +++ /dev/null @@ -1,33 +0,0 @@ -/** -* Standin for C++0x's std::async -* (C) 2009 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_ASYNC_H__ -#define BOTAN_ASYNC_H__ - -#include -#include - -namespace Botan { - -/** -* A simple version of std::async (as it is not in GCC 4.5) -* Will be removed once GCC supports it natively -*/ -template -auto std_async(F f) -> std::future - { - typedef decltype(f()) result_type; - std::packaged_task task(std::move(f)); - std::future future = task.get_future(); - std::thread thread(std::move(task)); - thread.detach(); - return future; - } - -} - -#endif diff --git a/src/utils/info.txt b/src/utils/info.txt index 2fb17fd80..2fb3e79a5 100644 --- a/src/utils/info.txt +++ b/src/utils/info.txt @@ -13,7 +13,6 @@ version.cpp -async.h bit_ops.h debug.h mlock.h -- cgit v1.2.3