From 3c55f159b8e2ff80c0f0ab0820de0afc414be7db Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 30 Sep 2008 04:35:34 +0000 Subject: Split off part of the core module into libstate (basically the whole lookup/global_state piece). Move timer and mutex directories into utils/ --- src/core/def_alg.cpp | 610 ---------------------- src/core/def_mode.cpp | 177 ------- src/core/eng_base.cpp | 306 ----------- src/core/engine.cpp | 382 -------------- src/core/engine.h | 123 ----- src/core/get_enc.cpp | 219 -------- src/core/get_pbe.cpp | 87 --- src/core/get_pbe.h | 22 - src/core/info.txt | 42 +- src/core/init.h | 50 -- src/core/init_def.cpp | 60 --- src/core/init_opt.cpp | 102 ---- src/core/libstate.cpp | 294 ----------- src/core/libstate.h | 90 ---- src/core/libstate/def_alg.cpp | 610 ++++++++++++++++++++++ src/core/libstate/def_mode.cpp | 177 +++++++ src/core/libstate/eng_base.cpp | 306 +++++++++++ src/core/libstate/engine.cpp | 382 ++++++++++++++ src/core/libstate/engine.h | 123 +++++ src/core/libstate/get_enc.cpp | 219 ++++++++ src/core/libstate/get_pbe.cpp | 87 +++ src/core/libstate/get_pbe.h | 22 + src/core/libstate/info.txt | 34 ++ src/core/libstate/init.h | 50 ++ src/core/libstate/init_def.cpp | 60 +++ src/core/libstate/init_opt.cpp | 102 ++++ src/core/libstate/libstate.cpp | 294 +++++++++++ src/core/libstate/libstate.h | 90 ++++ src/core/libstate/look_add.h | 28 + src/core/libstate/look_pk.cpp | 74 +++ src/core/libstate/look_pk.h | 38 ++ src/core/libstate/lookup.cpp | 239 +++++++++ src/core/libstate/lookup.h | 98 ++++ src/core/libstate/oids.cpp | 74 +++ src/core/libstate/oids.h | 36 ++ src/core/libstate/policy.cpp | 492 +++++++++++++++++ src/core/look_add.h | 28 - src/core/look_pk.cpp | 74 --- src/core/look_pk.h | 38 -- src/core/lookup.cpp | 239 --------- src/core/lookup.h | 98 ---- src/core/oids.cpp | 74 --- src/core/oids.h | 36 -- src/core/policy.cpp | 492 ----------------- src/core/selftest/info.txt | 24 + src/core/selftest/selftest.cpp | 163 ++++++ src/core/selftest/selftest.h | 20 + src/mutex/noop_mutex/info.txt | 10 - src/mutex/noop_mutex/mux_noop.cpp | 48 -- src/mutex/noop_mutex/mux_noop.h | 24 - src/mutex/pthreads/info.txt | 29 - src/mutex/pthreads/mux_pthr.cpp | 56 -- src/mutex/pthreads/mux_pthr.h | 24 - src/mutex/qt_mutex/info.txt | 18 - src/mutex/qt_mutex/mux_qt.cpp | 33 -- src/mutex/qt_mutex/mux_qt.h | 25 - src/mutex/win32_crit_section/info.txt | 16 - src/mutex/win32_crit_section/mux_win32.cpp | 32 -- src/mutex/win32_crit_section/mux_win32.h | 24 - src/selftest/info.txt | 24 - src/selftest/selftest.cpp | 163 ------ src/selftest/selftest.h | 20 - src/timer/cpu_counter/info.txt | 36 -- src/timer/cpu_counter/tm_hard.cpp | 49 -- src/timer/cpu_counter/tm_hard.h | 24 - src/timer/gettimeofday/info.txt | 32 -- src/timer/gettimeofday/tm_unix.cpp | 22 - src/timer/gettimeofday/tm_unix.h | 24 - src/timer/posix_rt/info.txt | 28 - src/timer/posix_rt/tm_posix.cpp | 31 -- src/timer/posix_rt/tm_posix.h | 24 - src/timer/timer_base/info.txt | 10 - src/timer/timer_base/timers.cpp | 52 -- src/timer/timer_base/timers.h | 29 - src/timer/win32_query_perf_ctr/info.txt | 25 - src/timer/win32_query_perf_ctr/tm_win32.cpp | 21 - src/timer/win32_query_perf_ctr/tm_win32.h | 24 - src/utils/mutex/noop_mutex/info.txt | 10 + src/utils/mutex/noop_mutex/mux_noop.cpp | 48 ++ src/utils/mutex/noop_mutex/mux_noop.h | 24 + src/utils/mutex/pthreads/info.txt | 29 + src/utils/mutex/pthreads/mux_pthr.cpp | 56 ++ src/utils/mutex/pthreads/mux_pthr.h | 24 + src/utils/mutex/qt_mutex/info.txt | 18 + src/utils/mutex/qt_mutex/mux_qt.cpp | 33 ++ src/utils/mutex/qt_mutex/mux_qt.h | 25 + src/utils/mutex/win32_crit_section/info.txt | 16 + src/utils/mutex/win32_crit_section/mux_win32.cpp | 32 ++ src/utils/mutex/win32_crit_section/mux_win32.h | 24 + src/utils/timer/cpu_counter/info.txt | 36 ++ src/utils/timer/cpu_counter/tm_hard.cpp | 49 ++ src/utils/timer/cpu_counter/tm_hard.h | 24 + src/utils/timer/gettimeofday/info.txt | 32 ++ src/utils/timer/gettimeofday/tm_unix.cpp | 22 + src/utils/timer/gettimeofday/tm_unix.h | 24 + src/utils/timer/posix_rt/info.txt | 28 + src/utils/timer/posix_rt/tm_posix.cpp | 31 ++ src/utils/timer/posix_rt/tm_posix.h | 24 + src/utils/timer/timer_base/info.txt | 10 + src/utils/timer/timer_base/timers.cpp | 52 ++ src/utils/timer/timer_base/timers.h | 29 + src/utils/timer/win32_query_perf_ctr/info.txt | 25 + src/utils/timer/win32_query_perf_ctr/tm_win32.cpp | 21 + src/utils/timer/win32_query_perf_ctr/tm_win32.h | 24 + 104 files changed, 4623 insertions(+), 4609 deletions(-) delete mode 100644 src/core/def_alg.cpp delete mode 100644 src/core/def_mode.cpp delete mode 100644 src/core/eng_base.cpp delete mode 100644 src/core/engine.cpp delete mode 100644 src/core/engine.h delete mode 100644 src/core/get_enc.cpp delete mode 100644 src/core/get_pbe.cpp delete mode 100644 src/core/get_pbe.h delete mode 100644 src/core/init.h delete mode 100644 src/core/init_def.cpp delete mode 100644 src/core/init_opt.cpp delete mode 100644 src/core/libstate.cpp delete mode 100644 src/core/libstate.h create mode 100644 src/core/libstate/def_alg.cpp create mode 100644 src/core/libstate/def_mode.cpp create mode 100644 src/core/libstate/eng_base.cpp create mode 100644 src/core/libstate/engine.cpp create mode 100644 src/core/libstate/engine.h create mode 100644 src/core/libstate/get_enc.cpp create mode 100644 src/core/libstate/get_pbe.cpp create mode 100644 src/core/libstate/get_pbe.h create mode 100644 src/core/libstate/info.txt create mode 100644 src/core/libstate/init.h create mode 100644 src/core/libstate/init_def.cpp create mode 100644 src/core/libstate/init_opt.cpp create mode 100644 src/core/libstate/libstate.cpp create mode 100644 src/core/libstate/libstate.h create mode 100644 src/core/libstate/look_add.h create mode 100644 src/core/libstate/look_pk.cpp create mode 100644 src/core/libstate/look_pk.h create mode 100644 src/core/libstate/lookup.cpp create mode 100644 src/core/libstate/lookup.h create mode 100644 src/core/libstate/oids.cpp create mode 100644 src/core/libstate/oids.h create mode 100644 src/core/libstate/policy.cpp delete mode 100644 src/core/look_add.h delete mode 100644 src/core/look_pk.cpp delete mode 100644 src/core/look_pk.h delete mode 100644 src/core/lookup.cpp delete mode 100644 src/core/lookup.h delete mode 100644 src/core/oids.cpp delete mode 100644 src/core/oids.h delete mode 100644 src/core/policy.cpp create mode 100644 src/core/selftest/info.txt create mode 100644 src/core/selftest/selftest.cpp create mode 100644 src/core/selftest/selftest.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/selftest/info.txt delete mode 100644 src/selftest/selftest.cpp delete mode 100644 src/selftest/selftest.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/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_base/info.txt delete mode 100644 src/timer/timer_base/timers.cpp delete mode 100644 src/timer/timer_base/timers.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/mutex/noop_mutex/info.txt create mode 100644 src/utils/mutex/noop_mutex/mux_noop.cpp create mode 100644 src/utils/mutex/noop_mutex/mux_noop.h create mode 100644 src/utils/mutex/pthreads/info.txt create mode 100644 src/utils/mutex/pthreads/mux_pthr.cpp create mode 100644 src/utils/mutex/pthreads/mux_pthr.h create mode 100644 src/utils/mutex/qt_mutex/info.txt create mode 100644 src/utils/mutex/qt_mutex/mux_qt.cpp create mode 100644 src/utils/mutex/qt_mutex/mux_qt.h create mode 100644 src/utils/mutex/win32_crit_section/info.txt create mode 100644 src/utils/mutex/win32_crit_section/mux_win32.cpp create mode 100644 src/utils/mutex/win32_crit_section/mux_win32.h create mode 100644 src/utils/timer/cpu_counter/info.txt create mode 100644 src/utils/timer/cpu_counter/tm_hard.cpp create mode 100644 src/utils/timer/cpu_counter/tm_hard.h create mode 100644 src/utils/timer/gettimeofday/info.txt create mode 100644 src/utils/timer/gettimeofday/tm_unix.cpp create mode 100644 src/utils/timer/gettimeofday/tm_unix.h create mode 100644 src/utils/timer/posix_rt/info.txt create mode 100644 src/utils/timer/posix_rt/tm_posix.cpp create mode 100644 src/utils/timer/posix_rt/tm_posix.h create mode 100644 src/utils/timer/timer_base/info.txt create mode 100644 src/utils/timer/timer_base/timers.cpp create mode 100644 src/utils/timer/timer_base/timers.h create mode 100644 src/utils/timer/win32_query_perf_ctr/info.txt create mode 100644 src/utils/timer/win32_query_perf_ctr/tm_win32.cpp create mode 100644 src/utils/timer/win32_query_perf_ctr/tm_win32.h diff --git a/src/core/def_alg.cpp b/src/core/def_alg.cpp deleted file mode 100644 index cad5dca5a..000000000 --- a/src/core/def_alg.cpp +++ /dev/null @@ -1,610 +0,0 @@ -/************************************************* -* Default Engine Algorithms Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include -#include - -#if defined(BOTAN_HAS_AES) - #include -#endif - -#if defined(BOTAN_HAS_BLOWFISH) - #include -#endif - -#if defined(BOTAN_HAS_CAST) - #include - #include -#endif - -#if defined(BOTAN_HAS_DES) - #include -#endif - -#if defined(BOTAN_HAS_GOST) - #include -#endif - -#if defined(BOTAN_HAS_IDEA) - #include -#endif - -#if defined(BOTAN_HAS_KASUMI) - #include -#endif - -#if defined(BOTAN_HAS_LION) - #include -#endif - -#if defined(BOTAN_HAS_LUBY_RACKOFF) - #include -#endif - -#if defined(BOTAN_HAS_MARS) - #include -#endif - -#if defined(BOTAN_HAS_MISTY1) - #include -#endif - -#if defined(BOTAN_HAS_NOEKEON) - #include -#endif - -#if defined(BOTAN_HAS_RC2) - #include -#endif - -#if defined(BOTAN_HAS_RC5) - #include -#endif - -#if defined(BOTAN_HAS_RC6) - #include -#endif - -#if defined(BOTAN_HAS_SAFER) - #include -#endif - -#if defined(BOTAN_HAS_SEED) - #include -#endif - -#if defined(BOTAN_HAS_SERPENT) - #include -#endif - -#if defined(BOTAN_HAS_SERPENT_IA32) - #include -#endif - -#if defined(BOTAN_HAS_SKIPJACK) - #include -#endif - -#if defined(BOTAN_HAS_SQUARE) - #include -#endif - -#if defined(BOTAN_HAS_TEA) - #include -#endif - -#if defined(BOTAN_HAS_TWOFISH) - #include -#endif - -#if defined(BOTAN_HAS_XTEA) - #include -#endif - -#if defined(BOTAN_HAS_ARC4) - #include -#endif - -#if defined(BOTAN_HAS_SALSA20) - #include -#endif - -#if defined(BOTAN_HAS_TURING) - #include -#endif - -#if defined(BOTAN_HAS_WID_WAKE) - #include -#endif - -#if defined(BOTAN_HAS_CIPHER_MODE_PADDING) - #include -#endif - -#if defined(BOTAN_HAS_ADLER32) - #include -#endif - -#if defined(BOTAN_HAS_CRC24) - #include -#endif - -#if defined(BOTAN_HAS_CRC32) - #include -#endif - -#if defined(BOTAN_HAS_FORK_256) - #include -#endif - -#if defined(BOTAN_HAS_HAS_160) - #include -#endif - -#if defined(BOTAN_HAS_MD2) - #include -#endif - -#if defined(BOTAN_HAS_MD4) - #include -#endif - -#if defined(BOTAN_HAS_MD4_IA32) - #include -#endif - -#if defined(BOTAN_HAS_MD5) - #include -#endif - -#if defined(BOTAN_HAS_MD5_IA32) - #include -#endif - -#if defined(BOTAN_HAS_RIPEMD_128) - #include -#endif - -#if defined(BOTAN_HAS_RIPEMD_160) - #include -#endif - -#if defined(BOTAN_HAS_SHA1) - #include -#endif - -#if defined(BOTAN_HAS_SHA1_IA32) - #include -#endif - -#if defined(BOTAN_HAS_SHA1_SSE2) - #include -#endif - -#if defined(BOTAN_HAS_SHA1_AMD64) - #include -#endif - -#if defined(BOTAN_HAS_SHA2) - #include - #include -#endif - -#if defined(BOTAN_HAS_TIGER) - #include -#endif - -#if defined(BOTAN_HAS_WHIRLPOOL) - #include -#endif - -#if defined(BOTAN_HAS_PARALLEL_HASH) - #include -#endif - -#if defined(BOTAN_HAS_CBC_MAC) - #include -#endif - -#if defined(BOTAN_HAS_CMAC) - #include -#endif - -#if defined(BOTAN_HAS_HMAC) - #include -#endif - -#if defined(BOTAN_HAS_SSL3_MAC) - #include -#endif - -#if defined(BOTAN_HAS_ANSI_X919_MAC) - #include -#endif - -#if defined(BOTAN_HAS_PBKDF1) - #include -#endif - -#if defined(BOTAN_HAS_PBKDF2) - #include -#endif - -#if defined(BOTAN_HAS_PGPS2K) - #include -#endif - -namespace Botan { - -/************************************************* -* Some macros to simplify control flow * -*************************************************/ -#define HANDLE_TYPE_NO_ARGS(NAME, TYPE) \ - if(algo_name == NAME) \ - { \ - if(name.size() == 1) \ - return new TYPE; \ - throw Invalid_Algorithm_Name(algo_spec); \ - } - -#define HANDLE_TYPE_ONE_U32BIT(NAME, TYPE, DEFAULT) \ - if(algo_name == NAME) \ - { \ - if(name.size() == 1) \ - return new TYPE(DEFAULT); \ - if(name.size() == 2) \ - return new TYPE(to_u32bit(name[1])); \ - throw Invalid_Algorithm_Name(algo_spec); \ - } - -#define HANDLE_TYPE_TWO_U32BIT(NAME, TYPE, DEFAULT) \ - if(algo_name == NAME) \ - { \ - if(name.size() == 1) \ - return new TYPE(DEFAULT); \ - if(name.size() == 2) \ - return new TYPE(to_u32bit(name[1])); \ - if(name.size() == 3) \ - return new TYPE(to_u32bit(name[1]), to_u32bit(name[2])); \ - throw Invalid_Algorithm_Name(algo_spec); \ - } - -#define HANDLE_TYPE_ONE_STRING(NAME, TYPE) \ - if(algo_name == NAME) \ - { \ - if(name.size() == 2) \ - return new TYPE(name[1]); \ - throw Invalid_Algorithm_Name(algo_spec); \ - } - -/************************************************* -* Look for an algorithm with this name * -*************************************************/ -BlockCipher* -Default_Engine::find_block_cipher(const std::string& algo_spec) const - { - std::vector name = parse_algorithm_name(algo_spec); - if(name.empty()) - return 0; - const std::string algo_name = global_state().deref_alias(name[0]); - -#if defined(BOTAN_HAS_AES) - HANDLE_TYPE_NO_ARGS("AES", AES); - HANDLE_TYPE_NO_ARGS("AES-128", AES_128); - HANDLE_TYPE_NO_ARGS("AES-192", AES_192); - HANDLE_TYPE_NO_ARGS("AES-256", AES_256); -#endif - -#if defined(BOTAN_HAS_BLOWFISH) - HANDLE_TYPE_NO_ARGS("Blowfish", Blowfish); -#endif - -#if defined(BOTAN_HAS_CAST) - HANDLE_TYPE_NO_ARGS("CAST-128", CAST_128); - HANDLE_TYPE_NO_ARGS("CAST-256", CAST_256); -#endif - -#if defined(BOTAN_HAS_DES) - HANDLE_TYPE_NO_ARGS("DES", DES); - HANDLE_TYPE_NO_ARGS("DESX", DESX); - HANDLE_TYPE_NO_ARGS("TripleDES", TripleDES); -#endif - -#if defined(BOTAN_HAS_GOST) - HANDLE_TYPE_NO_ARGS("GOST", GOST); -#endif - -#if defined(BOTAN_HAS_IDEA) - HANDLE_TYPE_NO_ARGS("IDEA", IDEA); -#endif - -#if defined(BOTAN_HAS_KASUMI) - HANDLE_TYPE_NO_ARGS("KASUMI", KASUMI); -#endif - -#if defined(BOTAN_HAS_MARS) - HANDLE_TYPE_NO_ARGS("MARS", MARS); -#endif - -#if defined(BOTAN_HAS_MISTY1) - HANDLE_TYPE_ONE_U32BIT("MISTY1", MISTY1, 8); -#endif - -#if defined(BOTAN_HAS_NOEKEON) - HANDLE_TYPE_NO_ARGS("Noekeon", Noekeon); -#endif - -#if defined(BOTAN_HAS_RC2) - HANDLE_TYPE_NO_ARGS("RC2", RC2); -#endif - -#if defined(BOTAN_HAS_RC5) - HANDLE_TYPE_ONE_U32BIT("RC5", RC5, 12); -#endif - -#if defined(BOTAN_HAS_RC6) - HANDLE_TYPE_NO_ARGS("RC6", RC6); -#endif - -#if defined(BOTAN_HAS_SAFER) - HANDLE_TYPE_ONE_U32BIT("SAFER-SK", SAFER_SK, 10); -#endif - -#if defined(BOTAN_HAS_SEED) - HANDLE_TYPE_NO_ARGS("SEED", SEED); -#endif - -#if defined(BOTAN_HAS_SERPENT_IA32) - HANDLE_TYPE_NO_ARGS("Serpent", Serpent_IA32); -#elif defined(BOTAN_HAS_SERPENT) - HANDLE_TYPE_NO_ARGS("Serpent", Serpent); -#endif - -#if defined(BOTAN_HAS_SKIPJACK) - HANDLE_TYPE_NO_ARGS("Skipjack", Skipjack); -#endif - -#if defined(BOTAN_HAS_SQUARE) - HANDLE_TYPE_NO_ARGS("Square", Square); -#endif - -#if defined(BOTAN_HAS_TEA) - HANDLE_TYPE_NO_ARGS("TEA", TEA); -#endif - -#if defined(BOTAN_HAS_TWOFISH) - HANDLE_TYPE_NO_ARGS("Twofish", Twofish); -#endif - -#if defined(BOTAN_HAS_XTEA) - HANDLE_TYPE_NO_ARGS("XTEA", XTEA); -#endif - -#if defined(BOTAN_HAS_LUBY_RACKOFF) - if(algo_name == "Luby-Rackoff" && name.size() >= 2) - { - HashFunction* hash = find_hash(name[1]); - if(hash) - return new LubyRackoff(hash); - } -#endif - -#if defined(BOTAN_HAS_LION) - if(algo_name == "Lion") - { - if(name.size() != 4) - throw Invalid_Algorithm_Name(algo_spec); - return new Lion(name[1], name[2], to_u32bit(name[3])); - } -#endif - - return 0; - } - -/************************************************* -* Look for an algorithm with this name * -*************************************************/ -StreamCipher* -Default_Engine::find_stream_cipher(const std::string& algo_spec) const - { - std::vector name = parse_algorithm_name(algo_spec); - if(name.empty()) - return 0; - const std::string algo_name = global_state().deref_alias(name[0]); - -#if defined(BOTAN_HAS_ARC4) - HANDLE_TYPE_ONE_U32BIT("ARC4", ARC4, 0); - HANDLE_TYPE_ONE_U32BIT("RC4_drop", ARC4, 768); -#endif - -#if defined(BOTAN_HAS_SALSA20) - HANDLE_TYPE_NO_ARGS("Salsa20", Salsa20); -#endif - -#if defined(BOTAN_HAS_TURING) - HANDLE_TYPE_NO_ARGS("Turing", Turing); -#endif - -#if defined(BOTAN_HAS_WID_WAKE) - HANDLE_TYPE_NO_ARGS("WiderWake4+1-BE", WiderWake_41_BE); -#endif - - return 0; - } - -/************************************************* -* Look for an algorithm with this name * -*************************************************/ -HashFunction* -Default_Engine::find_hash(const std::string& algo_spec) const - { - std::vector name = parse_algorithm_name(algo_spec); - if(name.empty()) - return 0; - const std::string algo_name = global_state().deref_alias(name[0]); - -#if defined(BOTAN_HAS_ADLER32) - HANDLE_TYPE_NO_ARGS("Adler32", Adler32); -#endif - -#if defined(BOTAN_HAS_CRC24) - HANDLE_TYPE_NO_ARGS("CRC24", CRC24); -#endif - -#if defined(BOTAN_HAS_CRC32) - HANDLE_TYPE_NO_ARGS("CRC32", CRC32); -#endif - -#if defined(BOTAN_HAS_FORK_256) - HANDLE_TYPE_NO_ARGS("FORK-256", FORK_256); -#endif - -#if defined(BOTAN_HAS_HAS_160) - HANDLE_TYPE_NO_ARGS("HAS-160", HAS_160); -#endif - -#if defined(BOTAN_HAS_MD2) - HANDLE_TYPE_NO_ARGS("MD2", MD2); -#endif - -#if defined(BOTAN_HAS_MD4_IA32) - HANDLE_TYPE_NO_ARGS("MD4", MD4_IA32); -#elif defined(BOTAN_HAS_MD4) - HANDLE_TYPE_NO_ARGS("MD4", MD4); -#endif - -#if defined(BOTAN_HAS_MD5_IA32) - HANDLE_TYPE_NO_ARGS("MD5", MD5_IA32); -#elif defined(BOTAN_HAS_MD5) - HANDLE_TYPE_NO_ARGS("MD5", MD5); -#endif - -#if defined(BOTAN_HAS_RIPEMD_128) - HANDLE_TYPE_NO_ARGS("RIPEMD-128", RIPEMD_128); -#endif - -#if defined(BOTAN_HAS_RIPEMD_160) - HANDLE_TYPE_NO_ARGS("RIPEMD-160", RIPEMD_160); -#endif - -#if defined(BOTAN_HAS_SHA1_SSE2) - HANDLE_TYPE_NO_ARGS("SHA-160", SHA_160_SSE2); -#elif defined(BOTAN_HAS_SHA1_AMD64) - HANDLE_TYPE_NO_ARGS("SHA-160", SHA_160_AMD64); -#elif defined(BOTAN_HAS_SHA1_IA32) - HANDLE_TYPE_NO_ARGS("SHA-160", SHA_160_IA32); -#elif defined(BOTAN_HAS_SHA1) - HANDLE_TYPE_NO_ARGS("SHA-160", SHA_160); -#endif - -#if defined(BOTAN_HAS_SHA2) - HANDLE_TYPE_NO_ARGS("SHA-256", SHA_256); - HANDLE_TYPE_NO_ARGS("SHA-384", SHA_384); - HANDLE_TYPE_NO_ARGS("SHA-512", SHA_512); -#endif - -#if defined(BOTAN_HAS_TIGER) - HANDLE_TYPE_TWO_U32BIT("Tiger", Tiger, 24); -#endif - -#if defined(BOTAN_HAS_WHIRLPOOL) - HANDLE_TYPE_NO_ARGS("Whirlpool", Whirlpool); -#endif - - if(algo_name == "Parallel") - { - if(name.size() < 2) - throw Invalid_Algorithm_Name(algo_spec); - name.erase(name.begin()); - return new Parallel(name); - } - - return 0; - } - -/************************************************* -* Look for an algorithm with this name * -*************************************************/ -MessageAuthenticationCode* -Default_Engine::find_mac(const std::string& algo_spec) const - { - std::vector name = parse_algorithm_name(algo_spec); - if(name.empty()) - return 0; - const std::string algo_name = global_state().deref_alias(name[0]); - -#if defined(BOTAN_HAS_CBC_MAC) - HANDLE_TYPE_ONE_STRING("CBC-MAC", CBC_MAC); -#endif - -#if defined(BOTAN_HAS_CMAC) - HANDLE_TYPE_ONE_STRING("CMAC", CMAC); -#endif - -#if defined(BOTAN_HAS_HMAC) - HANDLE_TYPE_ONE_STRING("HMAC", HMAC); -#endif - -#if defined(BOTAN_HAS_SSL3_MAC) - HANDLE_TYPE_ONE_STRING("SSL3-MAC", SSL3_MAC); -#endif - -#if defined(BOTAN_HAS_ANSI_X919_MAC) - HANDLE_TYPE_NO_ARGS("X9.19-MAC", ANSI_X919_MAC); -#endif - - return 0; - } - -/************************************************* -* Look for an algorithm with this name * -*************************************************/ -S2K* Default_Engine::find_s2k(const std::string& algo_spec) const - { - std::vector name = parse_algorithm_name(algo_spec); - if(name.empty()) - return 0; - - const std::string algo_name = global_state().deref_alias(name[0]); - -#if defined(BOTAN_HAS_PBKDF1) - HANDLE_TYPE_ONE_STRING("PBKDF1", PKCS5_PBKDF1); -#endif - -#if defined(BOTAN_HAS_PBKDF2) - HANDLE_TYPE_ONE_STRING("PBKDF2", PKCS5_PBKDF2); -#endif - -#if defined(BOTAN_HAS_PGPS2K) - HANDLE_TYPE_ONE_STRING("OpenPGP-S2K", OpenPGP_S2K); -#endif - - return 0; - } - -/************************************************* -* Look for an algorithm with this name * -*************************************************/ -BlockCipherModePaddingMethod* -Default_Engine::find_bc_pad(const std::string& algo_spec) const - { - std::vector name = parse_algorithm_name(algo_spec); - if(name.empty()) - return 0; - - const std::string algo_name = global_state().deref_alias(name[0]); - -#if defined(BOTAN_HAS_CIPHER_MODE_PADDING) - HANDLE_TYPE_NO_ARGS("PKCS7", PKCS7_Padding); - HANDLE_TYPE_NO_ARGS("OneAndZeros", OneAndZeros_Padding); - HANDLE_TYPE_NO_ARGS("X9.23", ANSI_X923_Padding); - HANDLE_TYPE_NO_ARGS("NoPadding", Null_Padding); -#endif - - return 0; - } - -} diff --git a/src/core/def_mode.cpp b/src/core/def_mode.cpp deleted file mode 100644 index b062cc34b..000000000 --- a/src/core/def_mode.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/************************************************* -* Default Engine Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include -#include -#include - -#if defined(BOTAN_HAS_ECB) - #include -#endif - -#if defined(BOTAN_HAS_CBC) - #include -#endif - -#if defined(BOTAN_HAS_CTS) - #include -#endif - -#if defined(BOTAN_HAS_CFB) - #include -#endif - -#if defined(BOTAN_HAS_OFB) - #include -#endif - -#if defined(BOTAN_HAS_CTR) - #include -#endif - -#if defined(BOTAN_HAS_EAX) - #include -#endif - -namespace Botan { - -/************************************************* -* Get a cipher object * -*************************************************/ -Keyed_Filter* Default_Engine::get_cipher(const std::string& algo_spec, - Cipher_Dir direction) - { - std::vector algo_parts = split_on(algo_spec, '/'); - if(algo_parts.empty()) - throw Invalid_Algorithm_Name(algo_spec); - - const std::string cipher = algo_parts[0]; - - if(have_stream_cipher(cipher)) - { - if(algo_parts.size() == 1) - return new StreamCipher_Filter(cipher); - return 0; - } - else if(have_block_cipher(cipher)) - { - if(algo_parts.size() != 2 && algo_parts.size() != 3) - return 0; - - std::string mode = algo_parts[1]; - u32bit bits = 0; - - if(mode.find("CFB") != std::string::npos || - mode.find("EAX") != std::string::npos) - { - std::vector algo_info = parse_algorithm_name(mode); - mode = algo_info[0]; - if(algo_info.size() == 1) - bits = 8*block_size_of(cipher); - else if(algo_info.size() == 2) - bits = to_u32bit(algo_info[1]); - else - throw Invalid_Algorithm_Name(algo_spec); - } - - std::string padding; - if(algo_parts.size() == 3) - padding = algo_parts[2]; - else - padding = (mode == "CBC") ? "PKCS7" : "NoPadding"; - - if(mode == "ECB" && padding == "CTS") - return 0; - else if((mode != "CBC" && mode != "ECB") && padding != "NoPadding") - throw Invalid_Algorithm_Name(algo_spec); - - if(mode == "OFB") - { -#if defined(BOTAN_HAS_OFB) - return new OFB(cipher); -#else - return 0; -#endif - } - else if(mode == "CTR-BE") - { -#if defined(BOTAN_HAS_CTR) - return new CTR_BE(cipher); -#else - return 0; -#endif - } - else if(mode == "ECB" || mode == "CBC" || mode == "CTS" || - mode == "CFB" || mode == "EAX") - { - if(mode == "ECB") - { -#if defined(BOTAN_HAS_ECB) - if(direction == ENCRYPTION) - return new ECB_Encryption(cipher, padding); - else - return new ECB_Decryption(cipher, padding); -#else - return 0; -#endif - } - else if(mode == "CFB") - { -#if defined(BOTAN_HAS_CFB) - if(direction == ENCRYPTION) - return new CFB_Encryption(cipher, bits); - else - return new CFB_Decryption(cipher, bits); -#else - return 0; -#endif - } - else if(mode == "CBC") - { - if(padding == "CTS") - { -#if defined(BOTAN_HAS_CTS) - if(direction == ENCRYPTION) - return new CTS_Encryption(cipher); - else - return new CTS_Decryption(cipher); -#else - return 0; -#endif - } - -#if defined(BOTAN_HAS_CBC) - if(direction == ENCRYPTION) - return new CBC_Encryption(cipher, padding); - else - return new CBC_Decryption(cipher, padding); -#else - return 0; -#endif - } - else if(mode == "EAX") - { -#if defined(BOTAN_HAS_EAX) - if(direction == ENCRYPTION) - return new EAX_Encryption(cipher, bits); - else - return new EAX_Decryption(cipher, bits); -#else - return 0; -#endif - } - else - throw Internal_Error("get_mode: " + cipher + "/" - + mode + "/" + padding); - } - else - return 0; - } - - return 0; - } - -} diff --git a/src/core/eng_base.cpp b/src/core/eng_base.cpp deleted file mode 100644 index 38234d462..000000000 --- a/src/core/eng_base.cpp +++ /dev/null @@ -1,306 +0,0 @@ -/************************************************* -* Basic No-Op Engine Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include -#include -#include - -namespace Botan { - -namespace { - -/************************************************* -* Algorithm Cache * -*************************************************/ -template -class Algorithm_Cache_Impl : public Engine::Algorithm_Cache - { - public: - T* get(const std::string& name) const - { - Mutex_Holder lock(mutex); - return search_map(mappings, name); - } - - void add(T* algo, const std::string& index_name = "") const - { - if(!algo) - return; - - Mutex_Holder lock(mutex); - - const std::string name = - (index_name != "" ? index_name : algo->name()); - - if(mappings.find(name) != mappings.end()) - delete mappings[name]; - mappings[name] = algo; - } - - Algorithm_Cache_Impl() - { - mutex = global_state().get_mutex(); - } - - ~Algorithm_Cache_Impl() - { - typename std::map::iterator i = mappings.begin(); - - while(i != mappings.end()) - { - delete i->second; - ++i; - } - delete mutex; - } - private: - Mutex* mutex; - mutable std::map mappings; - }; - -} - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -IF_Operation* Engine::if_op(const BigInt&, const BigInt&, const BigInt&, - const BigInt&, const BigInt&, const BigInt&, - const BigInt&, const BigInt&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -DSA_Operation* Engine::dsa_op(const DL_Group&, const BigInt&, - const BigInt&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -NR_Operation* Engine::nr_op(const DL_Group&, const BigInt&, - const BigInt&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -ELG_Operation* Engine::elg_op(const DL_Group&, const BigInt&, - const BigInt&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -DH_Operation* Engine::dh_op(const DL_Group&, const BigInt&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -Modular_Exponentiator* Engine::mod_exp(const BigInt&, - Power_Mod::Usage_Hints) const - { - return 0; - } - -/************************************************* -* Acquire a BlockCipher * -*************************************************/ -const BlockCipher* Engine::block_cipher(const std::string& name) const - { - return lookup_algo(cache_of_bc, global_state().deref_alias(name), - this, &Engine::find_block_cipher); - } - -/************************************************* -* Acquire a StreamCipher * -*************************************************/ -const StreamCipher* Engine::stream_cipher(const std::string& name) const - { - return lookup_algo(cache_of_sc, global_state().deref_alias(name), - this, &Engine::find_stream_cipher); - } - -/************************************************* -* Acquire a HashFunction * -*************************************************/ -const HashFunction* Engine::hash(const std::string& name) const - { - return lookup_algo(cache_of_hf, global_state().deref_alias(name), - this, &Engine::find_hash); - } - -/************************************************* -* Acquire a MessageAuthenticationCode * -*************************************************/ -const MessageAuthenticationCode* Engine::mac(const std::string& name) const - { - return lookup_algo(cache_of_mac, global_state().deref_alias(name), - this, &Engine::find_mac); - } - -/************************************************* -* Acquire a S2K object * -*************************************************/ -const S2K* Engine::s2k(const std::string& name) const - { - return lookup_algo(cache_of_s2k, global_state().deref_alias(name), - this, &Engine::find_s2k); - } - -/************************************************* -* Acquire a cipher padding object * -*************************************************/ -const BlockCipherModePaddingMethod* -Engine::bc_pad(const std::string& name) const - { - return lookup_algo(cache_of_bc_pad, global_state().deref_alias(name), - this, &Engine::find_bc_pad); - } - -/************************************************* -* Add a block cipher to the lookup table * -*************************************************/ -void Engine::add_algorithm(BlockCipher* algo) const - { - cache_of_bc->add(algo); - } - -/************************************************* -* Add a stream cipher to the lookup table * -*************************************************/ -void Engine::add_algorithm(StreamCipher* algo) const - { - cache_of_sc->add(algo); - } - -/************************************************* -* Add a hash function to the lookup table * -*************************************************/ -void Engine::add_algorithm(HashFunction* algo) const - { - cache_of_hf->add(algo); - } - -/************************************************* -* Add a MAC to the lookup table * -*************************************************/ -void Engine::add_algorithm(MessageAuthenticationCode* algo) const - { - cache_of_mac->add(algo); - } - -/************************************************* -* Add a S2K to the lookup table * -*************************************************/ -void Engine::add_algorithm(S2K* algo) const - { - cache_of_s2k->add(algo); - } - -/************************************************* -* Add a cipher pad method to the lookup table * -*************************************************/ -void Engine::add_algorithm(BlockCipherModePaddingMethod* algo) const - { - cache_of_bc_pad->add(algo); - } - -/************************************************* -* Create an Engine * -*************************************************/ -Engine::Engine() - { - cache_of_bc = new Algorithm_Cache_Impl(); - cache_of_sc = new Algorithm_Cache_Impl(); - cache_of_hf = new Algorithm_Cache_Impl(); - cache_of_mac = new Algorithm_Cache_Impl(); - cache_of_s2k = new Algorithm_Cache_Impl(); - cache_of_bc_pad = - new Algorithm_Cache_Impl(); - } - -/************************************************* -* Destroy an Engine * -*************************************************/ -Engine::~Engine() - { - delete cache_of_bc; - delete cache_of_sc; - delete cache_of_hf; - delete cache_of_mac; - delete cache_of_s2k; - delete cache_of_bc_pad; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -BlockCipher* Engine::find_block_cipher(const std::string&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -StreamCipher* Engine::find_stream_cipher(const std::string&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -HashFunction* Engine::find_hash(const std::string&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -MessageAuthenticationCode* Engine::find_mac(const std::string&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -S2K* Engine::find_s2k(const std::string&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -BlockCipherModePaddingMethod* Engine::find_bc_pad(const std::string&) const - { - return 0; - } - -/************************************************* -* Basic No-Op Engine Implementation * -*************************************************/ -Keyed_Filter* Engine::get_cipher(const std::string&, Cipher_Dir) - { - return 0; - } - -} diff --git a/src/core/engine.cpp b/src/core/engine.cpp deleted file mode 100644 index 804ab3580..000000000 --- a/src/core/engine.cpp +++ /dev/null @@ -1,382 +0,0 @@ -/************************************************* -* Engine Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include -#include -#include -#include - -namespace Botan { - -namespace Engine_Core { - -/************************************************* -* Acquire an IF op * -*************************************************/ -IF_Operation* if_op(const BigInt& e, const BigInt& n, const BigInt& d, - const BigInt& p, const BigInt& q, const BigInt& d1, - const BigInt& d2, const BigInt& c) - { - Library_State::Engine_Iterator i(global_state()); - - while(const Engine* engine = i.next()) - { - IF_Operation* op = engine->if_op(e, n, d, p, q, d1, d2, c); - if(op) - return op; - } - - throw Lookup_Error("Engine_Core::if_op: Unable to find a working engine"); - } - -/************************************************* -* Acquire a DSA op * -*************************************************/ -DSA_Operation* dsa_op(const DL_Group& group, const BigInt& y, const BigInt& x) - { - Library_State::Engine_Iterator i(global_state()); - - while(const Engine* engine = i.next()) - { - DSA_Operation* op = engine->dsa_op(group, y, x); - if(op) - return op; - } - - throw Lookup_Error("Engine_Core::dsa_op: Unable to find a working engine"); - } - -/************************************************* -* Acquire a NR op * -*************************************************/ -NR_Operation* nr_op(const DL_Group& group, const BigInt& y, const BigInt& x) - { - Library_State::Engine_Iterator i(global_state()); - - while(const Engine* engine = i.next()) - { - NR_Operation* op = engine->nr_op(group, y, x); - if(op) - return op; - } - - throw Lookup_Error("Engine_Core::nr_op: Unable to find a working engine"); - } - -/************************************************* -* Acquire an ElGamal op * -*************************************************/ -ELG_Operation* elg_op(const DL_Group& group, const BigInt& y, const BigInt& x) - { - Library_State::Engine_Iterator i(global_state()); - - while(const Engine* engine = i.next()) - { - ELG_Operation* op = engine->elg_op(group, y, x); - if(op) - return op; - } - - throw Lookup_Error("Engine_Core::elg_op: Unable to find a working engine"); - } - -/************************************************* -* Acquire a DH op * -*************************************************/ -DH_Operation* dh_op(const DL_Group& group, const BigInt& x) - { - Library_State::Engine_Iterator i(global_state()); - - while(const Engine* engine = i.next()) - { - DH_Operation* op = engine->dh_op(group, x); - if(op) - return op; - } - - throw Lookup_Error("Engine_Core::dh_op: Unable to find a working engine"); - } - -/************************************************* -* Acquire a modular exponentiator * -*************************************************/ -Modular_Exponentiator* mod_exp(const BigInt& n, Power_Mod::Usage_Hints hints) - { - Library_State::Engine_Iterator i(global_state()); - - while(const Engine* engine = i.next()) - { - Modular_Exponentiator* op = engine->mod_exp(n, hints); - - if(op) - return op; - } - - throw Lookup_Error("Engine_Core::mod_exp: Unable to find a working engine"); - } - -} - -/************************************************* -* Acquire a block cipher * -*************************************************/ -const BlockCipher* retrieve_block_cipher(Library_State& libstate, - const std::string& name) - { - Library_State::Engine_Iterator i(libstate); - - while(const Engine* engine = i.next()) - { - const BlockCipher* algo = engine->block_cipher(name); - if(algo) - return algo; - } - - return 0; - } - -/************************************************* -* Acquire a stream cipher * -*************************************************/ -const StreamCipher* retrieve_stream_cipher(Library_State& libstate, - const std::string& name) - { - Library_State::Engine_Iterator i(libstate); - - while(const Engine* engine = i.next()) - { - const StreamCipher* algo = engine->stream_cipher(name); - if(algo) - return algo; - } - - return 0; - } - -/************************************************* -* Acquire a hash function * -*************************************************/ -const HashFunction* retrieve_hash(Library_State& libstate, - const std::string& name) - { - Library_State::Engine_Iterator i(libstate); - - while(const Engine* engine = i.next()) - { - const HashFunction* algo = engine->hash(name); - if(algo) - return algo; - } - - return 0; - } - -/************************************************* -* Acquire an authentication code * -*************************************************/ -const MessageAuthenticationCode* retrieve_mac(Library_State& libstate, - const std::string& name) - { - Library_State::Engine_Iterator i(libstate); - - while(const Engine* engine = i.next()) - { - const MessageAuthenticationCode* algo = engine->mac(name); - if(algo) - return algo; - } - - return 0; - } - -/************************************************* -* Acquire a string-to-key algorithm * -*************************************************/ -const S2K* retrieve_s2k(Library_State& libstate, - const std::string& name) - { - Library_State::Engine_Iterator i(libstate); - - while(const Engine* engine = i.next()) - { - const S2K* algo = engine->s2k(name); - if(algo) - return algo; - } - - return 0; - } - -/************************************************* -* Retrieve a block cipher padding method * -*************************************************/ -const BlockCipherModePaddingMethod* retrieve_bc_pad(Library_State& libstate, - const std::string& name) - { - Library_State::Engine_Iterator i(libstate); - - while(const Engine* engine = i.next()) - { - const BlockCipherModePaddingMethod* algo = engine->bc_pad(name); - if(algo) - return algo; - } - - return 0; - } - -/************************************************* -* Add a new block cipher * -*************************************************/ -void add_algorithm(Library_State& libstate, BlockCipher* algo) - { - Library_State::Engine_Iterator i(libstate); - - while(Engine* engine_base = i.next()) - { - Default_Engine* engine = dynamic_cast(engine_base); - if(engine) - { - engine->add_algorithm(algo); - return; - } - } - - throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); - } - -/************************************************* -* Add a new stream cipher * -*************************************************/ -void add_algorithm(Library_State& libstate, StreamCipher* algo) - { - Library_State::Engine_Iterator i(libstate); - - while(Engine* engine_base = i.next()) - { - Default_Engine* engine = dynamic_cast(engine_base); - if(engine) - { - engine->add_algorithm(algo); - return; - } - } - - throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); - } - -/************************************************* -* Add a new hash function * -*************************************************/ -void add_algorithm(Library_State& libstate, HashFunction* algo) - { - Library_State::Engine_Iterator i(libstate); - - while(Engine* engine_base = i.next()) - { - Default_Engine* engine = dynamic_cast(engine_base); - if(engine) - { - engine->add_algorithm(algo); - return; - } - } - - throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); - } - -/************************************************* -* Add a new authentication code * -*************************************************/ -void add_algorithm(Library_State& libstate, - MessageAuthenticationCode* algo) - { - Library_State::Engine_Iterator i(libstate); - - while(Engine* engine_base = i.next()) - { - Default_Engine* engine = dynamic_cast(engine_base); - if(engine) - { - engine->add_algorithm(algo); - return; - } - } - - throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); - } - -/************************************************* -* Add a padding method to the lookup table * -*************************************************/ -void add_algorithm(Library_State& libstate, - BlockCipherModePaddingMethod* algo) - { - Library_State::Engine_Iterator i(libstate); - - while(Engine* engine_base = i.next()) - { - Default_Engine* engine = dynamic_cast(engine_base); - if(engine) - { - engine->add_algorithm(algo); - return; - } - } - - throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); - } - -/************************************************* -* Get a cipher object * -*************************************************/ -Keyed_Filter* get_cipher(Library_State& libstate, - const std::string& algo_spec, - Cipher_Dir direction) - { - Library_State::Engine_Iterator i(libstate); - - while(Engine* engine = i.next()) - { - Keyed_Filter* algo = engine->get_cipher(algo_spec, direction); - if(algo) - return algo; - } - - throw Algorithm_Not_Found(algo_spec); - } - -/************************************************* -* Get a cipher object * -*************************************************/ -Keyed_Filter* get_cipher(Library_State& libstate, - const std::string& algo_spec, - const SymmetricKey& key, - const InitializationVector& iv, - Cipher_Dir direction) - { - Keyed_Filter* cipher = get_cipher(libstate, algo_spec, direction); - cipher->set_key(key); - - if(iv.length()) - cipher->set_iv(iv); - - return cipher; - } - -/************************************************* -* Get a cipher object * -*************************************************/ -Keyed_Filter* get_cipher(Library_State& libstate, - const std::string& algo_spec, - const SymmetricKey& key, - Cipher_Dir direction) - { - return get_cipher(libstate, algo_spec, - key, InitializationVector(), direction); - } - -} diff --git a/src/core/engine.h b/src/core/engine.h deleted file mode 100644 index 13007e662..000000000 --- a/src/core/engine.h +++ /dev/null @@ -1,123 +0,0 @@ -/************************************************* -* Engine Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_ENGINE_H__ -#define BOTAN_ENGINE_H__ - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Botan { - -/************************************************* -* Engine Base Class * -*************************************************/ -class BOTAN_DLL Engine - { - public: - template - class BOTAN_DLL Algorithm_Cache - { - public: - virtual T* get(const std::string&) const = 0; - virtual void add(T* algo, const std::string& = "") const = 0; - virtual ~Algorithm_Cache() {} - }; - - virtual IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&, - const BigInt&, const BigInt&, const BigInt&, - const BigInt&, const BigInt&) const; - virtual DSA_Operation* dsa_op(const DL_Group&, const BigInt&, - const BigInt&) const; - virtual NR_Operation* nr_op(const DL_Group&, const BigInt&, - const BigInt&) const; - virtual ELG_Operation* elg_op(const DL_Group&, const BigInt&, - const BigInt&) const; - virtual DH_Operation* dh_op(const DL_Group&, const BigInt&) const; - - virtual Modular_Exponentiator* mod_exp(const BigInt&, - Power_Mod::Usage_Hints) const; - - virtual Keyed_Filter* get_cipher(const std::string&, Cipher_Dir); - - const BlockCipher* block_cipher(const std::string&) const; - const StreamCipher* stream_cipher(const std::string&) const; - const HashFunction* hash(const std::string&) const; - const MessageAuthenticationCode* mac(const std::string&) const; - const class S2K* s2k(const std::string&) const; - const class BlockCipherModePaddingMethod* - bc_pad(const std::string&) const; - - void add_algorithm(BlockCipher*) const; - void add_algorithm(StreamCipher*) const; - void add_algorithm(HashFunction*) const; - void add_algorithm(MessageAuthenticationCode*) const; - void add_algorithm(class S2K*) const; - void add_algorithm(class BlockCipherModePaddingMethod*) const; - - Engine(); - virtual ~Engine(); - private: - virtual BlockCipher* find_block_cipher(const std::string&) const; - virtual StreamCipher* find_stream_cipher(const std::string&) const; - virtual HashFunction* find_hash(const std::string&) const; - virtual MessageAuthenticationCode* find_mac(const std::string&) const; - virtual class S2K* find_s2k(const std::string&) const; - virtual class BlockCipherModePaddingMethod* - find_bc_pad(const std::string&) const; - - template - const T* lookup_algo(const Algorithm_Cache* cache, - const std::string& name, - const Engine* engine, - T* (Engine::*find)(const std::string&) const) const - { - T* algo = cache->get(name); - if(!algo) - { - algo = (engine->*find)(name); - if(algo) - cache->add(algo, name); - } - return algo; - } - - Algorithm_Cache* cache_of_bc; - Algorithm_Cache* cache_of_sc; - Algorithm_Cache* cache_of_hf; - Algorithm_Cache* cache_of_mac; - Algorithm_Cache* cache_of_bc_pad; - Algorithm_Cache* cache_of_s2k; - }; - -namespace Engine_Core { - -/************************************************* -* Get an operation from an Engine * -*************************************************/ -Modular_Exponentiator* mod_exp(const BigInt&, Power_Mod::Usage_Hints); - -IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&, - const BigInt&, const BigInt&, const BigInt&, - const BigInt&, const BigInt&); - -DSA_Operation* dsa_op(const DL_Group&, const BigInt&, const BigInt&); -NR_Operation* nr_op(const DL_Group&, const BigInt&, const BigInt&); - -ELG_Operation* elg_op(const DL_Group&, const BigInt&, const BigInt&); - -DH_Operation* dh_op(const DL_Group&, const BigInt&); - -} - -} - -#endif diff --git a/src/core/get_enc.cpp b/src/core/get_enc.cpp deleted file mode 100644 index fb5952a3e..000000000 --- a/src/core/get_enc.cpp +++ /dev/null @@ -1,219 +0,0 @@ -/************************************************* -* EMSA/EME/KDF/MGF Retrieval Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include -#include -#include - -#if defined(BOTAN_HAS_MGF1) - #include -#endif - -#if defined(BOTAN_HAS_EMSA1) - #include -#endif - -#if defined(BOTAN_HAS_EMSA2) - #include -#endif - -#if defined(BOTAN_HAS_EMSA3) - #include -#endif - -#if defined(BOTAN_HAS_EMSA4) - #include -#endif - -#if defined(BOTAN_HAS_EMSA_RAW) - #include -#endif - -#if defined(BOTAN_HAS_EME1) - #include -#endif - -#if defined(BOTAN_HAS_EME_PKCS1v15) - #include -#endif - -#if defined(BOTAN_HAS_KDF1) - #include -#endif - -#if defined(BOTAN_HAS_KDF2) - #include -#endif - -#if defined(BOTAN_HAS_X942_PRF) - #include -#endif - -#if defined(BOTAN_HAS_SSL_V3_PRF) - #include -#endif - -#if defined(BOTAN_HAS_TLS_V10_PRF) - #include -#endif - -namespace Botan { - -/************************************************* -* Get an EMSA by name * -*************************************************/ -EMSA* get_emsa(const std::string& algo_spec) - { - std::vector name = parse_algorithm_name(algo_spec); - const std::string emsa_name = global_state().deref_alias(name[0]); - -#if defined(BOTAN_HAS_EMSA_RAW) - if(emsa_name == "Raw") - { - if(name.size() == 1) - return new EMSA_Raw; - } -#endif - -#if defined(BOTAN_HAS_EMSA1) - if(emsa_name == "EMSA1") - { - if(name.size() == 2) - return new EMSA1(name[1]); - } -#endif - -#if defined(BOTAN_HAS_EMSA2) - if(emsa_name == "EMSA2") - { - if(name.size() == 2) - return new EMSA2(name[1]); - } -#endif - -#if defined(BOTAN_HAS_EMSA3) - if(emsa_name == "EMSA3") - { - if(name.size() == 2) - return new EMSA3(name[1]); - } -#endif - -#if defined(BOTAN_HAS_EMSA4) - if(emsa_name == "EMSA4") - { - if(name.size() == 2) - return new EMSA4(name[1], "MGF1"); - if(name.size() == 3) - return new EMSA4(name[1], name[2]); - if(name.size() == 4) - return new EMSA4(name[1], name[2], to_u32bit(name[3])); - } -#endif - - throw Algorithm_Not_Found(algo_spec); - } - -/************************************************* -* Get an EME by name * -*************************************************/ -EME* get_eme(const std::string& algo_spec) - { - std::vector name = parse_algorithm_name(algo_spec); - const std::string eme_name = global_state().deref_alias(name[0]); - -#if defined(BOTAN_HAS_EME_PKCS1v15) - if(eme_name == "PKCS1v15") - { - if(name.size() == 1) - return new EME_PKCS1v15; - } -#endif - -#if defined(BOTAN_HAS_EME1) - if(eme_name == "EME1") - { - if(name.size() == 2) - return new EME1(name[1], "MGF1"); - if(name.size() == 3) - return new EME1(name[1], name[2]); - } -#endif - - throw Algorithm_Not_Found(algo_spec); - } - -/************************************************* -* Get an KDF by name * -*************************************************/ -KDF* get_kdf(const std::string& algo_spec) - { - std::vector name = parse_algorithm_name(algo_spec); - const std::string kdf_name = global_state().deref_alias(name[0]); - -#if defined(BOTAN_HAS_KDF1) - if(kdf_name == "KDF1") - { - if(name.size() == 2) - return new KDF1(name[1]); - } -#endif - -#if defined(BOTAN_HAS_KDF2) - if(kdf_name == "KDF2") - { - if(name.size() == 2) - return new KDF2(name[1]); - } -#endif - -#if defined(BOTAN_HAS_X942_PRF) - if(kdf_name == "X9.42-PRF") - { - if(name.size() == 2) - return new X942_PRF(name[1]); - } -#endif - -#if defined(BOTAN_HAS_TLS_V10_PRF) - if(kdf_name == "TLS-PRF") - { - if(name.size() == 1) - return new TLS_PRF; - } -#endif - -#if defined(BOTAN_HAS_SSL_V3_PRF) - if(kdf_name == "SSL3-PRF") - { - if(name.size() == 1) - return new SSL3_PRF; - } -#endif - - throw Algorithm_Not_Found(algo_spec); - } - -/************************************************* -* Get a MGF by name * -*************************************************/ -MGF* get_mgf(const std::string& algo_spec) - { - std::vector name = parse_algorithm_name(algo_spec); - const std::string mgf_name = global_state().deref_alias(name[0]); - -#ifdef BOTAN_HAS_MGF1 - if(mgf_name == "MGF1") - { - if(name.size() == 2) - return new MGF1(get_hash(name[1])); - } -#endif - - throw Algorithm_Not_Found(algo_spec); - } - -} diff --git a/src/core/get_pbe.cpp b/src/core/get_pbe.cpp deleted file mode 100644 index cd1ed2aa4..000000000 --- a/src/core/get_pbe.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/************************************************* -* PBE Retrieval Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include -#include - -#if defined(BOTAN_HAS_PBE_PKCS_V15) - #include -#endif - -#if defined(BOTAN_HAS_PBE_PKCS_V20) - #include -#endif - -namespace Botan { - -/************************************************* -* Get an encryption PBE, set new parameters * -*************************************************/ -PBE* get_pbe(const std::string& pbe_name) - { - std::vector algo_name; - algo_name = parse_algorithm_name(pbe_name); - - if(algo_name.size() != 3) - throw Invalid_Algorithm_Name(pbe_name); - - const std::string pbe = algo_name[0]; - const std::string digest = algo_name[1]; - const std::string cipher = algo_name[2]; - - PBE* pbe_obj = 0; - -#if defined(BOTAN_HAS_PBE_PKCS_V15) - if(!pbe_obj && pbe == "PBE-PKCS5v15") - pbe_obj = new PBE_PKCS5v15(digest, cipher, ENCRYPTION); -#endif - -#if defined(BOTAN_HAS_PBE_PKCS_V20) - if(!pbe_obj && pbe == "PBE-PKCS5v20") - pbe_obj = new PBE_PKCS5v20(digest, cipher); -#endif - - if(!pbe_obj) - throw Algorithm_Not_Found(pbe_name); - - return pbe_obj; - } - -/************************************************* -* Get a decryption PBE, decode parameters * -*************************************************/ -PBE* get_pbe(const OID& pbe_oid, DataSource& params) - { - std::vector algo_name; - algo_name = parse_algorithm_name(OIDS::lookup(pbe_oid)); - - if(algo_name.size() < 1) - throw Invalid_Algorithm_Name(pbe_oid.as_string()); - const std::string pbe_algo = algo_name[0]; - - if(pbe_algo == "PBE-PKCS5v15") - { -#if defined(BOTAN_HAS_PBE_PKCS_V15) - if(algo_name.size() != 3) - throw Invalid_Algorithm_Name(pbe_oid.as_string()); - const std::string digest = algo_name[1]; - const std::string cipher = algo_name[2]; - PBE* pbe = new PBE_PKCS5v15(digest, cipher, DECRYPTION); - pbe->decode_params(params); - return pbe; -#endif - } - else if(pbe_algo == "PBE-PKCS5v20") - { -#if defined(BOTAN_HAS_PBE_PKCS_V20) - return new PBE_PKCS5v20(params); -#endif - } - - throw Algorithm_Not_Found(pbe_oid.as_string()); - } - -} diff --git a/src/core/get_pbe.h b/src/core/get_pbe.h deleted file mode 100644 index e7b434c1f..000000000 --- a/src/core/get_pbe.h +++ /dev/null @@ -1,22 +0,0 @@ -/************************************************* -* PBE Lookup Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_LOOKUP_PBE_H__ -#define BOTAN_LOOKUP_PBE_H__ - -#include -#include - -namespace Botan { - -/************************************************* -* Get a PBE object * -*************************************************/ -BOTAN_DLL PBE* get_pbe(const std::string&); -BOTAN_DLL PBE* get_pbe(const OID&, DataSource&); - -} - -#endif diff --git a/src/core/info.txt b/src/core/info.txt index 681f72379..3a9f9f34f 100644 --- a/src/core/info.txt +++ b/src/core/info.txt @@ -11,54 +11,34 @@ sha2 hmac allocators filters +libstate timer_base base.cpp -data_src.cpp -datastor.cpp -def_alg.cpp -def_mode.cpp -def_powm.cpp -eng_base.cpp -engine.cpp -exceptn.cpp -get_enc.cpp -get_pbe.cpp -init_def.cpp -init_opt.cpp -kdf.cpp -libstate.cpp -look_pk.cpp -lookup.cpp -modules.cpp -oids.cpp -pk_pad.cpp -policy.cpp -rng.cpp -s2k.cpp -symkey.cpp base.h botan.h +data_src.cpp data_src.h +datastor.cpp datastor.h +def_powm.cpp eng_def.h -engine.h enums.h +exceptn.cpp exceptn.h -init.h +kdf.cpp kdf.h -libstate.h -look_add.h -look_pk.h -get_pbe.h -lookup.h +modules.cpp modules.h mutex.h -oids.h +pk_pad.cpp pk_pad.h +rng.cpp rng.h +s2k.cpp s2k.h +symkey.cpp symkey.h diff --git a/src/core/init.h b/src/core/init.h deleted file mode 100644 index f4296a868..000000000 --- a/src/core/init.h +++ /dev/null @@ -1,50 +0,0 @@ -/************************************************* -* Library Initialization Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_INIT_H__ -#define BOTAN_INIT_H__ - -#include -#include -#include - -namespace Botan { - -/************************************************* -* Options for initializing the library * -*************************************************/ -class BOTAN_DLL InitializerOptions - { - public: - bool thread_safe() const; - bool use_engines() const; - bool secure_memory() const; - bool fips_mode() const; - bool self_test() const; - - InitializerOptions(const std::string&); - private: - std::map args; - }; - -/************************************************* -* Library Initialization/Shutdown Object * -*************************************************/ -class BOTAN_DLL LibraryInitializer - { - public: - static void initialize(const std::string& = ""); - static void initialize(const InitializerOptions&); - static void initialize(const InitializerOptions&, class Modules&); - static void deinitialize(); - - LibraryInitializer(const std::string& args = "") { initialize(args); } - LibraryInitializer(const InitializerOptions& args) { initialize(args); } - ~LibraryInitializer() { deinitialize(); } - }; - -} - -#endif diff --git a/src/core/init_def.cpp b/src/core/init_def.cpp deleted file mode 100644 index 03f97252e..000000000 --- a/src/core/init_def.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/************************************************* -* Default Initialization Function Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include -#include - -namespace Botan { - -/************************************************* -* Library Initialization * -*************************************************/ -void LibraryInitializer::initialize(const InitializerOptions& args, - Modules& modules) - { - try - { - set_global_state(new Library_State); - - global_state().initialize(args, modules); - } - catch(...) - { - deinitialize(); - throw; - } - } - -/************************************************* -* Library Shutdown * -*************************************************/ -void LibraryInitializer::deinitialize() - { - set_global_state(0); - } - -/************************************************* -* Library Initialization * -*************************************************/ -void LibraryInitializer::initialize(const std::string& arg_string) - { - InitializerOptions args(arg_string); - Builtin_Modules modules(args); - - initialize(args, modules); - } - -/************************************************* -* Library Initialization * -*************************************************/ -void LibraryInitializer::initialize(const InitializerOptions& args) - { - Builtin_Modules modules(args); - - initialize(args, modules); - } - -} diff --git a/src/core/init_opt.cpp b/src/core/init_opt.cpp deleted file mode 100644 index 5c4fbee65..000000000 --- a/src/core/init_opt.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/************************************************* -* Initialization Options Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include -#include -#include - -namespace Botan { - -namespace { - -/************************************************* -* Check for an arbitrary boolean-valued option * -*************************************************/ -bool boolean_arg(const std::map& args, - const std::string& key, bool not_found = false) - { - std::map::const_iterator i = args.find(key); - if(i == args.end()) - return not_found; - - std::string value = i->second; - - if(value == "1" || value == "true" || value == "yes" || value == "on") - return true; - if(value == "0" || value == "false" || value == "no" || value == "off") - return false; - if(value == "default") - return not_found; - - throw Invalid_Argument("InitializerOptions: Bad argument for boolean " + - key + " of '" + value + "'"); - } - -} - -/************************************************* -* Check if thread safety was requested * -*************************************************/ -bool InitializerOptions::thread_safe() const - { - return boolean_arg(args, "thread_safe"); - } - -/************************************************* -* Check if secure allocation was requested * -*************************************************/ -bool InitializerOptions::secure_memory() const - { - return boolean_arg(args, "secure_memory"); - } - -/************************************************* -* Check if using engines was requested * -*************************************************/ -bool InitializerOptions::use_engines() const - { - return boolean_arg(args, "use_engines"); - } - -/************************************************* -* Check if FIPS mode was requested * -*************************************************/ -bool InitializerOptions::fips_mode() const - { - return boolean_arg(args, "fips140"); - } - -/************************************************* -* Check if startup self tests were requested * -*************************************************/ -bool InitializerOptions::self_test() const - { - return boolean_arg(args, "selftest", true); - } - -/************************************************* -* Setup an InitializerOptions * -*************************************************/ -InitializerOptions::InitializerOptions(const std::string& arg_string) - { - 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; - - if(arg_list[j].find('=') == std::string::npos) - args[arg_list[j]] = "true"; - else - { - std::vector name_and_value = split_on(arg_list[j], '='); - args[name_and_value[0]] = name_and_value[1]; - } - } - } - -} diff --git a/src/core/libstate.cpp b/src/core/libstate.cpp deleted file mode 100644 index 60bb24fee..000000000 --- a/src/core/libstate.cpp +++ /dev/null @@ -1,294 +0,0 @@ -/************************************************* -* Library Internal/Global State Source File * -* (C) 1999-2008 Jack Lloyd * -*************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(BOTAN_HAS_SELFTEST) - #include -#endif - -namespace Botan { - -/************************************************* -* Botan's global state * -*************************************************/ -namespace { - -Library_State* global_lib_state = 0; - -} - -/************************************************* -* Access the global state object * -*************************************************/ -Library_State& global_state() - { - if(!global_lib_state) - LibraryInitializer::initialize(); - return (*global_lib_state); - } - -/************************************************* -* Set a new global state object * -*************************************************/ -void set_global_state(Library_State* new_state) - { - delete swap_global_state(new_state); - } - -/************************************************* -* Swap two global state objects * -*************************************************/ -Library_State* swap_global_state(Library_State* new_state) - { - Library_State* old_state = global_lib_state; - global_lib_state = new_state; - return old_state; - } - -/************************************************* -* Increment the Engine iterator * -*************************************************/ -Engine* Library_State::Engine_Iterator::next() - { - return lib.get_engine_n(n++); - } - -/************************************************* -* 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 - { - Mutex_Holder lock(allocator_lock); - - if(type != "") - return search_map(alloc_factory, type, 0); - - if(!cached_default_allocator) - { - std::string chosen = this->option("base/default_allocator"); - - if(chosen == "") - chosen = "malloc"; - - cached_default_allocator = - search_map(alloc_factory, chosen, 0); - } - - return cached_default_allocator; - } - -/************************************************* -* Create a new name to object mapping * -*************************************************/ -void Library_State::add_allocator(Allocator* allocator) - { - Mutex_Holder lock(allocator_lock); - - allocator->init(); - - allocators.push_back(allocator); - alloc_factory[allocator->type()] = allocator; - } - -/************************************************* -* Set the default allocator type * -*************************************************/ -void Library_State::set_default_allocator(const std::string& type) - { - Mutex_Holder lock(allocator_lock); - - if(type == "") - return; - - this->set("conf", "base/default_allocator", type); - cached_default_allocator = 0; - } - -/************************************************* -* Get an engine out of the list * -*************************************************/ -Engine* Library_State::get_engine_n(u32bit n) const - { - Mutex_Holder lock(engine_lock); - - if(n >= engines.size()) - return 0; - return engines[n]; - } - -/************************************************* -* Add a new engine to the list * -*************************************************/ -void Library_State::add_engine(Engine* engine) - { - Mutex_Holder lock(engine_lock); - engines.insert(engines.begin(), engine); - } - -/************************************************* -* Get a configuration value * -*************************************************/ -std::string Library_State::get(const std::string& section, - const std::string& key) const - { - Mutex_Holder lock(config_lock); - - return search_map(config, - section + "/" + key, ""); - } - -/************************************************* -* See if a particular option has been set * -*************************************************/ -bool Library_State::is_set(const std::string& section, - const std::string& key) const - { - Mutex_Holder lock(config_lock); - - return search_map(config, section + "/" + key, false, true); - } - -/************************************************* -* Set a configuration value * -*************************************************/ -void Library_State::set(const std::string& section, const std::string& key, - const std::string& value, bool overwrite) - { - Mutex_Holder lock(config_lock); - - std::string full_key = section + "/" + key; - - std::map::const_iterator i = - config.find(full_key); - - if(overwrite || i == config.end() || i->second == "") - config[full_key] = value; - } - -/************************************************* -* Add an alias * -*************************************************/ -void Library_State::add_alias(const std::string& key, const std::string& value) - { - set("alias", key, value); - } - -/************************************************* -* Dereference an alias to a fixed name * -*************************************************/ -std::string Library_State::deref_alias(const std::string& key) const - { - std::string result = key; - while(is_set("alias", result)) - result = get("alias", result); - return result; - } - -/************************************************* -* Set/Add an option * -*************************************************/ -void Library_State::set_option(const std::string key, - const std::string& value) - { - set("conf", key, value); - } - -/************************************************* -* Get an option value * -*************************************************/ -std::string Library_State::option(const std::string& key) const - { - return get("conf", key); - } - -/************************************************* -* Load a set of modules * -*************************************************/ -void Library_State::initialize(const InitializerOptions& args, - Modules& modules) - { - if(mutex_factory) - throw Invalid_State("Library_State has already been initialized"); - - mutex_factory = modules.mutex_factory(args.thread_safe()); - - if(!mutex_factory) - throw Invalid_State("Could not acquire a mutex module at init"); - - allocator_lock = get_mutex(); - engine_lock = get_mutex(); - config_lock = get_mutex(); - - cached_default_allocator = 0; - - std::vector mod_allocs = modules.allocators(mutex_factory); - for(u32bit j = 0; j != mod_allocs.size(); ++j) - add_allocator(mod_allocs[j]); - - set_default_allocator(modules.default_allocator()); - - load_default_config(); - - std::vector mod_engines = modules.engines(); - for(u32bit j = 0; j != mod_engines.size(); ++j) - engines.push_back(mod_engines[j]); - -#if defined(BOTAN_HAS_SELFTEST) - if(args.fips_mode() || args.self_test()) - { - if(!passes_self_tests()) - throw Self_Test_Failure("Initialization self-tests"); - } -#endif - } - -/************************************************* -* Library_State Constructor * -*************************************************/ -Library_State::Library_State() - { - mutex_factory = 0; - allocator_lock = engine_lock = config_lock = 0; - cached_default_allocator = 0; - } - -/************************************************* -* Library_State Destructor * -*************************************************/ -Library_State::~Library_State() - { - std::for_each(engines.begin(), engines.end(), del_fun()); - - cached_default_allocator = 0; - - for(u32bit j = 0; j != allocators.size(); ++j) - { - allocators[j]->destroy(); - delete allocators[j]; - } - - delete allocator_lock; - delete engine_lock; - delete mutex_factory; - delete config_lock; - } - -} diff --git a/src/core/libstate.h b/src/core/libstate.h deleted file mode 100644 index 4b1221c84..000000000 --- a/src/core/libstate.h +++ /dev/null @@ -1,90 +0,0 @@ -/************************************************* -* Library Internal/Global State Header File * -* (C) 1999-2008 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_LIB_STATE_H__ -#define BOTAN_LIB_STATE_H__ - -#include -#include -#include -#include -#include - -namespace Botan { - -/************************************************* -* Global State Container Base * -*************************************************/ -class BOTAN_DLL Library_State - { - public: - Library_State(); - ~Library_State(); - - void initialize(const InitializerOptions&, Modules&); - - void load(Modules&); - - void add_engine(class Engine*); - - class BOTAN_DLL Engine_Iterator - { - public: - class Engine* next(); - Engine_Iterator(const Library_State& l) : lib(l) { n = 0; } - private: - const Library_State& lib; - u32bit n; - }; - friend class Engine_Iterator; - - Allocator* get_allocator(const std::string& = "") const; - void add_allocator(Allocator*); - void set_default_allocator(const std::string&); - - std::string get(const std::string&, const std::string&) const; - bool is_set(const std::string&, const std::string&) const; - void set(const std::string&, const std::string&, - const std::string&, bool = true); - - std::string option(const std::string&) const; - void set_option(const std::string, const std::string&); - - void add_alias(const std::string&, const std::string&); - std::string deref_alias(const std::string&) const; - - class Mutex* get_mutex() const; - private: - void load_default_config(); - - Library_State(const Library_State&) {} - Library_State& operator=(const Library_State&) { return (*this); } - - class Engine* get_engine_n(u32bit) const; - - class Mutex_Factory* mutex_factory; - - std::map config; - class Mutex* config_lock; - - class Mutex* allocator_lock; - std::map alloc_factory; - mutable Allocator* cached_default_allocator; - std::vector allocators; - - class Mutex* engine_lock; - std::vector engines; - }; - -/************************************************* -* Global State * -*************************************************/ -BOTAN_DLL Library_State& global_state(); -BOTAN_DLL void set_global_state(Library_State*); -BOTAN_DLL Library_State* swap_global_state(Library_State*); - -} - -#endif diff --git a/src/core/libstate/def_alg.cpp b/src/core/libstate/def_alg.cpp new file mode 100644 index 000000000..cad5dca5a --- /dev/null +++ b/src/core/libstate/def_alg.cpp @@ -0,0 +1,610 @@ +/************************************************* +* Default Engine Algorithms Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include +#include + +#if defined(BOTAN_HAS_AES) + #include +#endif + +#if defined(BOTAN_HAS_BLOWFISH) + #include +#endif + +#if defined(BOTAN_HAS_CAST) + #include + #include +#endif + +#if defined(BOTAN_HAS_DES) + #include +#endif + +#if defined(BOTAN_HAS_GOST) + #include +#endif + +#if defined(BOTAN_HAS_IDEA) + #include +#endif + +#if defined(BOTAN_HAS_KASUMI) + #include +#endif + +#if defined(BOTAN_HAS_LION) + #include +#endif + +#if defined(BOTAN_HAS_LUBY_RACKOFF) + #include +#endif + +#if defined(BOTAN_HAS_MARS) + #include +#endif + +#if defined(BOTAN_HAS_MISTY1) + #include +#endif + +#if defined(BOTAN_HAS_NOEKEON) + #include +#endif + +#if defined(BOTAN_HAS_RC2) + #include +#endif + +#if defined(BOTAN_HAS_RC5) + #include +#endif + +#if defined(BOTAN_HAS_RC6) + #include +#endif + +#if defined(BOTAN_HAS_SAFER) + #include +#endif + +#if defined(BOTAN_HAS_SEED) + #include +#endif + +#if defined(BOTAN_HAS_SERPENT) + #include +#endif + +#if defined(BOTAN_HAS_SERPENT_IA32) + #include +#endif + +#if defined(BOTAN_HAS_SKIPJACK) + #include +#endif + +#if defined(BOTAN_HAS_SQUARE) + #include +#endif + +#if defined(BOTAN_HAS_TEA) + #include +#endif + +#if defined(BOTAN_HAS_TWOFISH) + #include +#endif + +#if defined(BOTAN_HAS_XTEA) + #include +#endif + +#if defined(BOTAN_HAS_ARC4) + #include +#endif + +#if defined(BOTAN_HAS_SALSA20) + #include +#endif + +#if defined(BOTAN_HAS_TURING) + #include +#endif + +#if defined(BOTAN_HAS_WID_WAKE) + #include +#endif + +#if defined(BOTAN_HAS_CIPHER_MODE_PADDING) + #include +#endif + +#if defined(BOTAN_HAS_ADLER32) + #include +#endif + +#if defined(BOTAN_HAS_CRC24) + #include +#endif + +#if defined(BOTAN_HAS_CRC32) + #include +#endif + +#if defined(BOTAN_HAS_FORK_256) + #include +#endif + +#if defined(BOTAN_HAS_HAS_160) + #include +#endif + +#if defined(BOTAN_HAS_MD2) + #include +#endif + +#if defined(BOTAN_HAS_MD4) + #include +#endif + +#if defined(BOTAN_HAS_MD4_IA32) + #include +#endif + +#if defined(BOTAN_HAS_MD5) + #include +#endif + +#if defined(BOTAN_HAS_MD5_IA32) + #include +#endif + +#if defined(BOTAN_HAS_RIPEMD_128) + #include +#endif + +#if defined(BOTAN_HAS_RIPEMD_160) + #include +#endif + +#if defined(BOTAN_HAS_SHA1) + #include +#endif + +#if defined(BOTAN_HAS_SHA1_IA32) + #include +#endif + +#if defined(BOTAN_HAS_SHA1_SSE2) + #include +#endif + +#if defined(BOTAN_HAS_SHA1_AMD64) + #include +#endif + +#if defined(BOTAN_HAS_SHA2) + #include + #include +#endif + +#if defined(BOTAN_HAS_TIGER) + #include +#endif + +#if defined(BOTAN_HAS_WHIRLPOOL) + #include +#endif + +#if defined(BOTAN_HAS_PARALLEL_HASH) + #include +#endif + +#if defined(BOTAN_HAS_CBC_MAC) + #include +#endif + +#if defined(BOTAN_HAS_CMAC) + #include +#endif + +#if defined(BOTAN_HAS_HMAC) + #include +#endif + +#if defined(BOTAN_HAS_SSL3_MAC) + #include +#endif + +#if defined(BOTAN_HAS_ANSI_X919_MAC) + #include +#endif + +#if defined(BOTAN_HAS_PBKDF1) + #include +#endif + +#if defined(BOTAN_HAS_PBKDF2) + #include +#endif + +#if defined(BOTAN_HAS_PGPS2K) + #include +#endif + +namespace Botan { + +/************************************************* +* Some macros to simplify control flow * +*************************************************/ +#define HANDLE_TYPE_NO_ARGS(NAME, TYPE) \ + if(algo_name == NAME) \ + { \ + if(name.size() == 1) \ + return new TYPE; \ + throw Invalid_Algorithm_Name(algo_spec); \ + } + +#define HANDLE_TYPE_ONE_U32BIT(NAME, TYPE, DEFAULT) \ + if(algo_name == NAME) \ + { \ + if(name.size() == 1) \ + return new TYPE(DEFAULT); \ + if(name.size() == 2) \ + return new TYPE(to_u32bit(name[1])); \ + throw Invalid_Algorithm_Name(algo_spec); \ + } + +#define HANDLE_TYPE_TWO_U32BIT(NAME, TYPE, DEFAULT) \ + if(algo_name == NAME) \ + { \ + if(name.size() == 1) \ + return new TYPE(DEFAULT); \ + if(name.size() == 2) \ + return new TYPE(to_u32bit(name[1])); \ + if(name.size() == 3) \ + return new TYPE(to_u32bit(name[1]), to_u32bit(name[2])); \ + throw Invalid_Algorithm_Name(algo_spec); \ + } + +#define HANDLE_TYPE_ONE_STRING(NAME, TYPE) \ + if(algo_name == NAME) \ + { \ + if(name.size() == 2) \ + return new TYPE(name[1]); \ + throw Invalid_Algorithm_Name(algo_spec); \ + } + +/************************************************* +* Look for an algorithm with this name * +*************************************************/ +BlockCipher* +Default_Engine::find_block_cipher(const std::string& algo_spec) const + { + std::vector name = parse_algorithm_name(algo_spec); + if(name.empty()) + return 0; + const std::string algo_name = global_state().deref_alias(name[0]); + +#if defined(BOTAN_HAS_AES) + HANDLE_TYPE_NO_ARGS("AES", AES); + HANDLE_TYPE_NO_ARGS("AES-128", AES_128); + HANDLE_TYPE_NO_ARGS("AES-192", AES_192); + HANDLE_TYPE_NO_ARGS("AES-256", AES_256); +#endif + +#if defined(BOTAN_HAS_BLOWFISH) + HANDLE_TYPE_NO_ARGS("Blowfish", Blowfish); +#endif + +#if defined(BOTAN_HAS_CAST) + HANDLE_TYPE_NO_ARGS("CAST-128", CAST_128); + HANDLE_TYPE_NO_ARGS("CAST-256", CAST_256); +#endif + +#if defined(BOTAN_HAS_DES) + HANDLE_TYPE_NO_ARGS("DES", DES); + HANDLE_TYPE_NO_ARGS("DESX", DESX); + HANDLE_TYPE_NO_ARGS("TripleDES", TripleDES); +#endif + +#if defined(BOTAN_HAS_GOST) + HANDLE_TYPE_NO_ARGS("GOST", GOST); +#endif + +#if defined(BOTAN_HAS_IDEA) + HANDLE_TYPE_NO_ARGS("IDEA", IDEA); +#endif + +#if defined(BOTAN_HAS_KASUMI) + HANDLE_TYPE_NO_ARGS("KASUMI", KASUMI); +#endif + +#if defined(BOTAN_HAS_MARS) + HANDLE_TYPE_NO_ARGS("MARS", MARS); +#endif + +#if defined(BOTAN_HAS_MISTY1) + HANDLE_TYPE_ONE_U32BIT("MISTY1", MISTY1, 8); +#endif + +#if defined(BOTAN_HAS_NOEKEON) + HANDLE_TYPE_NO_ARGS("Noekeon", Noekeon); +#endif + +#if defined(BOTAN_HAS_RC2) + HANDLE_TYPE_NO_ARGS("RC2", RC2); +#endif + +#if defined(BOTAN_HAS_RC5) + HANDLE_TYPE_ONE_U32BIT("RC5", RC5, 12); +#endif + +#if defined(BOTAN_HAS_RC6) + HANDLE_TYPE_NO_ARGS("RC6", RC6); +#endif + +#if defined(BOTAN_HAS_SAFER) + HANDLE_TYPE_ONE_U32BIT("SAFER-SK", SAFER_SK, 10); +#endif + +#if defined(BOTAN_HAS_SEED) + HANDLE_TYPE_NO_ARGS("SEED", SEED); +#endif + +#if defined(BOTAN_HAS_SERPENT_IA32) + HANDLE_TYPE_NO_ARGS("Serpent", Serpent_IA32); +#elif defined(BOTAN_HAS_SERPENT) + HANDLE_TYPE_NO_ARGS("Serpent", Serpent); +#endif + +#if defined(BOTAN_HAS_SKIPJACK) + HANDLE_TYPE_NO_ARGS("Skipjack", Skipjack); +#endif + +#if defined(BOTAN_HAS_SQUARE) + HANDLE_TYPE_NO_ARGS("Square", Square); +#endif + +#if defined(BOTAN_HAS_TEA) + HANDLE_TYPE_NO_ARGS("TEA", TEA); +#endif + +#if defined(BOTAN_HAS_TWOFISH) + HANDLE_TYPE_NO_ARGS("Twofish", Twofish); +#endif + +#if defined(BOTAN_HAS_XTEA) + HANDLE_TYPE_NO_ARGS("XTEA", XTEA); +#endif + +#if defined(BOTAN_HAS_LUBY_RACKOFF) + if(algo_name == "Luby-Rackoff" && name.size() >= 2) + { + HashFunction* hash = find_hash(name[1]); + if(hash) + return new LubyRackoff(hash); + } +#endif + +#if defined(BOTAN_HAS_LION) + if(algo_name == "Lion") + { + if(name.size() != 4) + throw Invalid_Algorithm_Name(algo_spec); + return new Lion(name[1], name[2], to_u32bit(name[3])); + } +#endif + + return 0; + } + +/************************************************* +* Look for an algorithm with this name * +*************************************************/ +StreamCipher* +Default_Engine::find_stream_cipher(const std::string& algo_spec) const + { + std::vector name = parse_algorithm_name(algo_spec); + if(name.empty()) + return 0; + const std::string algo_name = global_state().deref_alias(name[0]); + +#if defined(BOTAN_HAS_ARC4) + HANDLE_TYPE_ONE_U32BIT("ARC4", ARC4, 0); + HANDLE_TYPE_ONE_U32BIT("RC4_drop", ARC4, 768); +#endif + +#if defined(BOTAN_HAS_SALSA20) + HANDLE_TYPE_NO_ARGS("Salsa20", Salsa20); +#endif + +#if defined(BOTAN_HAS_TURING) + HANDLE_TYPE_NO_ARGS("Turing", Turing); +#endif + +#if defined(BOTAN_HAS_WID_WAKE) + HANDLE_TYPE_NO_ARGS("WiderWake4+1-BE", WiderWake_41_BE); +#endif + + return 0; + } + +/************************************************* +* Look for an algorithm with this name * +*************************************************/ +HashFunction* +Default_Engine::find_hash(const std::string& algo_spec) const + { + std::vector name = parse_algorithm_name(algo_spec); + if(name.empty()) + return 0; + const std::string algo_name = global_state().deref_alias(name[0]); + +#if defined(BOTAN_HAS_ADLER32) + HANDLE_TYPE_NO_ARGS("Adler32", Adler32); +#endif + +#if defined(BOTAN_HAS_CRC24) + HANDLE_TYPE_NO_ARGS("CRC24", CRC24); +#endif + +#if defined(BOTAN_HAS_CRC32) + HANDLE_TYPE_NO_ARGS("CRC32", CRC32); +#endif + +#if defined(BOTAN_HAS_FORK_256) + HANDLE_TYPE_NO_ARGS("FORK-256", FORK_256); +#endif + +#if defined(BOTAN_HAS_HAS_160) + HANDLE_TYPE_NO_ARGS("HAS-160", HAS_160); +#endif + +#if defined(BOTAN_HAS_MD2) + HANDLE_TYPE_NO_ARGS("MD2", MD2); +#endif + +#if defined(BOTAN_HAS_MD4_IA32) + HANDLE_TYPE_NO_ARGS("MD4", MD4_IA32); +#elif defined(BOTAN_HAS_MD4) + HANDLE_TYPE_NO_ARGS("MD4", MD4); +#endif + +#if defined(BOTAN_HAS_MD5_IA32) + HANDLE_TYPE_NO_ARGS("MD5", MD5_IA32); +#elif defined(BOTAN_HAS_MD5) + HANDLE_TYPE_NO_ARGS("MD5", MD5); +#endif + +#if defined(BOTAN_HAS_RIPEMD_128) + HANDLE_TYPE_NO_ARGS("RIPEMD-128", RIPEMD_128); +#endif + +#if defined(BOTAN_HAS_RIPEMD_160) + HANDLE_TYPE_NO_ARGS("RIPEMD-160", RIPEMD_160); +#endif + +#if defined(BOTAN_HAS_SHA1_SSE2) + HANDLE_TYPE_NO_ARGS("SHA-160", SHA_160_SSE2); +#elif defined(BOTAN_HAS_SHA1_AMD64) + HANDLE_TYPE_NO_ARGS("SHA-160", SHA_160_AMD64); +#elif defined(BOTAN_HAS_SHA1_IA32) + HANDLE_TYPE_NO_ARGS("SHA-160", SHA_160_IA32); +#elif defined(BOTAN_HAS_SHA1) + HANDLE_TYPE_NO_ARGS("SHA-160", SHA_160); +#endif + +#if defined(BOTAN_HAS_SHA2) + HANDLE_TYPE_NO_ARGS("SHA-256", SHA_256); + HANDLE_TYPE_NO_ARGS("SHA-384", SHA_384); + HANDLE_TYPE_NO_ARGS("SHA-512", SHA_512); +#endif + +#if defined(BOTAN_HAS_TIGER) + HANDLE_TYPE_TWO_U32BIT("Tiger", Tiger, 24); +#endif + +#if defined(BOTAN_HAS_WHIRLPOOL) + HANDLE_TYPE_NO_ARGS("Whirlpool", Whirlpool); +#endif + + if(algo_name == "Parallel") + { + if(name.size() < 2) + throw Invalid_Algorithm_Name(algo_spec); + name.erase(name.begin()); + return new Parallel(name); + } + + return 0; + } + +/************************************************* +* Look for an algorithm with this name * +*************************************************/ +MessageAuthenticationCode* +Default_Engine::find_mac(const std::string& algo_spec) const + { + std::vector name = parse_algorithm_name(algo_spec); + if(name.empty()) + return 0; + const std::string algo_name = global_state().deref_alias(name[0]); + +#if defined(BOTAN_HAS_CBC_MAC) + HANDLE_TYPE_ONE_STRING("CBC-MAC", CBC_MAC); +#endif + +#if defined(BOTAN_HAS_CMAC) + HANDLE_TYPE_ONE_STRING("CMAC", CMAC); +#endif + +#if defined(BOTAN_HAS_HMAC) + HANDLE_TYPE_ONE_STRING("HMAC", HMAC); +#endif + +#if defined(BOTAN_HAS_SSL3_MAC) + HANDLE_TYPE_ONE_STRING("SSL3-MAC", SSL3_MAC); +#endif + +#if defined(BOTAN_HAS_ANSI_X919_MAC) + HANDLE_TYPE_NO_ARGS("X9.19-MAC", ANSI_X919_MAC); +#endif + + return 0; + } + +/************************************************* +* Look for an algorithm with this name * +*************************************************/ +S2K* Default_Engine::find_s2k(const std::string& algo_spec) const + { + std::vector name = parse_algorithm_name(algo_spec); + if(name.empty()) + return 0; + + const std::string algo_name = global_state().deref_alias(name[0]); + +#if defined(BOTAN_HAS_PBKDF1) + HANDLE_TYPE_ONE_STRING("PBKDF1", PKCS5_PBKDF1); +#endif + +#if defined(BOTAN_HAS_PBKDF2) + HANDLE_TYPE_ONE_STRING("PBKDF2", PKCS5_PBKDF2); +#endif + +#if defined(BOTAN_HAS_PGPS2K) + HANDLE_TYPE_ONE_STRING("OpenPGP-S2K", OpenPGP_S2K); +#endif + + return 0; + } + +/************************************************* +* Look for an algorithm with this name * +*************************************************/ +BlockCipherModePaddingMethod* +Default_Engine::find_bc_pad(const std::string& algo_spec) const + { + std::vector name = parse_algorithm_name(algo_spec); + if(name.empty()) + return 0; + + const std::string algo_name = global_state().deref_alias(name[0]); + +#if defined(BOTAN_HAS_CIPHER_MODE_PADDING) + HANDLE_TYPE_NO_ARGS("PKCS7", PKCS7_Padding); + HANDLE_TYPE_NO_ARGS("OneAndZeros", OneAndZeros_Padding); + HANDLE_TYPE_NO_ARGS("X9.23", ANSI_X923_Padding); + HANDLE_TYPE_NO_ARGS("NoPadding", Null_Padding); +#endif + + return 0; + } + +} diff --git a/src/core/libstate/def_mode.cpp b/src/core/libstate/def_mode.cpp new file mode 100644 index 000000000..b062cc34b --- /dev/null +++ b/src/core/libstate/def_mode.cpp @@ -0,0 +1,177 @@ +/************************************************* +* Default Engine Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include +#include +#include + +#if defined(BOTAN_HAS_ECB) + #include +#endif + +#if defined(BOTAN_HAS_CBC) + #include +#endif + +#if defined(BOTAN_HAS_CTS) + #include +#endif + +#if defined(BOTAN_HAS_CFB) + #include +#endif + +#if defined(BOTAN_HAS_OFB) + #include +#endif + +#if defined(BOTAN_HAS_CTR) + #include +#endif + +#if defined(BOTAN_HAS_EAX) + #include +#endif + +namespace Botan { + +/************************************************* +* Get a cipher object * +*************************************************/ +Keyed_Filter* Default_Engine::get_cipher(const std::string& algo_spec, + Cipher_Dir direction) + { + std::vector algo_parts = split_on(algo_spec, '/'); + if(algo_parts.empty()) + throw Invalid_Algorithm_Name(algo_spec); + + const std::string cipher = algo_parts[0]; + + if(have_stream_cipher(cipher)) + { + if(algo_parts.size() == 1) + return new StreamCipher_Filter(cipher); + return 0; + } + else if(have_block_cipher(cipher)) + { + if(algo_parts.size() != 2 && algo_parts.size() != 3) + return 0; + + std::string mode = algo_parts[1]; + u32bit bits = 0; + + if(mode.find("CFB") != std::string::npos || + mode.find("EAX") != std::string::npos) + { + std::vector algo_info = parse_algorithm_name(mode); + mode = algo_info[0]; + if(algo_info.size() == 1) + bits = 8*block_size_of(cipher); + else if(algo_info.size() == 2) + bits = to_u32bit(algo_info[1]); + else + throw Invalid_Algorithm_Name(algo_spec); + } + + std::string padding; + if(algo_parts.size() == 3) + padding = algo_parts[2]; + else + padding = (mode == "CBC") ? "PKCS7" : "NoPadding"; + + if(mode == "ECB" && padding == "CTS") + return 0; + else if((mode != "CBC" && mode != "ECB") && padding != "NoPadding") + throw Invalid_Algorithm_Name(algo_spec); + + if(mode == "OFB") + { +#if defined(BOTAN_HAS_OFB) + return new OFB(cipher); +#else + return 0; +#endif + } + else if(mode == "CTR-BE") + { +#if defined(BOTAN_HAS_CTR) + return new CTR_BE(cipher); +#else + return 0; +#endif + } + else if(mode == "ECB" || mode == "CBC" || mode == "CTS" || + mode == "CFB" || mode == "EAX") + { + if(mode == "ECB") + { +#if defined(BOTAN_HAS_ECB) + if(direction == ENCRYPTION) + return new ECB_Encryption(cipher, padding); + else + return new ECB_Decryption(cipher, padding); +#else + return 0; +#endif + } + else if(mode == "CFB") + { +#if defined(BOTAN_HAS_CFB) + if(direction == ENCRYPTION) + return new CFB_Encryption(cipher, bits); + else + return new CFB_Decryption(cipher, bits); +#else + return 0; +#endif + } + else if(mode == "CBC") + { + if(padding == "CTS") + { +#if defined(BOTAN_HAS_CTS) + if(direction == ENCRYPTION) + return new CTS_Encryption(cipher); + else + return new CTS_Decryption(cipher); +#else + return 0; +#endif + } + +#if defined(BOTAN_HAS_CBC) + if(direction == ENCRYPTION) + return new CBC_Encryption(cipher, padding); + else + return new CBC_Decryption(cipher, padding); +#else + return 0; +#endif + } + else if(mode == "EAX") + { +#if defined(BOTAN_HAS_EAX) + if(direction == ENCRYPTION) + return new EAX_Encryption(cipher, bits); + else + return new EAX_Decryption(cipher, bits); +#else + return 0; +#endif + } + else + throw Internal_Error("get_mode: " + cipher + "/" + + mode + "/" + padding); + } + else + return 0; + } + + return 0; + } + +} diff --git a/src/core/libstate/eng_base.cpp b/src/core/libstate/eng_base.cpp new file mode 100644 index 000000000..38234d462 --- /dev/null +++ b/src/core/libstate/eng_base.cpp @@ -0,0 +1,306 @@ +/************************************************* +* Basic No-Op Engine Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include +#include +#include + +namespace Botan { + +namespace { + +/************************************************* +* Algorithm Cache * +*************************************************/ +template +class Algorithm_Cache_Impl : public Engine::Algorithm_Cache + { + public: + T* get(const std::string& name) const + { + Mutex_Holder lock(mutex); + return search_map(mappings, name); + } + + void add(T* algo, const std::string& index_name = "") const + { + if(!algo) + return; + + Mutex_Holder lock(mutex); + + const std::string name = + (index_name != "" ? index_name : algo->name()); + + if(mappings.find(name) != mappings.end()) + delete mappings[name]; + mappings[name] = algo; + } + + Algorithm_Cache_Impl() + { + mutex = global_state().get_mutex(); + } + + ~Algorithm_Cache_Impl() + { + typename std::map::iterator i = mappings.begin(); + + while(i != mappings.end()) + { + delete i->second; + ++i; + } + delete mutex; + } + private: + Mutex* mutex; + mutable std::map mappings; + }; + +} + +/************************************************* +* Basic No-Op Engine Implementation * +*************************************************/ +IF_Operation* Engine::if_op(const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&) const + { + return 0; + } + +/************************************************* +* Basic No-Op Engine Implementation * +*************************************************/ +DSA_Operation* Engine::dsa_op(const DL_Group&, const BigInt&, + const BigInt&) const + { + return 0; + } + +/************************************************* +* Basic No-Op Engine Implementation * +*************************************************/ +NR_Operation* Engine::nr_op(const DL_Group&, const BigInt&, + const BigInt&) const + { + return 0; + } + +/************************************************* +* Basic No-Op Engine Implementation * +*************************************************/ +ELG_Operation* Engine::elg_op(const DL_Group&, const BigInt&, + const BigInt&) const + { + return 0; + } + +/************************************************* +* Basic No-Op Engine Implementation * +*************************************************/ +DH_Operation* Engine::dh_op(const DL_Group&, const BigInt&) const + { + return 0; + } + +/************************************************* +* Basic No-Op Engine Implementation * +*************************************************/ +Modular_Exponentiator* Engine::mod_exp(const BigInt&, + Power_Mod::Usage_Hints) const + { + return 0; + } + +/************************************************* +* Acquire a BlockCipher * +*************************************************/ +const BlockCipher* Engine::block_cipher(const std::string& name) const + { + return lookup_algo(cache_of_bc, global_state().deref_alias(name), + this, &Engine::find_block_cipher); + } + +/************************************************* +* Acquire a StreamCipher * +*************************************************/ +const StreamCipher* Engine::stream_cipher(const std::string& name) const + { + return lookup_algo(cache_of_sc, global_state().deref_alias(name), + this, &Engine::find_stream_cipher); + } + +/************************************************* +* Acquire a HashFunction * +*************************************************/ +const HashFunction* Engine::hash(const std::string& name) const + { + return lookup_algo(cache_of_hf, global_state().deref_alias(name), + this, &Engine::find_hash); + } + +/************************************************* +* Acquire a MessageAuthenticationCode * +*************************************************/ +const MessageAuthenticationCode* Engine::mac(const std::string& name) const + { + return lookup_algo(cache_of_mac, global_state().deref_alias(name), + this, &Engine::find_mac); + } + +/************************************************* +* Acquire a S2K object * +*************************************************/ +const S2K* Engine::s2k(const std::string& name) const + { + return lookup_algo(cache_of_s2k, global_state().deref_alias(name), + this, &Engine::find_s2k); + } + +/************************************************* +* Acquire a cipher padding object * +*************************************************/ +const BlockCipherModePaddingMethod* +Engine::bc_pad(const std::string& name) const + { + return lookup_algo(cache_of_bc_pad, global_state().deref_alias(name), + this, &Engine::find_bc_pad); + } + +/************************************************* +* Add a block cipher to the lookup table * +*************************************************/ +void Engine::add_algorithm(BlockCipher* algo) const + { + cache_of_bc->add(algo); + } + +/************************************************* +* Add a stream cipher to the lookup table * +*************************************************/ +void Engine::add_algorithm(StreamCipher* algo) const + { + cache_of_sc->add(algo); + } + +/************************************************* +* Add a hash function to the lookup table * +*************************************************/ +void Engine::add_algorithm(HashFunction* algo) const + { + cache_of_hf->add(algo); + } + +/************************************************* +* Add a MAC to the lookup table * +*************************************************/ +void Engine::add_algorithm(MessageAuthenticationCode* algo) const + { + cache_of_mac->add(algo); + } + +/************************************************* +* Add a S2K to the lookup table * +*************************************************/ +void Engine::add_algorithm(S2K* algo) const + { + cache_of_s2k->add(algo); + } + +/************************************************* +* Add a cipher pad method to the lookup table * +*************************************************/ +void Engine::add_algorithm(BlockCipherModePaddingMethod* algo) const + { + cache_of_bc_pad->add(algo); + } + +/************************************************* +* Create an Engine * +*************************************************/ +Engine::Engine() + { + cache_of_bc = new Algorithm_Cache_Impl(); + cache_of_sc = new Algorithm_Cache_Impl(); + cache_of_hf = new Algorithm_Cache_Impl(); + cache_of_mac = new Algorithm_Cache_Impl(); + cache_of_s2k = new Algorithm_Cache_Impl(); + cache_of_bc_pad = + new Algorithm_Cache_Impl(); + } + +/************************************************* +* Destroy an Engine * +*************************************************/ +Engine::~Engine() + { + delete cache_of_bc; + delete cache_of_sc; + delete cache_of_hf; + delete cache_of_mac; + delete cache_of_s2k; + delete cache_of_bc_pad; + } + +/************************************************* +* Basic No-Op Engine Implementation * +*************************************************/ +BlockCipher* Engine::find_block_cipher(const std::string&) const + { + return 0; + } + +/************************************************* +* Basic No-Op Engine Implementation * +*************************************************/ +StreamCipher* Engine::find_stream_cipher(const std::string&) const + { + return 0; + } + +/************************************************* +* Basic No-Op Engine Implementation * +*************************************************/ +HashFunction* Engine::find_hash(const std::string&) const + { + return 0; + } + +/************************************************* +* Basic No-Op Engine Implementation * +*************************************************/ +MessageAuthenticationCode* Engine::find_mac(const std::string&) const + { + return 0; + } + +/************************************************* +* Basic No-Op Engine Implementation * +*************************************************/ +S2K* Engine::find_s2k(const std::string&) const + { + return 0; + } + +/************************************************* +* Basic No-Op Engine Implementation * +*************************************************/ +BlockCipherModePaddingMethod* Engine::find_bc_pad(const std::string&) const + { + return 0; + } + +/************************************************* +* Basic No-Op Engine Implementation * +*************************************************/ +Keyed_Filter* Engine::get_cipher(const std::string&, Cipher_Dir) + { + return 0; + } + +} diff --git a/src/core/libstate/engine.cpp b/src/core/libstate/engine.cpp new file mode 100644 index 000000000..804ab3580 --- /dev/null +++ b/src/core/libstate/engine.cpp @@ -0,0 +1,382 @@ +/************************************************* +* Engine Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include +#include +#include +#include + +namespace Botan { + +namespace Engine_Core { + +/************************************************* +* Acquire an IF op * +*************************************************/ +IF_Operation* if_op(const BigInt& e, const BigInt& n, const BigInt& d, + const BigInt& p, const BigInt& q, const BigInt& d1, + const BigInt& d2, const BigInt& c) + { + Library_State::Engine_Iterator i(global_state()); + + while(const Engine* engine = i.next()) + { + IF_Operation* op = engine->if_op(e, n, d, p, q, d1, d2, c); + if(op) + return op; + } + + throw Lookup_Error("Engine_Core::if_op: Unable to find a working engine"); + } + +/************************************************* +* Acquire a DSA op * +*************************************************/ +DSA_Operation* dsa_op(const DL_Group& group, const BigInt& y, const BigInt& x) + { + Library_State::Engine_Iterator i(global_state()); + + while(const Engine* engine = i.next()) + { + DSA_Operation* op = engine->dsa_op(group, y, x); + if(op) + return op; + } + + throw Lookup_Error("Engine_Core::dsa_op: Unable to find a working engine"); + } + +/************************************************* +* Acquire a NR op * +*************************************************/ +NR_Operation* nr_op(const DL_Group& group, const BigInt& y, const BigInt& x) + { + Library_State::Engine_Iterator i(global_state()); + + while(const Engine* engine = i.next()) + { + NR_Operation* op = engine->nr_op(group, y, x); + if(op) + return op; + } + + throw Lookup_Error("Engine_Core::nr_op: Unable to find a working engine"); + } + +/************************************************* +* Acquire an ElGamal op * +*************************************************/ +ELG_Operation* elg_op(const DL_Group& group, const BigInt& y, const BigInt& x) + { + Library_State::Engine_Iterator i(global_state()); + + while(const Engine* engine = i.next()) + { + ELG_Operation* op = engine->elg_op(group, y, x); + if(op) + return op; + } + + throw Lookup_Error("Engine_Core::elg_op: Unable to find a working engine"); + } + +/************************************************* +* Acquire a DH op * +*************************************************/ +DH_Operation* dh_op(const DL_Group& group, const BigInt& x) + { + Library_State::Engine_Iterator i(global_state()); + + while(const Engine* engine = i.next()) + { + DH_Operation* op = engine->dh_op(group, x); + if(op) + return op; + } + + throw Lookup_Error("Engine_Core::dh_op: Unable to find a working engine"); + } + +/************************************************* +* Acquire a modular exponentiator * +*************************************************/ +Modular_Exponentiator* mod_exp(const BigInt& n, Power_Mod::Usage_Hints hints) + { + Library_State::Engine_Iterator i(global_state()); + + while(const Engine* engine = i.next()) + { + Modular_Exponentiator* op = engine->mod_exp(n, hints); + + if(op) + return op; + } + + throw Lookup_Error("Engine_Core::mod_exp: Unable to find a working engine"); + } + +} + +/************************************************* +* Acquire a block cipher * +*************************************************/ +const BlockCipher* retrieve_block_cipher(Library_State& libstate, + const std::string& name) + { + Library_State::Engine_Iterator i(libstate); + + while(const Engine* engine = i.next()) + { + const BlockCipher* algo = engine->block_cipher(name); + if(algo) + return algo; + } + + return 0; + } + +/************************************************* +* Acquire a stream cipher * +*************************************************/ +const StreamCipher* retrieve_stream_cipher(Library_State& libstate, + const std::string& name) + { + Library_State::Engine_Iterator i(libstate); + + while(const Engine* engine = i.next()) + { + const StreamCipher* algo = engine->stream_cipher(name); + if(algo) + return algo; + } + + return 0; + } + +/************************************************* +* Acquire a hash function * +*************************************************/ +const HashFunction* retrieve_hash(Library_State& libstate, + const std::string& name) + { + Library_State::Engine_Iterator i(libstate); + + while(const Engine* engine = i.next()) + { + const HashFunction* algo = engine->hash(name); + if(algo) + return algo; + } + + return 0; + } + +/************************************************* +* Acquire an authentication code * +*************************************************/ +const MessageAuthenticationCode* retrieve_mac(Library_State& libstate, + const std::string& name) + { + Library_State::Engine_Iterator i(libstate); + + while(const Engine* engine = i.next()) + { + const MessageAuthenticationCode* algo = engine->mac(name); + if(algo) + return algo; + } + + return 0; + } + +/************************************************* +* Acquire a string-to-key algorithm * +*************************************************/ +const S2K* retrieve_s2k(Library_State& libstate, + const std::string& name) + { + Library_State::Engine_Iterator i(libstate); + + while(const Engine* engine = i.next()) + { + const S2K* algo = engine->s2k(name); + if(algo) + return algo; + } + + return 0; + } + +/************************************************* +* Retrieve a block cipher padding method * +*************************************************/ +const BlockCipherModePaddingMethod* retrieve_bc_pad(Library_State& libstate, + const std::string& name) + { + Library_State::Engine_Iterator i(libstate); + + while(const Engine* engine = i.next()) + { + const BlockCipherModePaddingMethod* algo = engine->bc_pad(name); + if(algo) + return algo; + } + + return 0; + } + +/************************************************* +* Add a new block cipher * +*************************************************/ +void add_algorithm(Library_State& libstate, BlockCipher* algo) + { + Library_State::Engine_Iterator i(libstate); + + while(Engine* engine_base = i.next()) + { + Default_Engine* engine = dynamic_cast(engine_base); + if(engine) + { + engine->add_algorithm(algo); + return; + } + } + + throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); + } + +/************************************************* +* Add a new stream cipher * +*************************************************/ +void add_algorithm(Library_State& libstate, StreamCipher* algo) + { + Library_State::Engine_Iterator i(libstate); + + while(Engine* engine_base = i.next()) + { + Default_Engine* engine = dynamic_cast(engine_base); + if(engine) + { + engine->add_algorithm(algo); + return; + } + } + + throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); + } + +/************************************************* +* Add a new hash function * +*************************************************/ +void add_algorithm(Library_State& libstate, HashFunction* algo) + { + Library_State::Engine_Iterator i(libstate); + + while(Engine* engine_base = i.next()) + { + Default_Engine* engine = dynamic_cast(engine_base); + if(engine) + { + engine->add_algorithm(algo); + return; + } + } + + throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); + } + +/************************************************* +* Add a new authentication code * +*************************************************/ +void add_algorithm(Library_State& libstate, + MessageAuthenticationCode* algo) + { + Library_State::Engine_Iterator i(libstate); + + while(Engine* engine_base = i.next()) + { + Default_Engine* engine = dynamic_cast(engine_base); + if(engine) + { + engine->add_algorithm(algo); + return; + } + } + + throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); + } + +/************************************************* +* Add a padding method to the lookup table * +*************************************************/ +void add_algorithm(Library_State& libstate, + BlockCipherModePaddingMethod* algo) + { + Library_State::Engine_Iterator i(libstate); + + while(Engine* engine_base = i.next()) + { + Default_Engine* engine = dynamic_cast(engine_base); + if(engine) + { + engine->add_algorithm(algo); + return; + } + } + + throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); + } + +/************************************************* +* Get a cipher object * +*************************************************/ +Keyed_Filter* get_cipher(Library_State& libstate, + const std::string& algo_spec, + Cipher_Dir direction) + { + Library_State::Engine_Iterator i(libstate); + + while(Engine* engine = i.next()) + { + Keyed_Filter* algo = engine->get_cipher(algo_spec, direction); + if(algo) + return algo; + } + + throw Algorithm_Not_Found(algo_spec); + } + +/************************************************* +* Get a cipher object * +*************************************************/ +Keyed_Filter* get_cipher(Library_State& libstate, + const std::string& algo_spec, + const SymmetricKey& key, + const InitializationVector& iv, + Cipher_Dir direction) + { + Keyed_Filter* cipher = get_cipher(libstate, algo_spec, direction); + cipher->set_key(key); + + if(iv.length()) + cipher->set_iv(iv); + + return cipher; + } + +/************************************************* +* Get a cipher object * +*************************************************/ +Keyed_Filter* get_cipher(Library_State& libstate, + const std::string& algo_spec, + const SymmetricKey& key, + Cipher_Dir direction) + { + return get_cipher(libstate, algo_spec, + key, InitializationVector(), direction); + } + +} diff --git a/src/core/libstate/engine.h b/src/core/libstate/engine.h new file mode 100644 index 000000000..13007e662 --- /dev/null +++ b/src/core/libstate/engine.h @@ -0,0 +1,123 @@ +/************************************************* +* Engine Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_ENGINE_H__ +#define BOTAN_ENGINE_H__ + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Botan { + +/************************************************* +* Engine Base Class * +*************************************************/ +class BOTAN_DLL Engine + { + public: + template + class BOTAN_DLL Algorithm_Cache + { + public: + virtual T* get(const std::string&) const = 0; + virtual void add(T* algo, const std::string& = "") const = 0; + virtual ~Algorithm_Cache() {} + }; + + virtual IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&) const; + virtual DSA_Operation* dsa_op(const DL_Group&, const BigInt&, + const BigInt&) const; + virtual NR_Operation* nr_op(const DL_Group&, const BigInt&, + const BigInt&) const; + virtual ELG_Operation* elg_op(const DL_Group&, const BigInt&, + const BigInt&) const; + virtual DH_Operation* dh_op(const DL_Group&, const BigInt&) const; + + virtual Modular_Exponentiator* mod_exp(const BigInt&, + Power_Mod::Usage_Hints) const; + + virtual Keyed_Filter* get_cipher(const std::string&, Cipher_Dir); + + const BlockCipher* block_cipher(const std::string&) const; + const StreamCipher* stream_cipher(const std::string&) const; + const HashFunction* hash(const std::string&) const; + const MessageAuthenticationCode* mac(const std::string&) const; + const class S2K* s2k(const std::string&) const; + const class BlockCipherModePaddingMethod* + bc_pad(const std::string&) const; + + void add_algorithm(BlockCipher*) const; + void add_algorithm(StreamCipher*) const; + void add_algorithm(HashFunction*) const; + void add_algorithm(MessageAuthenticationCode*) const; + void add_algorithm(class S2K*) const; + void add_algorithm(class BlockCipherModePaddingMethod*) const; + + Engine(); + virtual ~Engine(); + private: + virtual BlockCipher* find_block_cipher(const std::string&) const; + virtual StreamCipher* find_stream_cipher(const std::string&) const; + virtual HashFunction* find_hash(const std::string&) const; + virtual MessageAuthenticationCode* find_mac(const std::string&) const; + virtual class S2K* find_s2k(const std::string&) const; + virtual class BlockCipherModePaddingMethod* + find_bc_pad(const std::string&) const; + + template + const T* lookup_algo(const Algorithm_Cache* cache, + const std::string& name, + const Engine* engine, + T* (Engine::*find)(const std::string&) const) const + { + T* algo = cache->get(name); + if(!algo) + { + algo = (engine->*find)(name); + if(algo) + cache->add(algo, name); + } + return algo; + } + + Algorithm_Cache* cache_of_bc; + Algorithm_Cache* cache_of_sc; + Algorithm_Cache* cache_of_hf; + Algorithm_Cache* cache_of_mac; + Algorithm_Cache* cache_of_bc_pad; + Algorithm_Cache* cache_of_s2k; + }; + +namespace Engine_Core { + +/************************************************* +* Get an operation from an Engine * +*************************************************/ +Modular_Exponentiator* mod_exp(const BigInt&, Power_Mod::Usage_Hints); + +IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&); + +DSA_Operation* dsa_op(const DL_Group&, const BigInt&, const BigInt&); +NR_Operation* nr_op(const DL_Group&, const BigInt&, const BigInt&); + +ELG_Operation* elg_op(const DL_Group&, const BigInt&, const BigInt&); + +DH_Operation* dh_op(const DL_Group&, const BigInt&); + +} + +} + +#endif diff --git a/src/core/libstate/get_enc.cpp b/src/core/libstate/get_enc.cpp new file mode 100644 index 000000000..fb5952a3e --- /dev/null +++ b/src/core/libstate/get_enc.cpp @@ -0,0 +1,219 @@ +/************************************************* +* EMSA/EME/KDF/MGF Retrieval Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include +#include +#include + +#if defined(BOTAN_HAS_MGF1) + #include +#endif + +#if defined(BOTAN_HAS_EMSA1) + #include +#endif + +#if defined(BOTAN_HAS_EMSA2) + #include +#endif + +#if defined(BOTAN_HAS_EMSA3) + #include +#endif + +#if defined(BOTAN_HAS_EMSA4) + #include +#endif + +#if defined(BOTAN_HAS_EMSA_RAW) + #include +#endif + +#if defined(BOTAN_HAS_EME1) + #include +#endif + +#if defined(BOTAN_HAS_EME_PKCS1v15) + #include +#endif + +#if defined(BOTAN_HAS_KDF1) + #include +#endif + +#if defined(BOTAN_HAS_KDF2) + #include +#endif + +#if defined(BOTAN_HAS_X942_PRF) + #include +#endif + +#if defined(BOTAN_HAS_SSL_V3_PRF) + #include +#endif + +#if defined(BOTAN_HAS_TLS_V10_PRF) + #include +#endif + +namespace Botan { + +/************************************************* +* Get an EMSA by name * +*************************************************/ +EMSA* get_emsa(const std::string& algo_spec) + { + std::vector name = parse_algorithm_name(algo_spec); + const std::string emsa_name = global_state().deref_alias(name[0]); + +#if defined(BOTAN_HAS_EMSA_RAW) + if(emsa_name == "Raw") + { + if(name.size() == 1) + return new EMSA_Raw; + } +#endif + +#if defined(BOTAN_HAS_EMSA1) + if(emsa_name == "EMSA1") + { + if(name.size() == 2) + return new EMSA1(name[1]); + } +#endif + +#if defined(BOTAN_HAS_EMSA2) + if(emsa_name == "EMSA2") + { + if(name.size() == 2) + return new EMSA2(name[1]); + } +#endif + +#if defined(BOTAN_HAS_EMSA3) + if(emsa_name == "EMSA3") + { + if(name.size() == 2) + return new EMSA3(name[1]); + } +#endif + +#if defined(BOTAN_HAS_EMSA4) + if(emsa_name == "EMSA4") + { + if(name.size() == 2) + return new EMSA4(name[1], "MGF1"); + if(name.size() == 3) + return new EMSA4(name[1], name[2]); + if(name.size() == 4) + return new EMSA4(name[1], name[2], to_u32bit(name[3])); + } +#endif + + throw Algorithm_Not_Found(algo_spec); + } + +/************************************************* +* Get an EME by name * +*************************************************/ +EME* get_eme(const std::string& algo_spec) + { + std::vector name = parse_algorithm_name(algo_spec); + const std::string eme_name = global_state().deref_alias(name[0]); + +#if defined(BOTAN_HAS_EME_PKCS1v15) + if(eme_name == "PKCS1v15") + { + if(name.size() == 1) + return new EME_PKCS1v15; + } +#endif + +#if defined(BOTAN_HAS_EME1) + if(eme_name == "EME1") + { + if(name.size() == 2) + return new EME1(name[1], "MGF1"); + if(name.size() == 3) + return new EME1(name[1], name[2]); + } +#endif + + throw Algorithm_Not_Found(algo_spec); + } + +/************************************************* +* Get an KDF by name * +*************************************************/ +KDF* get_kdf(const std::string& algo_spec) + { + std::vector name = parse_algorithm_name(algo_spec); + const std::string kdf_name = global_state().deref_alias(name[0]); + +#if defined(BOTAN_HAS_KDF1) + if(kdf_name == "KDF1") + { + if(name.size() == 2) + return new KDF1(name[1]); + } +#endif + +#if defined(BOTAN_HAS_KDF2) + if(kdf_name == "KDF2") + { + if(name.size() == 2) + return new KDF2(name[1]); + } +#endif + +#if defined(BOTAN_HAS_X942_PRF) + if(kdf_name == "X9.42-PRF") + { + if(name.size() == 2) + return new X942_PRF(name[1]); + } +#endif + +#if defined(BOTAN_HAS_TLS_V10_PRF) + if(kdf_name == "TLS-PRF") + { + if(name.size() == 1) + return new TLS_PRF; + } +#endif + +#if defined(BOTAN_HAS_SSL_V3_PRF) + if(kdf_name == "SSL3-PRF") + { + if(name.size() == 1) + return new SSL3_PRF; + } +#endif + + throw Algorithm_Not_Found(algo_spec); + } + +/************************************************* +* Get a MGF by name * +*************************************************/ +MGF* get_mgf(const std::string& algo_spec) + { + std::vector name = parse_algorithm_name(algo_spec); + const std::string mgf_name = global_state().deref_alias(name[0]); + +#ifdef BOTAN_HAS_MGF1 + if(mgf_name == "MGF1") + { + if(name.size() == 2) + return new MGF1(get_hash(name[1])); + } +#endif + + throw Algorithm_Not_Found(algo_spec); + } + +} diff --git a/src/core/libstate/get_pbe.cpp b/src/core/libstate/get_pbe.cpp new file mode 100644 index 000000000..cd1ed2aa4 --- /dev/null +++ b/src/core/libstate/get_pbe.cpp @@ -0,0 +1,87 @@ +/************************************************* +* PBE Retrieval Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include +#include + +#if defined(BOTAN_HAS_PBE_PKCS_V15) + #include +#endif + +#if defined(BOTAN_HAS_PBE_PKCS_V20) + #include +#endif + +namespace Botan { + +/************************************************* +* Get an encryption PBE, set new parameters * +*************************************************/ +PBE* get_pbe(const std::string& pbe_name) + { + std::vector algo_name; + algo_name = parse_algorithm_name(pbe_name); + + if(algo_name.size() != 3) + throw Invalid_Algorithm_Name(pbe_name); + + const std::string pbe = algo_name[0]; + const std::string digest = algo_name[1]; + const std::string cipher = algo_name[2]; + + PBE* pbe_obj = 0; + +#if defined(BOTAN_HAS_PBE_PKCS_V15) + if(!pbe_obj && pbe == "PBE-PKCS5v15") + pbe_obj = new PBE_PKCS5v15(digest, cipher, ENCRYPTION); +#endif + +#if defined(BOTAN_HAS_PBE_PKCS_V20) + if(!pbe_obj && pbe == "PBE-PKCS5v20") + pbe_obj = new PBE_PKCS5v20(digest, cipher); +#endif + + if(!pbe_obj) + throw Algorithm_Not_Found(pbe_name); + + return pbe_obj; + } + +/************************************************* +* Get a decryption PBE, decode parameters * +*************************************************/ +PBE* get_pbe(const OID& pbe_oid, DataSource& params) + { + std::vector algo_name; + algo_name = parse_algorithm_name(OIDS::lookup(pbe_oid)); + + if(algo_name.size() < 1) + throw Invalid_Algorithm_Name(pbe_oid.as_string()); + const std::string pbe_algo = algo_name[0]; + + if(pbe_algo == "PBE-PKCS5v15") + { +#if defined(BOTAN_HAS_PBE_PKCS_V15) + if(algo_name.size() != 3) + throw Invalid_Algorithm_Name(pbe_oid.as_string()); + const std::string digest = algo_name[1]; + const std::string cipher = algo_name[2]; + PBE* pbe = new PBE_PKCS5v15(digest, cipher, DECRYPTION); + pbe->decode_params(params); + return pbe; +#endif + } + else if(pbe_algo == "PBE-PKCS5v20") + { +#if defined(BOTAN_HAS_PBE_PKCS_V20) + return new PBE_PKCS5v20(params); +#endif + } + + throw Algorithm_Not_Found(pbe_oid.as_string()); + } + +} diff --git a/src/core/libstate/get_pbe.h b/src/core/libstate/get_pbe.h new file mode 100644 index 000000000..e7b434c1f --- /dev/null +++ b/src/core/libstate/get_pbe.h @@ -0,0 +1,22 @@ +/************************************************* +* PBE Lookup Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_LOOKUP_PBE_H__ +#define BOTAN_LOOKUP_PBE_H__ + +#include +#include + +namespace Botan { + +/************************************************* +* Get a PBE object * +*************************************************/ +BOTAN_DLL PBE* get_pbe(const std::string&); +BOTAN_DLL PBE* get_pbe(const OID&, DataSource&); + +} + +#endif diff --git a/src/core/libstate/info.txt b/src/core/libstate/info.txt new file mode 100644 index 000000000..f0040a688 --- /dev/null +++ b/src/core/libstate/info.txt @@ -0,0 +1,34 @@ +realname "Botan Core Module" + +load_on auto + +define CORE_MODULE + + +aes +sha1 + + + +def_alg.cpp +def_mode.cpp +eng_base.cpp +engine.cpp +get_enc.cpp +get_pbe.cpp +init.h +init_def.cpp +init_opt.cpp +libstate.cpp +look_pk.cpp +lookup.cpp +oids.cpp +policy.cpp +engine.h +get_pbe.h +libstate.h +look_add.h +look_pk.h +lookup.h +oids.h + diff --git a/src/core/libstate/init.h b/src/core/libstate/init.h new file mode 100644 index 000000000..f4296a868 --- /dev/null +++ b/src/core/libstate/init.h @@ -0,0 +1,50 @@ +/************************************************* +* Library Initialization Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_INIT_H__ +#define BOTAN_INIT_H__ + +#include +#include +#include + +namespace Botan { + +/************************************************* +* Options for initializing the library * +*************************************************/ +class BOTAN_DLL InitializerOptions + { + public: + bool thread_safe() const; + bool use_engines() const; + bool secure_memory() const; + bool fips_mode() const; + bool self_test() const; + + InitializerOptions(const std::string&); + private: + std::map args; + }; + +/************************************************* +* Library Initialization/Shutdown Object * +*************************************************/ +class BOTAN_DLL LibraryInitializer + { + public: + static void initialize(const std::string& = ""); + static void initialize(const InitializerOptions&); + static void initialize(const InitializerOptions&, class Modules&); + static void deinitialize(); + + LibraryInitializer(const std::string& args = "") { initialize(args); } + LibraryInitializer(const InitializerOptions& args) { initialize(args); } + ~LibraryInitializer() { deinitialize(); } + }; + +} + +#endif diff --git a/src/core/libstate/init_def.cpp b/src/core/libstate/init_def.cpp new file mode 100644 index 000000000..03f97252e --- /dev/null +++ b/src/core/libstate/init_def.cpp @@ -0,0 +1,60 @@ +/************************************************* +* Default Initialization Function Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include +#include + +namespace Botan { + +/************************************************* +* Library Initialization * +*************************************************/ +void LibraryInitializer::initialize(const InitializerOptions& args, + Modules& modules) + { + try + { + set_global_state(new Library_State); + + global_state().initialize(args, modules); + } + catch(...) + { + deinitialize(); + throw; + } + } + +/************************************************* +* Library Shutdown * +*************************************************/ +void LibraryInitializer::deinitialize() + { + set_global_state(0); + } + +/************************************************* +* Library Initialization * +*************************************************/ +void LibraryInitializer::initialize(const std::string& arg_string) + { + InitializerOptions args(arg_string); + Builtin_Modules modules(args); + + initialize(args, modules); + } + +/************************************************* +* Library Initialization * +*************************************************/ +void LibraryInitializer::initialize(const InitializerOptions& args) + { + Builtin_Modules modules(args); + + initialize(args, modules); + } + +} diff --git a/src/core/libstate/init_opt.cpp b/src/core/libstate/init_opt.cpp new file mode 100644 index 000000000..5c4fbee65 --- /dev/null +++ b/src/core/libstate/init_opt.cpp @@ -0,0 +1,102 @@ +/************************************************* +* Initialization Options Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include +#include +#include + +namespace Botan { + +namespace { + +/************************************************* +* Check for an arbitrary boolean-valued option * +*************************************************/ +bool boolean_arg(const std::map& args, + const std::string& key, bool not_found = false) + { + std::map::const_iterator i = args.find(key); + if(i == args.end()) + return not_found; + + std::string value = i->second; + + if(value == "1" || value == "true" || value == "yes" || value == "on") + return true; + if(value == "0" || value == "false" || value == "no" || value == "off") + return false; + if(value == "default") + return not_found; + + throw Invalid_Argument("InitializerOptions: Bad argument for boolean " + + key + " of '" + value + "'"); + } + +} + +/************************************************* +* Check if thread safety was requested * +*************************************************/ +bool InitializerOptions::thread_safe() const + { + return boolean_arg(args, "thread_safe"); + } + +/************************************************* +* Check if secure allocation was requested * +*************************************************/ +bool InitializerOptions::secure_memory() const + { + return boolean_arg(args, "secure_memory"); + } + +/************************************************* +* Check if using engines was requested * +*************************************************/ +bool InitializerOptions::use_engines() const + { + return boolean_arg(args, "use_engines"); + } + +/************************************************* +* Check if FIPS mode was requested * +*************************************************/ +bool InitializerOptions::fips_mode() const + { + return boolean_arg(args, "fips140"); + } + +/************************************************* +* Check if startup self tests were requested * +*************************************************/ +bool InitializerOptions::self_test() const + { + return boolean_arg(args, "selftest", true); + } + +/************************************************* +* Setup an InitializerOptions * +*************************************************/ +InitializerOptions::InitializerOptions(const std::string& arg_string) + { + 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; + + if(arg_list[j].find('=') == std::string::npos) + args[arg_list[j]] = "true"; + else + { + std::vector name_and_value = split_on(arg_list[j], '='); + args[name_and_value[0]] = name_and_value[1]; + } + } + } + +} diff --git a/src/core/libstate/libstate.cpp b/src/core/libstate/libstate.cpp new file mode 100644 index 000000000..60bb24fee --- /dev/null +++ b/src/core/libstate/libstate.cpp @@ -0,0 +1,294 @@ +/************************************************* +* Library Internal/Global State Source File * +* (C) 1999-2008 Jack Lloyd * +*************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(BOTAN_HAS_SELFTEST) + #include +#endif + +namespace Botan { + +/************************************************* +* Botan's global state * +*************************************************/ +namespace { + +Library_State* global_lib_state = 0; + +} + +/************************************************* +* Access the global state object * +*************************************************/ +Library_State& global_state() + { + if(!global_lib_state) + LibraryInitializer::initialize(); + return (*global_lib_state); + } + +/************************************************* +* Set a new global state object * +*************************************************/ +void set_global_state(Library_State* new_state) + { + delete swap_global_state(new_state); + } + +/************************************************* +* Swap two global state objects * +*************************************************/ +Library_State* swap_global_state(Library_State* new_state) + { + Library_State* old_state = global_lib_state; + global_lib_state = new_state; + return old_state; + } + +/************************************************* +* Increment the Engine iterator * +*************************************************/ +Engine* Library_State::Engine_Iterator::next() + { + return lib.get_engine_n(n++); + } + +/************************************************* +* 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 + { + Mutex_Holder lock(allocator_lock); + + if(type != "") + return search_map(alloc_factory, type, 0); + + if(!cached_default_allocator) + { + std::string chosen = this->option("base/default_allocator"); + + if(chosen == "") + chosen = "malloc"; + + cached_default_allocator = + search_map(alloc_factory, chosen, 0); + } + + return cached_default_allocator; + } + +/************************************************* +* Create a new name to object mapping * +*************************************************/ +void Library_State::add_allocator(Allocator* allocator) + { + Mutex_Holder lock(allocator_lock); + + allocator->init(); + + allocators.push_back(allocator); + alloc_factory[allocator->type()] = allocator; + } + +/************************************************* +* Set the default allocator type * +*************************************************/ +void Library_State::set_default_allocator(const std::string& type) + { + Mutex_Holder lock(allocator_lock); + + if(type == "") + return; + + this->set("conf", "base/default_allocator", type); + cached_default_allocator = 0; + } + +/************************************************* +* Get an engine out of the list * +*************************************************/ +Engine* Library_State::get_engine_n(u32bit n) const + { + Mutex_Holder lock(engine_lock); + + if(n >= engines.size()) + return 0; + return engines[n]; + } + +/************************************************* +* Add a new engine to the list * +*************************************************/ +void Library_State::add_engine(Engine* engine) + { + Mutex_Holder lock(engine_lock); + engines.insert(engines.begin(), engine); + } + +/************************************************* +* Get a configuration value * +*************************************************/ +std::string Library_State::get(const std::string& section, + const std::string& key) const + { + Mutex_Holder lock(config_lock); + + return search_map(config, + section + "/" + key, ""); + } + +/************************************************* +* See if a particular option has been set * +*************************************************/ +bool Library_State::is_set(const std::string& section, + const std::string& key) const + { + Mutex_Holder lock(config_lock); + + return search_map(config, section + "/" + key, false, true); + } + +/************************************************* +* Set a configuration value * +*************************************************/ +void Library_State::set(const std::string& section, const std::string& key, + const std::string& value, bool overwrite) + { + Mutex_Holder lock(config_lock); + + std::string full_key = section + "/" + key; + + std::map::const_iterator i = + config.find(full_key); + + if(overwrite || i == config.end() || i->second == "") + config[full_key] = value; + } + +/************************************************* +* Add an alias * +*************************************************/ +void Library_State::add_alias(const std::string& key, const std::string& value) + { + set("alias", key, value); + } + +/************************************************* +* Dereference an alias to a fixed name * +*************************************************/ +std::string Library_State::deref_alias(const std::string& key) const + { + std::string result = key; + while(is_set("alias", result)) + result = get("alias", result); + return result; + } + +/************************************************* +* Set/Add an option * +*************************************************/ +void Library_State::set_option(const std::string key, + const std::string& value) + { + set("conf", key, value); + } + +/************************************************* +* Get an option value * +*************************************************/ +std::string Library_State::option(const std::string& key) const + { + return get("conf", key); + } + +/************************************************* +* Load a set of modules * +*************************************************/ +void Library_State::initialize(const InitializerOptions& args, + Modules& modules) + { + if(mutex_factory) + throw Invalid_State("Library_State has already been initialized"); + + mutex_factory = modules.mutex_factory(args.thread_safe()); + + if(!mutex_factory) + throw Invalid_State("Could not acquire a mutex module at init"); + + allocator_lock = get_mutex(); + engine_lock = get_mutex(); + config_lock = get_mutex(); + + cached_default_allocator = 0; + + std::vector mod_allocs = modules.allocators(mutex_factory); + for(u32bit j = 0; j != mod_allocs.size(); ++j) + add_allocator(mod_allocs[j]); + + set_default_allocator(modules.default_allocator()); + + load_default_config(); + + std::vector mod_engines = modules.engines(); + for(u32bit j = 0; j != mod_engines.size(); ++j) + engines.push_back(mod_engines[j]); + +#if defined(BOTAN_HAS_SELFTEST) + if(args.fips_mode() || args.self_test()) + { + if(!passes_self_tests()) + throw Self_Test_Failure("Initialization self-tests"); + } +#endif + } + +/************************************************* +* Library_State Constructor * +*************************************************/ +Library_State::Library_State() + { + mutex_factory = 0; + allocator_lock = engine_lock = config_lock = 0; + cached_default_allocator = 0; + } + +/************************************************* +* Library_State Destructor * +*************************************************/ +Library_State::~Library_State() + { + std::for_each(engines.begin(), engines.end(), del_fun()); + + cached_default_allocator = 0; + + for(u32bit j = 0; j != allocators.size(); ++j) + { + allocators[j]->destroy(); + delete allocators[j]; + } + + delete allocator_lock; + delete engine_lock; + delete mutex_factory; + delete config_lock; + } + +} diff --git a/src/core/libstate/libstate.h b/src/core/libstate/libstate.h new file mode 100644 index 000000000..4b1221c84 --- /dev/null +++ b/src/core/libstate/libstate.h @@ -0,0 +1,90 @@ +/************************************************* +* Library Internal/Global State Header File * +* (C) 1999-2008 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_LIB_STATE_H__ +#define BOTAN_LIB_STATE_H__ + +#include +#include +#include +#include +#include + +namespace Botan { + +/************************************************* +* Global State Container Base * +*************************************************/ +class BOTAN_DLL Library_State + { + public: + Library_State(); + ~Library_State(); + + void initialize(const InitializerOptions&, Modules&); + + void load(Modules&); + + void add_engine(class Engine*); + + class BOTAN_DLL Engine_Iterator + { + public: + class Engine* next(); + Engine_Iterator(const Library_State& l) : lib(l) { n = 0; } + private: + const Library_State& lib; + u32bit n; + }; + friend class Engine_Iterator; + + Allocator* get_allocator(const std::string& = "") const; + void add_allocator(Allocator*); + void set_default_allocator(const std::string&); + + std::string get(const std::string&, const std::string&) const; + bool is_set(const std::string&, const std::string&) const; + void set(const std::string&, const std::string&, + const std::string&, bool = true); + + std::string option(const std::string&) const; + void set_option(const std::string, const std::string&); + + void add_alias(const std::string&, const std::string&); + std::string deref_alias(const std::string&) const; + + class Mutex* get_mutex() const; + private: + void load_default_config(); + + Library_State(const Library_State&) {} + Library_State& operator=(const Library_State&) { return (*this); } + + class Engine* get_engine_n(u32bit) const; + + class Mutex_Factory* mutex_factory; + + std::map config; + class Mutex* config_lock; + + class Mutex* allocator_lock; + std::map alloc_factory; + mutable Allocator* cached_default_allocator; + std::vector allocators; + + class Mutex* engine_lock; + std::vector engines; + }; + +/************************************************* +* Global State * +*************************************************/ +BOTAN_DLL Library_State& global_state(); +BOTAN_DLL void set_global_state(Library_State*); +BOTAN_DLL Library_State* swap_global_state(Library_State*); + +} + +#endif diff --git a/src/core/libstate/look_add.h b/src/core/libstate/look_add.h new file mode 100644 index 000000000..8c170049d --- /dev/null +++ b/src/core/libstate/look_add.h @@ -0,0 +1,28 @@ +/************************************************* +* Lookup Table Management Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_LOOKUP_MANGEMENT_H__ +#define BOTAN_LOOKUP_MANGEMENT_H__ + +#include +#include +#include +#include + +namespace Botan { + +/************************************************* +* Add an algorithm to the lookup table * +*************************************************/ +BOTAN_DLL void add_algorithm(Library_State&, BlockCipher*); +BOTAN_DLL void add_algorithm(Library_State&, StreamCipher*); +BOTAN_DLL void add_algorithm(Library_State&, HashFunction*); +BOTAN_DLL void add_algorithm(Library_State&, MessageAuthenticationCode*); +BOTAN_DLL void add_algorithm(Library_State&, S2K*); +BOTAN_DLL void add_algorithm(Library_State&, BlockCipherModePaddingMethod*); + +} + +#endif diff --git a/src/core/libstate/look_pk.cpp b/src/core/libstate/look_pk.cpp new file mode 100644 index 000000000..a4062b57c --- /dev/null +++ b/src/core/libstate/look_pk.cpp @@ -0,0 +1,74 @@ +/************************************************* +* PK Algorithm Lookup Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include + +namespace Botan { + +/************************************************* +* Get a PK_Encryptor object * +*************************************************/ +PK_Encryptor* get_pk_encryptor(const PK_Encrypting_Key& key, + const std::string& eme) + { + return new PK_Encryptor_MR_with_EME(key, eme); + } + +/************************************************* +* Get a PK_Decryptor object * +*************************************************/ +PK_Decryptor* get_pk_decryptor(const PK_Decrypting_Key& key, + const std::string& eme) + { + return new PK_Decryptor_MR_with_EME(key, eme); + } + +/************************************************* +* Get a PK_Signer object * +*************************************************/ +PK_Signer* get_pk_signer(const PK_Signing_Key& key, + const std::string& encoding, + Signature_Format sig_format) + { + PK_Signer* signer = new PK_Signer(key, encoding); + signer->set_output_format(sig_format); + return signer; + } + +/************************************************* +* Get a PK_Verifier object * +*************************************************/ +PK_Verifier* get_pk_verifier(const PK_Verifying_with_MR_Key& key, + const std::string& encoding, + Signature_Format sig_format) + { + PK_Verifier* verifier = new PK_Verifier_with_MR(key, encoding); + verifier->set_input_format(sig_format); + return verifier; + } + +/************************************************* +* Get a PK_Verifier object * +*************************************************/ +PK_Verifier* get_pk_verifier(const PK_Verifying_wo_MR_Key& key, + const std::string& encoding, + Signature_Format sig_format) + { + PK_Verifier* verifier = new PK_Verifier_wo_MR(key, encoding); + verifier->set_input_format(sig_format); + return verifier; + } + +/************************************************* +* Get a PK_Key_Agreement object * +*************************************************/ +PK_Key_Agreement* get_pk_kas(const PK_Key_Agreement_Key& key, + const std::string& kdf) + { + return new PK_Key_Agreement(key, kdf); + } + +} diff --git a/src/core/libstate/look_pk.h b/src/core/libstate/look_pk.h new file mode 100644 index 000000000..63756ad22 --- /dev/null +++ b/src/core/libstate/look_pk.h @@ -0,0 +1,38 @@ +/************************************************* +* PK Algorithm Lookup Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_PK_LOOKUP_H__ +#define BOTAN_PK_LOOKUP_H__ + +#include + +namespace Botan { + +/************************************************* +* Get an PK algorithm object * +*************************************************/ +BOTAN_DLL PK_Encryptor* get_pk_encryptor(const PK_Encrypting_Key&, + const std::string&); + +BOTAN_DLL PK_Decryptor* get_pk_decryptor(const PK_Decrypting_Key&, + const std::string&); + +BOTAN_DLL PK_Signer* get_pk_signer(const PK_Signing_Key&, + const std::string&, + Signature_Format = IEEE_1363); + +BOTAN_DLL PK_Verifier* get_pk_verifier(const PK_Verifying_with_MR_Key&, + const std::string&, + Signature_Format = IEEE_1363); +BOTAN_DLL PK_Verifier* get_pk_verifier(const PK_Verifying_wo_MR_Key&, + const std::string&, + Signature_Format = IEEE_1363); + +BOTAN_DLL PK_Key_Agreement* get_pk_kas(const PK_Key_Agreement_Key&, + const std::string&); + +} + +#endif diff --git a/src/core/libstate/lookup.cpp b/src/core/libstate/lookup.cpp new file mode 100644 index 000000000..8e65afb93 --- /dev/null +++ b/src/core/libstate/lookup.cpp @@ -0,0 +1,239 @@ +/************************************************* +* Algorithm Retrieval Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include + +namespace Botan { + +/************************************************* +* Get a block cipher by name * +*************************************************/ +BlockCipher* get_block_cipher(const std::string& name) + { + const BlockCipher* cipher = retrieve_block_cipher(global_state(), name); + if(cipher) + return cipher->clone(); + throw Algorithm_Not_Found(name); + } + +/************************************************* +* Get a stream cipher by name * +*************************************************/ +StreamCipher* get_stream_cipher(const std::string& name) + { + const StreamCipher* cipher = retrieve_stream_cipher(global_state(), name); + if(cipher) + return cipher->clone(); + throw Algorithm_Not_Found(name); + } + +/************************************************* +* Get a hash function by name * +*************************************************/ +HashFunction* get_hash(const std::string& name) + { + const HashFunction* hash = retrieve_hash(global_state(), name); + if(hash) + return hash->clone(); + throw Algorithm_Not_Found(name); + } + +/************************************************* +* Get a MAC by name * +*************************************************/ +MessageAuthenticationCode* get_mac(const std::string& name) + { + const MessageAuthenticationCode* mac = retrieve_mac(global_state(), name); + if(mac) + return mac->clone(); + throw Algorithm_Not_Found(name); + } + +/************************************************* +* Get a S2K algorithm by name * +*************************************************/ +S2K* get_s2k(const std::string& name) + { + const S2K* s2k = retrieve_s2k(global_state(), name); + if(s2k) + return s2k->clone(); + throw Algorithm_Not_Found(name); + } + +/************************************************* +* Get a block cipher padding method by name * +*************************************************/ +const BlockCipherModePaddingMethod* get_bc_pad(const std::string& name) + { + const BlockCipherModePaddingMethod* pad = + retrieve_bc_pad(global_state(), name); + + if(pad) + return pad; + throw Algorithm_Not_Found(name); + } + +/************************************************* +* Query if an algorithm exists * +*************************************************/ +bool have_algorithm(const std::string& name) + { + if(retrieve_block_cipher(global_state(), name)) + return true; + if(retrieve_stream_cipher(global_state(), name)) + return true; + if(retrieve_hash(global_state(), name)) + return true; + if(retrieve_mac(global_state(), name)) + return true; + return false; + } + +/************************************************* +* Query if Botan has the named block cipher * +*************************************************/ +bool have_block_cipher(const std::string& name) + { + return (retrieve_block_cipher(global_state(), name) != 0); + } + +/************************************************* +* Query if Botan has the named stream cipher * +*************************************************/ +bool have_stream_cipher(const std::string& name) + { + return (retrieve_stream_cipher(global_state(), name) != 0); + } + +/************************************************* +* Query if Botan has the named hash function * +*************************************************/ +bool have_hash(const std::string& name) + { + return (retrieve_hash(global_state(), name) != 0); + } + +/************************************************* +* Query if Botan has the named MAC * +*************************************************/ +bool have_mac(const std::string& name) + { + return (retrieve_mac(global_state(), name) != 0); + } + +/************************************************* +* Query the block size of a cipher or hash * +*************************************************/ +u32bit block_size_of(const std::string& name) + { + const BlockCipher* cipher = retrieve_block_cipher(global_state(), name); + if(cipher) + return cipher->BLOCK_SIZE; + + const HashFunction* hash = retrieve_hash(global_state(), name); + if(hash) + return hash->HASH_BLOCK_SIZE; + + throw Algorithm_Not_Found(name); + } + +/************************************************* +* Query the OUTPUT_LENGTH of a hash or MAC * +*************************************************/ +u32bit output_length_of(const std::string& name) + { + const HashFunction* hash = retrieve_hash(global_state(), name); + if(hash) + return hash->OUTPUT_LENGTH; + + const MessageAuthenticationCode* mac = retrieve_mac(global_state(), name); + if(mac) + return mac->OUTPUT_LENGTH; + + throw Algorithm_Not_Found(name); + } + +/************************************************* +* Check if a keylength is valid for this algo * +*************************************************/ +bool valid_keylength_for(u32bit key_len, const std::string& name) + { + const BlockCipher* bc = retrieve_block_cipher(global_state(), name); + if(bc) + return bc->valid_keylength(key_len); + + const StreamCipher* sc = retrieve_stream_cipher(global_state(), name); + if(sc) + return sc->valid_keylength(key_len); + + const MessageAuthenticationCode* mac = retrieve_mac(global_state(), name); + if(mac) + return mac->valid_keylength(key_len); + + throw Algorithm_Not_Found(name); + } + +/************************************************* +* Query the MINIMUM_KEYLENGTH of an algorithm * +*************************************************/ +u32bit min_keylength_of(const std::string& name) + { + const BlockCipher* bc = retrieve_block_cipher(global_state(), name); + if(bc) + return bc->MINIMUM_KEYLENGTH; + + const StreamCipher* sc = retrieve_stream_cipher(global_state(), name); + if(sc) + return sc->MINIMUM_KEYLENGTH; + + const MessageAuthenticationCode* mac = retrieve_mac(global_state(), name); + if(mac) + return mac->MINIMUM_KEYLENGTH; + + throw Algorithm_Not_Found(name); + } + +/************************************************* +* Query the MAXIMUM_KEYLENGTH of an algorithm * +*************************************************/ +u32bit max_keylength_of(const std::string& name) + { + const BlockCipher* bc = retrieve_block_cipher(global_state(), name); + if(bc) + return bc->MAXIMUM_KEYLENGTH; + + const StreamCipher* sc = retrieve_stream_cipher(global_state(), name); + if(sc) + return sc->MAXIMUM_KEYLENGTH; + + const MessageAuthenticationCode* mac = retrieve_mac(global_state(), name); + if(mac) + return mac->MAXIMUM_KEYLENGTH; + + throw Algorithm_Not_Found(name); + } + +/************************************************* +* Query the KEYLENGTH_MULTIPLE of an algorithm * +*************************************************/ +u32bit keylength_multiple_of(const std::string& name) + { + const BlockCipher* bc = retrieve_block_cipher(global_state(), name); + if(bc) + return bc->KEYLENGTH_MULTIPLE; + + const StreamCipher* sc = retrieve_stream_cipher(global_state(), name); + if(sc) + return sc->KEYLENGTH_MULTIPLE; + + const MessageAuthenticationCode* mac = retrieve_mac(global_state(), name); + if(mac) + return mac->KEYLENGTH_MULTIPLE; + + throw Algorithm_Not_Found(name); + } + +} diff --git a/src/core/libstate/lookup.h b/src/core/libstate/lookup.h new file mode 100644 index 000000000..016ad4618 --- /dev/null +++ b/src/core/libstate/lookup.h @@ -0,0 +1,98 @@ +/************************************************* +* Algorithm Lookup Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_LOOKUP_H__ +#define BOTAN_LOOKUP_H__ + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Botan { + +/************************************************* +* Retrieve an object from the lookup table * +*************************************************/ +BOTAN_DLL const BlockCipher* +retrieve_block_cipher(Library_State&, const std::string&); + +BOTAN_DLL const StreamCipher* +retrieve_stream_cipher(Library_State&, const std::string&); + +BOTAN_DLL const HashFunction* +retrieve_hash(Library_State&, const std::string&); + +BOTAN_DLL const MessageAuthenticationCode* +retrieve_mac(Library_State&, const std::string&); + +BOTAN_DLL const S2K* retrieve_s2k(Library_State&, const std::string&); + +BOTAN_DLL const BlockCipherModePaddingMethod* +retrieve_bc_pad(Library_State&, const std::string&); + +/************************************************* +* Get an algorithm object * +*************************************************/ +BOTAN_DLL BlockCipher* get_block_cipher(const std::string&); +BOTAN_DLL StreamCipher* get_stream_cipher(const std::string&); +BOTAN_DLL HashFunction* get_hash(const std::string&); +BOTAN_DLL MessageAuthenticationCode* get_mac(const std::string&); +BOTAN_DLL S2K* get_s2k(const std::string&); +BOTAN_DLL const BlockCipherModePaddingMethod* get_bc_pad(const std::string&); + +/************************************************* +* Get an EMSA/EME/KDF/MGF function * +*************************************************/ +BOTAN_DLL EME* get_eme(const std::string&); +BOTAN_DLL EMSA* get_emsa(const std::string&); +BOTAN_DLL MGF* get_mgf(const std::string&); +BOTAN_DLL KDF* get_kdf(const std::string&); + +/************************************************* +* Get a cipher object * +*************************************************/ +BOTAN_DLL Keyed_Filter* get_cipher(Library_State&, + const std::string&, + const SymmetricKey&, + const InitializationVector&, + Cipher_Dir); + +BOTAN_DLL Keyed_Filter* get_cipher(Library_State&, + const std::string&, + const SymmetricKey&, + Cipher_Dir); + +BOTAN_DLL Keyed_Filter* get_cipher(Library_State&, + const std::string&, Cipher_Dir); + +/************************************************* +* Check to see if an algorithm exists * +*************************************************/ +BOTAN_DLL bool have_algorithm(const std::string&); + +BOTAN_DLL bool have_block_cipher(const std::string&); +BOTAN_DLL bool have_stream_cipher(const std::string&); +BOTAN_DLL bool have_hash(const std::string&); +BOTAN_DLL bool have_mac(const std::string&); + +/************************************************* +* Query information about an algorithm * +*************************************************/ +BOTAN_DLL u32bit block_size_of(const std::string&); +BOTAN_DLL u32bit output_length_of(const std::string&); + +BOTAN_DLL bool valid_keylength_for(u32bit, const std::string&); +BOTAN_DLL u32bit min_keylength_of(const std::string&); +BOTAN_DLL u32bit max_keylength_of(const std::string&); +BOTAN_DLL u32bit keylength_multiple_of(const std::string&); + +} + +#endif diff --git a/src/core/libstate/oids.cpp b/src/core/libstate/oids.cpp new file mode 100644 index 000000000..0823625ea --- /dev/null +++ b/src/core/libstate/oids.cpp @@ -0,0 +1,74 @@ +/************************************************* +* OID Registry Source File * +* (C) 1999-2008 Jack Lloyd * +*************************************************/ + +#include +#include + +namespace Botan { + +namespace OIDS { + +/************************************************* +* Register an OID to string mapping * +*************************************************/ +void add_oid(const OID& oid, const std::string& name) + { + const std::string oid_str = oid.as_string(); + + if(!global_state().is_set("oid2str", oid_str)) + global_state().set("oid2str", oid_str, name); + if(!global_state().is_set("str2oid", name)) + global_state().set("str2oid", name, oid_str); + } + +/************************************************* +* Do an OID to string lookup * +*************************************************/ +std::string lookup(const OID& oid) + { + std::string name = global_state().get("oid2str", oid.as_string()); + if(name == "") + return oid.as_string(); + return name; + } + +/************************************************* +* Do a string to OID lookup * +*************************************************/ +OID lookup(const std::string& name) + { + std::string value = global_state().get("str2oid", name); + if(value != "") + return OID(value); + + try + { + return OID(name); + } + catch(Exception) + { + throw Lookup_Error("No object identifier found for " + name); + } + } + +/************************************************* +* Check to see if an OID exists in the table * +*************************************************/ +bool have_oid(const std::string& name) + { + return global_state().is_set("str2oid", name); + } + +/************************************************* +* Check to see if an OID exists in the table * +*************************************************/ +bool name_of(const OID& oid, const std::string& name) + { + return (oid == lookup(name)); + } + +} + +} diff --git a/src/core/libstate/oids.h b/src/core/libstate/oids.h new file mode 100644 index 000000000..b5be0e01f --- /dev/null +++ b/src/core/libstate/oids.h @@ -0,0 +1,36 @@ +/************************************************* +* OID Registry Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_OIDS_H__ +#define BOTAN_OIDS_H__ + +#include + +namespace Botan { + +namespace OIDS { + +/************************************************* +* Register an OID to string mapping * +*************************************************/ +BOTAN_DLL void add_oid(const OID&, const std::string&); + +/************************************************* +* See if an OID exists in the internal table * +*************************************************/ +BOTAN_DLL bool have_oid(const std::string&); + +/************************************************* +* Perform OID<->string mappings * +*************************************************/ +BOTAN_DLL std::string lookup(const OID&); +BOTAN_DLL OID lookup(const std::string&); +BOTAN_DLL bool name_of(const OID&, const std::string&); + +} + +} + +#endif diff --git a/src/core/libstate/policy.cpp b/src/core/libstate/policy.cpp new file mode 100644 index 000000000..39810760b --- /dev/null +++ b/src/core/libstate/policy.cpp @@ -0,0 +1,492 @@ +/************************************************* +* Default Policy Source File * +* (C) 1999-2008 Jack Lloyd * +*************************************************/ + +#include + +namespace Botan { + +namespace { + +/************************************************* +* OID loading helper function * +*************************************************/ +void add_oid(Library_State& config, + const std::string& oid_str, + const std::string& name) + { + if(!config.is_set("oid2str", oid_str)) + config.set("oid2str", oid_str, name); + if(!config.is_set("str2oid", name)) + config.set("str2oid", name, oid_str); + } + +/************************************************* +* Load all of the default OIDs * +*************************************************/ +void set_default_oids(Library_State& config) + { + add_oid(config, "1.2.840.113549.1.1.1", "RSA"); + add_oid(config, "2.5.8.1.1", "RSA"); + add_oid(config, "1.2.840.10040.4.1", "DSA"); + add_oid(config, "1.2.840.10046.2.1", "DH"); + add_oid(config, "1.3.6.1.4.1.3029.1.2.1", "ELG"); + add_oid(config, "1.3.6.1.4.1.25258.1.1", "RW"); + add_oid(config, "1.3.6.1.4.1.25258.1.2", "NR"); + + add_oid(config, "1.3.14.3.2.7", "DES/CBC"); + add_oid(config, "1.2.840.113549.3.7", "TripleDES/CBC"); + add_oid(config, "1.2.840.113549.3.2", "RC2/CBC"); + add_oid(config, "1.2.840.113533.7.66.10", "CAST-128/CBC"); + add_oid(config, "2.16.840.1.101.3.4.1.2", "AES-128/CBC"); + add_oid(config, "2.16.840.1.101.3.4.1.22", "AES-192/CBC"); + add_oid(config, "2.16.840.1.101.3.4.1.42", "AES-256/CBC"); + + add_oid(config, "1.2.840.113549.2.5", "MD5"); + add_oid(config, "1.3.6.1.4.1.11591.12.2", "Tiger(24,3)"); + + add_oid(config, "1.3.14.3.2.26", "SHA-160"); + add_oid(config, "2.16.840.1.101.3.4.2.4", "SHA-224"); + add_oid(config, "2.16.840.1.101.3.4.2.1", "SHA-256"); + add_oid(config, "2.16.840.1.101.3.4.2.2", "SHA-384"); + add_oid(config, "2.16.840.1.101.3.4.2.3", "SHA-512"); + + add_oid(config, "1.2.840.113549.1.9.16.3.6", "KeyWrap.TripleDES"); + add_oid(config, "1.2.840.113549.1.9.16.3.7", "KeyWrap.RC2"); + add_oid(config, "1.2.840.113533.7.66.15", "KeyWrap.CAST-128"); + add_oid(config, "2.16.840.1.101.3.4.1.5", "KeyWrap.AES-128"); + add_oid(config, "2.16.840.1.101.3.4.1.25", "KeyWrap.AES-192"); + add_oid(config, "2.16.840.1.101.3.4.1.45", "KeyWrap.AES-256"); + + add_oid(config, "1.2.840.113549.1.9.16.3.8", "Compression.Zlib"); + + add_oid(config, "1.2.840.113549.1.1.1", "RSA/EME-PKCS1-v1_5"); + add_oid(config, "1.2.840.113549.1.1.2", "RSA/EMSA3(MD2)"); + add_oid(config, "1.2.840.113549.1.1.4", "RSA/EMSA3(MD5)"); + add_oid(config, "1.2.840.113549.1.1.5", "RSA/EMSA3(SHA-160)"); + add_oid(config, "1.2.840.113549.1.1.11", "RSA/EMSA3(SHA-256)"); + add_oid(config, "1.2.840.113549.1.1.12", "RSA/EMSA3(SHA-384)"); + add_oid(config, "1.2.840.113549.1.1.13", "RSA/EMSA3(SHA-512)"); + add_oid(config, "1.3.36.3.3.1.2", "RSA/EMSA3(RIPEMD-160)"); + + add_oid(config, "1.2.840.10040.4.3", "DSA/EMSA1(SHA-160)"); + add_oid(config, "2.16.840.1.101.3.4.3.1", "DSA/EMSA1(SHA-224)"); + add_oid(config, "2.16.840.1.101.3.4.3.2", "DSA/EMSA1(SHA-256)"); + + add_oid(config, "1.3.6.1.4.1.25258.2.1.1.1", "RW/EMSA2(RIPEMD-160)"); + add_oid(config, "1.3.6.1.4.1.25258.2.1.1.2", "RW/EMSA2(SHA-160)"); + add_oid(config, "1.3.6.1.4.1.25258.2.1.1.3", "RW/EMSA2(SHA-224)"); + add_oid(config, "1.3.6.1.4.1.25258.2.1.1.4", "RW/EMSA2(SHA-256)"); + add_oid(config, "1.3.6.1.4.1.25258.2.1.1.5", "RW/EMSA2(SHA-384)"); + add_oid(config, "1.3.6.1.4.1.25258.2.1.1.6", "RW/EMSA2(SHA-512)"); + + add_oid(config, "1.3.6.1.4.1.25258.2.1.2.1", "RW/EMSA4(RIPEMD-160)"); + add_oid(config, "1.3.6.1.4.1.25258.2.1.2.2", "RW/EMSA4(SHA-160)"); + add_oid(config, "1.3.6.1.4.1.25258.2.1.2.3", "RW/EMSA4(SHA-224)"); + add_oid(config, "1.3.6.1.4.1.25258.2.1.2.4", "RW/EMSA4(SHA-256)"); + add_oid(config, "1.3.6.1.4.1.25258.2.1.2.5", "RW/EMSA4(SHA-384)"); + add_oid(config, "1.3.6.1.4.1.25258.2.1.2.6", "RW/EMSA4(SHA-512)"); + + add_oid(config, "1.3.6.1.4.1.25258.2.2.1.1", "NR/EMSA2(RIPEMD-160)"); + add_oid(config, "1.3.6.1.4.1.25258.2.2.1.2", "NR/EMSA2(SHA-160)"); + add_oid(config, "1.3.6.1.4.1.25258.2.2.1.3", "NR/EMSA2(SHA-224)"); + add_oid(config, "1.3.6.1.4.1.25258.2.2.1.4", "NR/EMSA2(SHA-256)"); + add_oid(config, "1.3.6.1.4.1.25258.2.2.1.5", "NR/EMSA2(SHA-384)"); + add_oid(config, "1.3.6.1.4.1.25258.2.2.1.6", "NR/EMSA2(SHA-512)"); + + add_oid(config, "2.5.4.3", "X520.CommonName"); + add_oid(config, "2.5.4.4", "X520.Surname"); + add_oid(config, "2.5.4.5", "X520.SerialNumber"); + add_oid(config, "2.5.4.6", "X520.Country"); + add_oid(config, "2.5.4.7", "X520.Locality"); + add_oid(config, "2.5.4.8", "X520.State"); + add_oid(config, "2.5.4.10", "X520.Organization"); + add_oid(config, "2.5.4.11", "X520.OrganizationalUnit"); + add_oid(config, "2.5.4.12", "X520.Title"); + add_oid(config, "2.5.4.42", "X520.GivenName"); + add_oid(config, "2.5.4.43", "X520.Initials"); + add_oid(config, "2.5.4.44", "X520.GenerationalQualifier"); + add_oid(config, "2.5.4.46", "X520.DNQualifier"); + add_oid(config, "2.5.4.65", "X520.Pseudonym"); + + add_oid(config, "1.2.840.113549.1.5.12", "PKCS5.PBKDF2"); + add_oid(config, "1.2.840.113549.1.5.1", "PBE-PKCS5v15(MD2,DES/CBC)"); + add_oid(config, "1.2.840.113549.1.5.4", "PBE-PKCS5v15(MD2,RC2/CBC)"); + add_oid(config, "1.2.840.113549.1.5.3", "PBE-PKCS5v15(MD5,DES/CBC)"); + add_oid(config, "1.2.840.113549.1.5.6", "PBE-PKCS5v15(MD5,RC2/CBC)"); + add_oid(config, "1.2.840.113549.1.5.10", "PBE-PKCS5v15(SHA-160,DES/CBC)"); + add_oid(config, "1.2.840.113549.1.5.11", "PBE-PKCS5v15(SHA-160,RC2/CBC)"); + add_oid(config, "1.2.840.113549.1.5.13", "PBE-PKCS5v20"); + + add_oid(config, "1.2.840.113549.1.9.1", "PKCS9.EmailAddress"); + add_oid(config, "1.2.840.113549.1.9.2", "PKCS9.UnstructuredName"); + add_oid(config, "1.2.840.113549.1.9.3", "PKCS9.ContentType"); + add_oid(config, "1.2.840.113549.1.9.4", "PKCS9.MessageDigest"); + add_oid(config, "1.2.840.113549.1.9.7", "PKCS9.ChallengePassword"); + add_oid(config, "1.2.840.113549.1.9.14", "PKCS9.ExtensionRequest"); + + add_oid(config, "1.2.840.113549.1.7.1", "CMS.DataContent"); + add_oid(config, "1.2.840.113549.1.7.2", "CMS.SignedData"); + add_oid(config, "1.2.840.113549.1.7.3", "CMS.EnvelopedData"); + add_oid(config, "1.2.840.113549.1.7.5", "CMS.DigestedData"); + add_oid(config, "1.2.840.113549.1.7.6", "CMS.EncryptedData"); + add_oid(config, "1.2.840.113549.1.9.16.1.2", "CMS.AuthenticatedData"); + add_oid(config, "1.2.840.113549.1.9.16.1.9", "CMS.CompressedData"); + + add_oid(config, "2.5.29.14", "X509v3.SubjectKeyIdentifier"); + add_oid(config, "2.5.29.15", "X509v3.KeyUsage"); + add_oid(config, "2.5.29.17", "X509v3.SubjectAlternativeName"); + add_oid(config, "2.5.29.18", "X509v3.IssuerAlternativeName"); + add_oid(config, "2.5.29.19", "X509v3.BasicConstraints"); + add_oid(config, "2.5.29.20", "X509v3.CRLNumber"); + add_oid(config, "2.5.29.21", "X509v3.ReasonCode"); + add_oid(config, "2.5.29.23", "X509v3.HoldInstructionCode"); + add_oid(config, "2.5.29.24", "X509v3.InvalidityDate"); + add_oid(config, "2.5.29.32", "X509v3.CertificatePolicies"); + add_oid(config, "2.5.29.35", "X509v3.AuthorityKeyIdentifier"); + add_oid(config, "2.5.29.36", "X509v3.PolicyConstraints"); + add_oid(config, "2.5.29.37", "X509v3.ExtendedKeyUsage"); + + add_oid(config, "2.5.29.32.0", "X509v3.AnyPolicy"); + + add_oid(config, "1.3.6.1.5.5.7.3.1", "PKIX.ServerAuth"); + add_oid(config, "1.3.6.1.5.5.7.3.2", "PKIX.ClientAuth"); + add_oid(config, "1.3.6.1.5.5.7.3.3", "PKIX.CodeSigning"); + add_oid(config, "1.3.6.1.5.5.7.3.4", "PKIX.EmailProtection"); + add_oid(config, "1.3.6.1.5.5.7.3.5", "PKIX.IPsecEndSystem"); + add_oid(config, "1.3.6.1.5.5.7.3.6", "PKIX.IPsecTunnel"); + add_oid(config, "1.3.6.1.5.5.7.3.7", "PKIX.IPsecUser"); + add_oid(config, "1.3.6.1.5.5.7.3.8", "PKIX.TimeStamping"); + add_oid(config, "1.3.6.1.5.5.7.3.9", "PKIX.OCSPSigning"); + + add_oid(config, "1.3.6.1.5.5.7.8.5", "PKIX.XMPPAddr"); + } + +/************************************************* +* Set the default algorithm aliases * +*************************************************/ +void set_default_aliases(Library_State& config) + { + config.add_alias("OpenPGP.Cipher.1", "IDEA"); + config.add_alias("OpenPGP.Cipher.2", "TripleDES"); + config.add_alias("OpenPGP.Cipher.3", "CAST-128"); + config.add_alias("OpenPGP.Cipher.4", "Blowfish"); + config.add_alias("OpenPGP.Cipher.5", "SAFER-SK(13)"); + config.add_alias("OpenPGP.Cipher.7", "AES-128"); + config.add_alias("OpenPGP.Cipher.8", "AES-192"); + config.add_alias("OpenPGP.Cipher.9", "AES-256"); + config.add_alias("OpenPGP.Cipher.10", "Twofish"); + + config.add_alias("OpenPGP.Digest.1", "MD5"); + config.add_alias("OpenPGP.Digest.2", "SHA-1"); + config.add_alias("OpenPGP.Digest.3", "RIPEMD-160"); + config.add_alias("OpenPGP.Digest.5", "MD2"); + config.add_alias("OpenPGP.Digest.6", "Tiger(24,3)"); + config.add_alias("OpenPGP.Digest.7", "HAVAL(20,5)"); + config.add_alias("OpenPGP.Digest.8", "SHA-256"); + + config.add_alias("TLS.Digest.0", "Parallel(MD5,SHA-160)"); + + config.add_alias("EME-PKCS1-v1_5", "PKCS1v15"); + config.add_alias("OAEP-MGF1", "EME1"); + config.add_alias("EME-OAEP", "EME1"); + config.add_alias("X9.31", "EMSA2"); + config.add_alias("EMSA-PKCS1-v1_5", "EMSA3"); + config.add_alias("PSS-MGF1", "EMSA4"); + config.add_alias("EMSA-PSS", "EMSA4"); + + config.add_alias("Rijndael", "AES"); + config.add_alias("3DES", "TripleDES"); + config.add_alias("DES-EDE", "TripleDES"); + config.add_alias("CAST5", "CAST-128"); + config.add_alias("SHA1", "SHA-160"); + config.add_alias("SHA-1", "SHA-160"); + config.add_alias("SEAL", "SEAL-3.0-BE"); + config.add_alias("MARK-4", "ARC4(256)"); + config.add_alias("OMAC", "CMAC"); + } + +/************************************************* +* Set the default configuration toggles * +*************************************************/ +void set_default_config(Library_State& config) + { + config.set_option("base/default_allocator", "malloc"); + + config.set_option("pk/test/public", "basic"); + config.set_option("pk/test/private", "basic"); + config.set_option("pk/test/private_gen", "all"); + + config.set_option("x509/exts/basic_constraints", "critical"); + config.set_option("x509/exts/subject_key_id", "yes"); + config.set_option("x509/exts/authority_key_id", "yes"); + config.set_option("x509/exts/subject_alternative_name", "yes"); + config.set_option("x509/exts/issuer_alternative_name", "no"); + config.set_option("x509/exts/key_usage", "critical"); + config.set_option("x509/exts/extended_key_usage", "yes"); + config.set_option("x509/exts/crl_number", "yes"); + } + +/************************************************* +* Set the built-in discrete log groups * +*************************************************/ +void set_default_dl_groups(Library_State& config) + { + config.set("dl", "modp/ietf/768", + "-----BEGIN X942 DH PARAMETERS-----" + "MIHIAmEA///////////JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxObIlFK" + "CHmONATd75UZs806QxswKwpt8l8UN0/hNW1tUcJF5IW1dmJefsb0TELppjo2IP//" + "////////AgECAmB//////////+SH7VEQtGEaYmMxRcBuDmiUgScERTPmOgEF31Md" + "ic2RKKUEPMcaAm73yozZ5p0hjZgVhTb5L4obp/Catrao4SLyQtq7MS8/Y3omIXTT" + "HRsQf/////////8=" + "-----END X942 DH PARAMETERS-----"); + + config.set("dl", "modp/ietf/1024", + "-----BEGIN X942 DH PARAMETERS-----" + "MIIBCgKBgQD//////////8kP2qIhaMI0xMZii4DcHNEpAk4IimfMdAILvqY7E5si" + "UUoIeY40BN3vlRmzzTpDGzArCm3yXxQ3T+E1bW1RwkXkhbV2Yl5+xvRMQummN+1r" + "C/9ctvQGt+3uOGv7Womfpa6fJBF8Sx/mSShmUezmU4H//////////wIBAgKBgH//" + "////////5IftURC0YRpiYzFFwG4OaJSBJwRFM+Y6AQXfUx2JzZEopQQ8xxoCbvfK" + "jNnmnSGNmBWFNvkvihun8Jq2tqjhIvJC2rsxLz9jeiYhdNMb9rWF/65begNb9vcc" + "Nf2tRM/S10+SCL4lj/MklDMo9nMpwP//////////" + "-----END X942 DH PARAMETERS-----"); + + config.set("dl", "modp/ietf/1536", + "-----BEGIN X942 DH PARAMETERS-----" + "MIIBigKBwQD//////////8kP2qIhaMI0xMZii4DcHNEpAk4IimfMdAILvqY7E5si" + "UUoIeY40BN3vlRmzzTpDGzArCm3yXxQ3T+E1bW1RwkXkhbV2Yl5+xvRMQummN+1r" + "C/9ctvQGt+3uOGv7Womfpa6fJBF8Sx/mSShmUezkWz3CAHy4oWO/BZjaSDYcVdOa" + "aRY/qP0kz1+DZV0j3KOtlhxi81YghVK7ntUpB3CWlm1nDDVOSryYBPF0bAjKI3Mn" + "//////////8CAQICgcB//////////+SH7VEQtGEaYmMxRcBuDmiUgScERTPmOgEF" + "31Mdic2RKKUEPMcaAm73yozZ5p0hjZgVhTb5L4obp/Catrao4SLyQtq7MS8/Y3om" + "IXTTG/a1hf+uW3oDW/b3HDX9rUTP0tdPkgi+JY/zJJQzKPZyLZ7hAD5cULHfgsxt" + "JBsOKunNNIsf1H6SZ6/Bsq6R7lHWyw4xeasQQqldz2qUg7hLSzazhhqnJV5MAni6" + "NgRlEbmT//////////8=" + "-----END X942 DH PARAMETERS-----"); + + config.set("dl", "modp/ietf/2048", + "-----BEGIN X942 DH PARAMETERS-----" + "MIICDAKCAQEA///////////JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxOb" + "IlFKCHmONATd75UZs806QxswKwpt8l8UN0/hNW1tUcJF5IW1dmJefsb0TELppjft" + "awv/XLb0Brft7jhr+1qJn6WunyQRfEsf5kkoZlHs5Fs9wgB8uKFjvwWY2kg2HFXT" + "mmkWP6j9JM9fg2VdI9yjrZYcYvNWIIVSu57VKQdwlpZtZww1Tkq8mATxdGwIyhgh" + "fDKQXkYuNs474553LBgOhgObJ4Oi7Aeij7XFXfBvTFLJ3ivL9pVYFxg5lUl86pVq" + "5RXSJhiY+gUQFXKOWoqsqmj//////////wIBAgKCAQB//////////+SH7VEQtGEa" + "YmMxRcBuDmiUgScERTPmOgEF31Mdic2RKKUEPMcaAm73yozZ5p0hjZgVhTb5L4ob" + "p/Catrao4SLyQtq7MS8/Y3omIXTTG/a1hf+uW3oDW/b3HDX9rUTP0tdPkgi+JY/z" + "JJQzKPZyLZ7hAD5cULHfgsxtJBsOKunNNIsf1H6SZ6/Bsq6R7lHWyw4xeasQQqld" + "z2qUg7hLSzazhhqnJV5MAni6NgRlDBC+GUgvIxcbZx3xzzuWDAdDAc2TwdF2A9FH" + "2uKu+DemKWTvFeX7SqwLjBzKpL51SrVyiukTDEx9AogKuUctRVZVNH//////////" + "-----END X942 DH PARAMETERS-----"); + + config.set("dl", "modp/ietf/3072", + "-----BEGIN X942 DH PARAMETERS-----" + "MIIDDAKCAYEA///////////JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxOb" + "IlFKCHmONATd75UZs806QxswKwpt8l8UN0/hNW1tUcJF5IW1dmJefsb0TELppjft" + "awv/XLb0Brft7jhr+1qJn6WunyQRfEsf5kkoZlHs5Fs9wgB8uKFjvwWY2kg2HFXT" + "mmkWP6j9JM9fg2VdI9yjrZYcYvNWIIVSu57VKQdwlpZtZww1Tkq8mATxdGwIyhgh" + "fDKQXkYuNs474553LBgOhgObJ4Oi7Aeij7XFXfBvTFLJ3ivL9pVYFxg5lUl86pVq" + "5RXSJhiY+gUQFXKOWoqqxC2tMxcNBFB6M6hVIavfHLpk7PuFBFjb7wqK6nFXXQYM" + "fbOXD4Wm4eTHq/WujNsJM9cejJTgSiVhnc7j0iYa0u5r8S/6BtmKCGTYdgJzPshq" + "ZFIfKxgXeyAMu+EXV3phXWx3CYjAutlG4gjiT6B05asxQ9tb/OD9EI5LgtEgqTrS" + "yv//////////AgECAoIBgH//////////5IftURC0YRpiYzFFwG4OaJSBJwRFM+Y6" + "AQXfUx2JzZEopQQ8xxoCbvfKjNnmnSGNmBWFNvkvihun8Jq2tqjhIvJC2rsxLz9j" + "eiYhdNMb9rWF/65begNb9vccNf2tRM/S10+SCL4lj/MklDMo9nItnuEAPlxQsd+C" + "zG0kGw4q6c00ix/UfpJnr8GyrpHuUdbLDjF5qxBCqV3PapSDuEtLNrOGGqclXkwC" + "eLo2BGUMEL4ZSC8jFxtnHfHPO5YMB0MBzZPB0XYD0Ufa4q74N6YpZO8V5ftKrAuM" + "HMqkvnVKtXKK6RMMTH0CiAq5Ry1FVWIW1pmLhoIoPRnUKpDV745dMnZ9woIsbfeF" + "RXU4q66DBj7Zy4fC03DyY9X610ZthJnrj0ZKcCUSsM7ncekTDWl3NfiX/QNsxQQy" + "bDsBOZ9kNTIpD5WMC72QBl3wi6u9MK62O4TEYF1so3EEcSfQOnLVmKHtrf5wfohH" + "JcFokFSdaWV//////////w==" + "-----END X942 DH PARAMETERS-----"); + + config.set("dl", "modp/ietf/4096", + "-----BEGIN X942 DH PARAMETERS-----" + "MIIEDAKCAgEA///////////JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxOb" + "IlFKCHmONATd75UZs806QxswKwpt8l8UN0/hNW1tUcJF5IW1dmJefsb0TELppjft" + "awv/XLb0Brft7jhr+1qJn6WunyQRfEsf5kkoZlHs5Fs9wgB8uKFjvwWY2kg2HFXT" + "mmkWP6j9JM9fg2VdI9yjrZYcYvNWIIVSu57VKQdwlpZtZww1Tkq8mATxdGwIyhgh" + "fDKQXkYuNs474553LBgOhgObJ4Oi7Aeij7XFXfBvTFLJ3ivL9pVYFxg5lUl86pVq" + "5RXSJhiY+gUQFXKOWoqqxC2tMxcNBFB6M6hVIavfHLpk7PuFBFjb7wqK6nFXXQYM" + "fbOXD4Wm4eTHq/WujNsJM9cejJTgSiVhnc7j0iYa0u5r8S/6BtmKCGTYdgJzPshq" + "ZFIfKxgXeyAMu+EXV3phXWx3CYjAutlG4gjiT6B05asxQ9tb/OD9EI5LgtEgqSEI" + "ARpyPBKnh+bXiHGaEL26WyaZwycYavTiPBqUaDS2FQvaJYPpyirUTOjbu8LbBN6O" + "+S6O/BQfvsqmKHxZR05rwF2ZspZPoJDDoiM7oYZRW+ftH2EpcM7i16+4G912IXBI" + "HNAGkSfVsFqpk7TqmI2P3cGG/7fckKbAj030Nck0BjGZ//////////8CAQICggIA" + "f//////////kh+1RELRhGmJjMUXAbg5olIEnBEUz5joBBd9THYnNkSilBDzHGgJu" + "98qM2eadIY2YFYU2+S+KG6fwmra2qOEi8kLauzEvP2N6JiF00xv2tYX/rlt6A1v2" + "9xw1/a1Ez9LXT5IIviWP8ySUMyj2ci2e4QA+XFCx34LMbSQbDirpzTSLH9R+kmev" + "wbKuke5R1ssOMXmrEEKpXc9qlIO4S0s2s4YapyVeTAJ4ujYEZQwQvhlILyMXG2cd" + "8c87lgwHQwHNk8HRdgPRR9rirvg3pilk7xXl+0qsC4wcyqS+dUq1corpEwxMfQKI" + "CrlHLUVVYhbWmYuGgig9GdQqkNXvjl0ydn3Cgixt94VFdTirroMGPtnLh8LTcPJj" + "1frXRm2EmeuPRkpwJRKwzudx6RMNaXc1+Jf9A2zFBDJsOwE5n2Q1MikPlYwLvZAG" + "XfCLq70wrrY7hMRgXWyjcQRxJ9A6ctWYoe2t/nB+iEclwWiQVJCEAI05HglTw/Nr" + "xDjNCF7dLZNM4ZOMNXpxHg1KNBpbCoXtEsH05RVqJnRt3eFtgm9HfJdHfgoP32VT" + "FD4so6c14C7M2Usn0Ehh0RGd0MMorfP2j7CUuGdxa9fcDe67ELgkDmgDSJPq2C1U" + "ydp1TEbH7uDDf9vuSFNgR6b6GuSaAxjM//////////8=" + "-----END X942 DH PARAMETERS-----"); + + config.set("dl", "modp/ietf/6144", + "-----BEGIN X942 DH PARAMETERS-----" + "MIIGDAKCAwEA///////////JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxOb" + "IlFKCHmONATd75UZs806QxswKwpt8l8UN0/hNW1tUcJF5IW1dmJefsb0TELppjft" + "awv/XLb0Brft7jhr+1qJn6WunyQRfEsf5kkoZlHs5Fs9wgB8uKFjvwWY2kg2HFXT" + "mmkWP6j9JM9fg2VdI9yjrZYcYvNWIIVSu57VKQdwlpZtZww1Tkq8mATxdGwIyhgh" + "fDKQXkYuNs474553LBgOhgObJ4Oi7Aeij7XFXfBvTFLJ3ivL9pVYFxg5lUl86pVq" + "5RXSJhiY+gUQFXKOWoqqxC2tMxcNBFB6M6hVIavfHLpk7PuFBFjb7wqK6nFXXQYM" + "fbOXD4Wm4eTHq/WujNsJM9cejJTgSiVhnc7j0iYa0u5r8S/6BtmKCGTYdgJzPshq" + "ZFIfKxgXeyAMu+EXV3phXWx3CYjAutlG4gjiT6B05asxQ9tb/OD9EI5LgtEgqSEI" + "ARpyPBKnh+bXiHGaEL26WyaZwycYavTiPBqUaDS2FQvaJYPpyirUTOjbu8LbBN6O" + "+S6O/BQfvsqmKHxZR05rwF2ZspZPoJDDoiM7oYZRW+ftH2EpcM7i16+4G912IXBI" + "HNAGkSfVsFqpk7TqmI2P3cGG/7fckKbAj030Nck0AoSSNsP6tNJ8cCbB1NyyYCZG" + "3sl1HnY9uje9+P+UBq2eUw7l2zgvQTABrrBqU+2QJ9gxF5cnsIZaiRjaPtvrz5sU" + "7UTObLrO1Lsb238UR+bMJUszIFFRK9evQm+49AE3jNK/WYPKAcZLkuzwMuoV0XId" + "A/SC185udP721V5wL0aYDIK1qEAxkAscnlnnyX++x+jzI6l6fjbMiL4PHUW3/1ha" + "xUvUB7IrQVSqzI9tfr9I4dgUzF7SD4A34KeXFe7ym+MoBqHVi7fF2nb1UKo9ih+/" + "8OsZzLGjE9Vc2lbJ7C7yljI4f+jXbjwEaAQ+j2Y/SGDuEr8tWwt0dNbmlPkebcxA" + "JP//////////AoIDAH//////////5IftURC0YRpiYzFFwG4OaJSBJwRFM+Y6AQXf" + "Ux2JzZEopQQ8xxoCbvfKjNnmnSGNmBWFNvkvihun8Jq2tqjhIvJC2rsxLz9jeiYh" + "dNMb9rWF/65begNb9vccNf2tRM/S10+SCL4lj/MklDMo9nItnuEAPlxQsd+CzG0k" + "Gw4q6c00ix/UfpJnr8GyrpHuUdbLDjF5qxBCqV3PapSDuEtLNrOGGqclXkwCeLo2" + "BGUMEL4ZSC8jFxtnHfHPO5YMB0MBzZPB0XYD0Ufa4q74N6YpZO8V5ftKrAuMHMqk" + "vnVKtXKK6RMMTH0CiAq5Ry1FVWIW1pmLhoIoPRnUKpDV745dMnZ9woIsbfeFRXU4" + "q66DBj7Zy4fC03DyY9X610ZthJnrj0ZKcCUSsM7ncekTDWl3NfiX/QNsxQQybDsB" + "OZ9kNTIpD5WMC72QBl3wi6u9MK62O4TEYF1so3EEcSfQOnLVmKHtrf5wfohHJcFo" + "kFSQhACNOR4JU8Pza8Q4zQhe3S2TTOGTjDV6cR4NSjQaWwqF7RLB9OUVaiZ0bd3h" + "bYJvR3yXR34KD99lUxQ+LKOnNeAuzNlLJ9BIYdERndDDKK3z9o+wlLhncWvX3A3u" + "uxC4JA5oA0iT6tgtVMnadUxGx+7gw3/b7khTYEem+hrkmgFCSRth/VppPjgTYOpu" + "WTATI29kuo87Ht0b3vx/ygNWzymHcu2cF6CYANdYNSn2yBPsGIvLk9hDLUSMbR9t" + "9efNinaiZzZdZ2pdje2/iiPzZhKlmZAoqJXr16E33HoAm8ZpX6zB5QDjJcl2eBl1" + "Cui5DoH6QWvnNzp/e2qvOBejTAZBWtQgGMgFjk8s8+S/32P0eZHUvT8bZkRfB46i" + "2/+sLWKl6gPZFaCqVWZHtr9fpHDsCmYvaQfAG/BTy4r3eU3xlANQ6sXb4u07eqhV" + "HsUP3/h1jOZY0Ynqrm0rZPYXeUsZHD/0a7ceAjQCH0ezH6Qwdwlflq2Fujprc0p8" + "jzbmIBJ//////////wIBAg==" + "-----END X942 DH PARAMETERS-----"); + + config.set("dl", "modp/ietf/8192", + "-----BEGIN X942 DH PARAMETERS-----" + "MIIIDAKCBAEA///////////JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxOb" + "IlFKCHmONATd75UZs806QxswKwpt8l8UN0/hNW1tUcJF5IW1dmJefsb0TELppjft" + "awv/XLb0Brft7jhr+1qJn6WunyQRfEsf5kkoZlHs5Fs9wgB8uKFjvwWY2kg2HFXT" + "mmkWP6j9JM9fg2VdI9yjrZYcYvNWIIVSu57VKQdwlpZtZww1Tkq8mATxdGwIyhgh" + "fDKQXkYuNs474553LBgOhgObJ4Oi7Aeij7XFXfBvTFLJ3ivL9pVYFxg5lUl86pVq" + "5RXSJhiY+gUQFXKOWoqqxC2tMxcNBFB6M6hVIavfHLpk7PuFBFjb7wqK6nFXXQYM" + "fbOXD4Wm4eTHq/WujNsJM9cejJTgSiVhnc7j0iYa0u5r8S/6BtmKCGTYdgJzPshq" + "ZFIfKxgXeyAMu+EXV3phXWx3CYjAutlG4gjiT6B05asxQ9tb/OD9EI5LgtEgqSEI" + "ARpyPBKnh+bXiHGaEL26WyaZwycYavTiPBqUaDS2FQvaJYPpyirUTOjbu8LbBN6O" + "+S6O/BQfvsqmKHxZR05rwF2ZspZPoJDDoiM7oYZRW+ftH2EpcM7i16+4G912IXBI" + "HNAGkSfVsFqpk7TqmI2P3cGG/7fckKbAj030Nck0AoSSNsP6tNJ8cCbB1NyyYCZG" + "3sl1HnY9uje9+P+UBq2eUw7l2zgvQTABrrBqU+2QJ9gxF5cnsIZaiRjaPtvrz5sU" + "7UTObLrO1Lsb238UR+bMJUszIFFRK9evQm+49AE3jNK/WYPKAcZLkuzwMuoV0XId" + "A/SC185udP721V5wL0aYDIK1qEAxkAscnlnnyX++x+jzI6l6fjbMiL4PHUW3/1ha" + "xUvUB7IrQVSqzI9tfr9I4dgUzF7SD4A34KeXFe7ym+MoBqHVi7fF2nb1UKo9ih+/" + "8OsZzLGjE9Vc2lbJ7C7yljI4f+jXbjwEaAQ+j2Y/SGDuEr8tWwt0dNbmlPkebb4R" + "WXSjkm8S/uXkOHd8tqky34zYvsTQc7kxujvIMraNndMAdB+nv4r8R+0ldvaTa6Qk" + "ZjqrY5xa5PVoNCO0dCvxyXgjjxbL451lLeP9uL78hIrZIiIuBKQDfAcT61eoGiPw" + "xzRz/GRs6jBrS8vIhi+Dhd36nUt/osCH6HloMwPtW906Bis89bOieKZtKhP4P0T4" + "Ld8xDuB0q2o2RZfomaAlXcFk8xzFCEaFHfmrSBld7X6hsdUQvX7nTXP682vDHs+i" + "aDWQRvTrh5+SQAlDi0gcbNeImgAu1e44K8kZDab8Am5HlVjkR1Z36aqeMFDidlaU" + "38gfVuiAuW5xYMmA3Zjt09///////////wKCBAB//////////+SH7VEQtGEaYmMx" + "RcBuDmiUgScERTPmOgEF31Mdic2RKKUEPMcaAm73yozZ5p0hjZgVhTb5L4obp/Ca" + "trao4SLyQtq7MS8/Y3omIXTTG/a1hf+uW3oDW/b3HDX9rUTP0tdPkgi+JY/zJJQz" + "KPZyLZ7hAD5cULHfgsxtJBsOKunNNIsf1H6SZ6/Bsq6R7lHWyw4xeasQQqldz2qU" + "g7hLSzazhhqnJV5MAni6NgRlDBC+GUgvIxcbZx3xzzuWDAdDAc2TwdF2A9FH2uKu" + "+DemKWTvFeX7SqwLjBzKpL51SrVyiukTDEx9AogKuUctRVViFtaZi4aCKD0Z1CqQ" + "1e+OXTJ2fcKCLG33hUV1OKuugwY+2cuHwtNw8mPV+tdGbYSZ649GSnAlErDO53Hp" + "Ew1pdzX4l/0DbMUEMmw7ATmfZDUyKQ+VjAu9kAZd8IurvTCutjuExGBdbKNxBHEn" + "0Dpy1Zih7a3+cH6IRyXBaJBUkIQAjTkeCVPD82vEOM0IXt0tk0zhk4w1enEeDUo0" + "GlsKhe0SwfTlFWomdG3d4W2Cb0d8l0d+Cg/fZVMUPiyjpzXgLszZSyfQSGHREZ3Q" + "wyit8/aPsJS4Z3Fr19wN7rsQuCQOaANIk+rYLVTJ2nVMRsfu4MN/2+5IU2BHpvoa" + "5JoBQkkbYf1aaT44E2DqblkwEyNvZLqPOx7dG978f8oDVs8ph3LtnBegmADXWDUp" + "9sgT7BiLy5PYQy1EjG0fbfXnzYp2omc2XWdqXY3tv4oj82YSpZmQKKiV69ehN9x6" + "AJvGaV+sweUA4yXJdngZdQrouQ6B+kFr5zc6f3tqrzgXo0wGQVrUIBjIBY5PLPPk" + "v99j9HmR1L0/G2ZEXweOotv/rC1ipeoD2RWgqlVmR7a/X6Rw7ApmL2kHwBvwU8uK" + "93lN8ZQDUOrF2+LtO3qoVR7FD9/4dYzmWNGJ6q5tK2T2F3lLGRw/9Gu3HgI0Ah9H" + "sx+kMHcJX5athbo6a3NKfI823wisulHJN4l/cvIcO75bVJlvxmxfYmg53JjdHeQZ" + "W0bO6YA6D9PfxX4j9pK7e0m10hIzHVWxzi1yerQaEdo6FfjkvBHHi2XxzrKW8f7c" + "X35CRWyRERcCUgG+A4n1q9QNEfhjmjn+MjZ1GDWl5eRDF8HC7v1Opb/RYEP0PLQZ" + "gfat7p0DFZ562dE8UzaVCfwfonwW75iHcDpVtRsiy/RM0BKu4LJ5jmKEI0KO/NWk" + "DK72v1DY6ohev3Omuf15teGPZ9E0GsgjenXDz8kgBKHFpA42a8RNABdq9xwV5IyG" + "034BNyPKrHIjqzv01U8YKHE7K0pv5A+rdEBctziwZMBuzHbp7///////////AgEC" + "-----END X942 DH PARAMETERS-----"); + + config.set("dl", "dsa/jce/512", + "-----BEGIN DSA PARAMETERS-----" + "MIGdAkEA/KaCzo4Syrom78z3EQ5SbbB4sF7ey80etKII864WF64B81uRpH5t9jQT" + "xeEu0ImbzRMqzVDZkVG9xD7nN1kuFwIVAJYu3cw2nLqOuyYO5rahJtk0bjjFAkEA" + "3gtU76vylwh+5iPVylWIxkgo70/eT/uuHs0gBndrBbEbgeo83pvDlkwWh8UyW/Q9" + "fM76DQqGvl3/3dDRFD3NdQ==" + "-----END DSA PARAMETERS-----"); + + config.set("dl", "dsa/jce/768", + "-----BEGIN DSA PARAMETERS-----" + "MIHdAmEA6eZCWZ01XzfJf/01ZxILjiXJzUPpJ7OpZw++xdiQFBki0sOzrSSACTeZ" + "hp0ehGqrSfqwrSbSzmoiIZ1HC859d31KIfvpwnC1f2BwAvPO+Dk2lM9F7jaIwRqM" + "VqsSej2vAhUAnNvYTJ8awvOND4D0KrlS5zOL9RECYQDe7p717RUWzn5pXmcrjO5F" + "5s17NuDmOF+JS6hhY/bz5sbU6KgRRtQBfe/dccvZD6Akdlm4i3zByJT0gmn9Txqs" + "CjBTjf9rP8ds+xMcnnlltYhYqwpDtVczWRKoqlR/lWg=" + "-----END DSA PARAMETERS-----"); + + config.set("dl", "dsa/jce/1024", + "-----BEGIN DSA PARAMETERS-----" + "MIIBHgKBgQD9f1OBHXUSKVLfSpwu7OTn9hG3UjzvRADDHj+AtlEmaUVdQCJR+1k9" + "jVj6v8X1ujD2y5tVbNeBO4AdNG/yZmC3a5lQpaSfn+gEexAiwk+7qdf+t8Yb+DtX" + "58aophUPBPuD9tPFHsMCNVQTWhaRMvZ1864rYdcq7/IiAxmd0UgBxwIVAJdgUI8V" + "IwvMspK5gqLrhAvwWBz1AoGARpYDUS4wJ4zTlHWV2yLuyYJqYyKtyXNE9B10DDJX" + "JMj577qn1NgD/4xgnc0QDrxb38+tfGpCX66nhuogUOvpg1HqH9of3yTWlHqmuaoj" + "dmlTgC9NfUqOy6BtGXaKJJH/sW0O+cQ6mbX3FnL/bwoktETQc20E04oaEyLa9s3Y" + "jJ0=" + "-----END DSA PARAMETERS-----"); + + config.set("dl", "dsa/botan/2048", + "-----BEGIN DSA PARAMETERS-----" + "MIICLAKCAQEAkcSKT9+898Aq6V59oSYSK13Shk9Vm4fo50oobVL1m9HeaN/WRdDg" + "DGDAgAMYkZgDdO61lKUyv9Z7mgnqxLhmOgeRDmjzlGX7cEDSXfE5MuusQ0elMOy6" + "YchU+biA08DDZgCAWHxFVm2t4mvVo5S+CTtMDyS1r/747GxbPlf7iQJam8FnaZMh" + "MeFtPJTvyrGNDfBhIDzFPmEDvHLVWUv9QMplOA9EqahR3LB1SV/AM6ilgHGhvXj+" + "BS9mVVZI60txnSr+i0iA+NrW8VgYuhePiSdMhwvpuW6wjEbEAEDMLv4d+xsYaN0x" + "nePDSjKmOrbrEiQgmkGWgMx5AtFyjU354QIhAIzX1FD4bwrZTu5M5GmodW0evRBY" + "JBlD6v+ws1RYXpJNAoIBAA2fXgdhtNvRgz1qsalhoJlsXyIwP3LYTBQPZ8Qx2Uq1" + "cVvqgaDJjTnOS8941rnryJXTT+idlAkdWEhhXvFfXobxHZb2yWniA936WDVkIKSc" + "tES1lbkBqTPP4HZ7WU8YoHt/kd7NukRriJkPePL/kfL+fNQ/0uRtGOraH3u2YCxh" + "f27zpLKE8v2boQo2BC3o+oeiyjZZf+yBFXoUheRAQd8CgwERy4gLvm7UlIFIhvll" + "zcMTX1zPE4Nyi/ZbgG+WksCxDWxMCcdabKO0ATyxarLBBfa+I66pAA6rIXiYX5cs" + "mAV+HIbkTnIYaI6krg82NtzKdFydzU5q/7Z8y8E9YTE=" + "-----END DSA PARAMETERS-----"); + + config.set("dl", "dsa/botan/3072", + "-----BEGIN DSA PARAMETERS-----" + "MIIDLAKCAYEA5LUIgHWWY1heFCRgyi2d/xMviuTIQN2jomZoiRJP5WOLhOiim3rz" + "+hIJvmv8S1By7Tsrc4e68/hX9HioAijvNgC3az3Pth0g00RlslBtLK+H3259wM6R" + "vS0Wekb2rcwxxTHk+cervbkq3fNbCoBsZikqX14X6WTdCZkDczrEKKs12A6m9oW/" + "uovkBo5UGK5eytno/wc94rY+Tn6tNciptwtb1Hz7iNNztm83kxk5sKtxvVWVgJCG" + "2gFVM30YWg5Ps2pRmxtiArhZHmACRJzxzTpmOE9tIHOxzXO+ypO68eGmEX0COPIi" + "rh7X/tGFqJDn9n+rj+uXU8wTSlGD3+h64llfe1wtn7tCJJ/dWVE+HTOWs+sv2GaE" + "8oWoRI/nV6ApiBxAdguU75Gb35dAw4OJWZ7FGm6btRmo4GhJHpzgovz+PLYNZs8N" + "+tIKjsaEBIaEphREV1vRck1zUrRKdgB3s71r04XOWwpyUMwL92jagpI4Buuc+7E4" + "hDcxthggjHWbAiEAs+vTZOxp74zzuvZDt1c0sWM5suSeXN4bWcHp+0DuDFsCggGA" + "K+0h7vg5ZKIwrom7px2ffDnFL8gim047x+WUTTKdoQ8BDqyee69sAJ/E6ylgcj4r" + "Vt9GY+TDrIAOkljeL3ZJ0gZ4KJP4Ze/KSY0u7zAHTqXop6smJxKk2UovOwuaku5A" + "D7OKPMWaXcfkNtXABLIuNQKDgbUck0B+sy1K4P1Cy0XhLQ7O6KJiOO3iCCp7FSIR" + "PGbO+NdFxs88uUX4TS9N4W1Epx3hmCcOE/A1U8iLjTI60LlIob8hA6lJl5tu0W+1" + "88lT2Vt8jojKZ9z1pjb7nKOdkkIV96iE7Wx+48ltjZcVQnl0t8Q1EoLhPTdz99KL" + "RS8QiSoTx1hzKN6kgntrNpsqjcFyrcWD9R8qZZjFSD5bxGewL5HQWcQC0Y4sJoD3" + "dqoG9JKAoscsF8xC1bbnQMXEsas8UcLtCSviotiwU65Xc9FCXtKwjwbi3VBZLfGk" + "eMFVkc39EVZP+I/zi3IdQjkv2kcyEtz9jS2IqXagCv/m//tDCjWeZMorNRyiQSOU" + "-----END DSA PARAMETERS-----"); + } +} + +/************************************************* +* Set the default policy * +*************************************************/ +void Library_State::load_default_config() + { + set_default_config(*this); + set_default_aliases(*this); + set_default_oids(*this); + set_default_dl_groups(*this); + } + +} diff --git a/src/core/look_add.h b/src/core/look_add.h deleted file mode 100644 index 8c170049d..000000000 --- a/src/core/look_add.h +++ /dev/null @@ -1,28 +0,0 @@ -/************************************************* -* Lookup Table Management Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_LOOKUP_MANGEMENT_H__ -#define BOTAN_LOOKUP_MANGEMENT_H__ - -#include -#include -#include -#include - -namespace Botan { - -/************************************************* -* Add an algorithm to the lookup table * -*************************************************/ -BOTAN_DLL void add_algorithm(Library_State&, BlockCipher*); -BOTAN_DLL void add_algorithm(Library_State&, StreamCipher*); -BOTAN_DLL void add_algorithm(Library_State&, HashFunction*); -BOTAN_DLL void add_algorithm(Library_State&, MessageAuthenticationCode*); -BOTAN_DLL void add_algorithm(Library_State&, S2K*); -BOTAN_DLL void add_algorithm(Library_State&, BlockCipherModePaddingMethod*); - -} - -#endif diff --git a/src/core/look_pk.cpp b/src/core/look_pk.cpp deleted file mode 100644 index a4062b57c..000000000 --- a/src/core/look_pk.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/************************************************* -* PK Algorithm Lookup Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include - -namespace Botan { - -/************************************************* -* Get a PK_Encryptor object * -*************************************************/ -PK_Encryptor* get_pk_encryptor(const PK_Encrypting_Key& key, - const std::string& eme) - { - return new PK_Encryptor_MR_with_EME(key, eme); - } - -/************************************************* -* Get a PK_Decryptor object * -*************************************************/ -PK_Decryptor* get_pk_decryptor(const PK_Decrypting_Key& key, - const std::string& eme) - { - return new PK_Decryptor_MR_with_EME(key, eme); - } - -/************************************************* -* Get a PK_Signer object * -*************************************************/ -PK_Signer* get_pk_signer(const PK_Signing_Key& key, - const std::string& encoding, - Signature_Format sig_format) - { - PK_Signer* signer = new PK_Signer(key, encoding); - signer->set_output_format(sig_format); - return signer; - } - -/************************************************* -* Get a PK_Verifier object * -*************************************************/ -PK_Verifier* get_pk_verifier(const PK_Verifying_with_MR_Key& key, - const std::string& encoding, - Signature_Format sig_format) - { - PK_Verifier* verifier = new PK_Verifier_with_MR(key, encoding); - verifier->set_input_format(sig_format); - return verifier; - } - -/************************************************* -* Get a PK_Verifier object * -*************************************************/ -PK_Verifier* get_pk_verifier(const PK_Verifying_wo_MR_Key& key, - const std::string& encoding, - Signature_Format sig_format) - { - PK_Verifier* verifier = new PK_Verifier_wo_MR(key, encoding); - verifier->set_input_format(sig_format); - return verifier; - } - -/************************************************* -* Get a PK_Key_Agreement object * -*************************************************/ -PK_Key_Agreement* get_pk_kas(const PK_Key_Agreement_Key& key, - const std::string& kdf) - { - return new PK_Key_Agreement(key, kdf); - } - -} diff --git a/src/core/look_pk.h b/src/core/look_pk.h deleted file mode 100644 index 63756ad22..000000000 --- a/src/core/look_pk.h +++ /dev/null @@ -1,38 +0,0 @@ -/************************************************* -* PK Algorithm Lookup Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_PK_LOOKUP_H__ -#define BOTAN_PK_LOOKUP_H__ - -#include - -namespace Botan { - -/************************************************* -* Get an PK algorithm object * -*************************************************/ -BOTAN_DLL PK_Encryptor* get_pk_encryptor(const PK_Encrypting_Key&, - const std::string&); - -BOTAN_DLL PK_Decryptor* get_pk_decryptor(const PK_Decrypting_Key&, - const std::string&); - -BOTAN_DLL PK_Signer* get_pk_signer(const PK_Signing_Key&, - const std::string&, - Signature_Format = IEEE_1363); - -BOTAN_DLL PK_Verifier* get_pk_verifier(const PK_Verifying_with_MR_Key&, - const std::string&, - Signature_Format = IEEE_1363); -BOTAN_DLL PK_Verifier* get_pk_verifier(const PK_Verifying_wo_MR_Key&, - const std::string&, - Signature_Format = IEEE_1363); - -BOTAN_DLL PK_Key_Agreement* get_pk_kas(const PK_Key_Agreement_Key&, - const std::string&); - -} - -#endif diff --git a/src/core/lookup.cpp b/src/core/lookup.cpp deleted file mode 100644 index 8e65afb93..000000000 --- a/src/core/lookup.cpp +++ /dev/null @@ -1,239 +0,0 @@ -/************************************************* -* Algorithm Retrieval Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include - -namespace Botan { - -/************************************************* -* Get a block cipher by name * -*************************************************/ -BlockCipher* get_block_cipher(const std::string& name) - { - const BlockCipher* cipher = retrieve_block_cipher(global_state(), name); - if(cipher) - return cipher->clone(); - throw Algorithm_Not_Found(name); - } - -/************************************************* -* Get a stream cipher by name * -*************************************************/ -StreamCipher* get_stream_cipher(const std::string& name) - { - const StreamCipher* cipher = retrieve_stream_cipher(global_state(), name); - if(cipher) - return cipher->clone(); - throw Algorithm_Not_Found(name); - } - -/************************************************* -* Get a hash function by name * -*************************************************/ -HashFunction* get_hash(const std::string& name) - { - const HashFunction* hash = retrieve_hash(global_state(), name); - if(hash) - return hash->clone(); - throw Algorithm_Not_Found(name); - } - -/************************************************* -* Get a MAC by name * -*************************************************/ -MessageAuthenticationCode* get_mac(const std::string& name) - { - const MessageAuthenticationCode* mac = retrieve_mac(global_state(), name); - if(mac) - return mac->clone(); - throw Algorithm_Not_Found(name); - } - -/************************************************* -* Get a S2K algorithm by name * -*************************************************/ -S2K* get_s2k(const std::string& name) - { - const S2K* s2k = retrieve_s2k(global_state(), name); - if(s2k) - return s2k->clone(); - throw Algorithm_Not_Found(name); - } - -/************************************************* -* Get a block cipher padding method by name * -*************************************************/ -const BlockCipherModePaddingMethod* get_bc_pad(const std::string& name) - { - const BlockCipherModePaddingMethod* pad = - retrieve_bc_pad(global_state(), name); - - if(pad) - return pad; - throw Algorithm_Not_Found(name); - } - -/************************************************* -* Query if an algorithm exists * -*************************************************/ -bool have_algorithm(const std::string& name) - { - if(retrieve_block_cipher(global_state(), name)) - return true; - if(retrieve_stream_cipher(global_state(), name)) - return true; - if(retrieve_hash(global_state(), name)) - return true; - if(retrieve_mac(global_state(), name)) - return true; - return false; - } - -/************************************************* -* Query if Botan has the named block cipher * -*************************************************/ -bool have_block_cipher(const std::string& name) - { - return (retrieve_block_cipher(global_state(), name) != 0); - } - -/************************************************* -* Query if Botan has the named stream cipher * -*************************************************/ -bool have_stream_cipher(const std::string& name) - { - return (retrieve_stream_cipher(global_state(), name) != 0); - } - -/************************************************* -* Query if Botan has the named hash function * -*************************************************/ -bool have_hash(const std::string& name) - { - return (retrieve_hash(global_state(), name) != 0); - } - -/************************************************* -* Query if Botan has the named MAC * -*************************************************/ -bool have_mac(const std::string& name) - { - return (retrieve_mac(global_state(), name) != 0); - } - -/************************************************* -* Query the block size of a cipher or hash * -*************************************************/ -u32bit block_size_of(const std::string& name) - { - const BlockCipher* cipher = retrieve_block_cipher(global_state(), name); - if(cipher) - return cipher->BLOCK_SIZE; - - const HashFunction* hash = retrieve_hash(global_state(), name); - if(hash) - return hash->HASH_BLOCK_SIZE; - - throw Algorithm_Not_Found(name); - } - -/************************************************* -* Query the OUTPUT_LENGTH of a hash or MAC * -*************************************************/ -u32bit output_length_of(const std::string& name) - { - const HashFunction* hash = retrieve_hash(global_state(), name); - if(hash) - return hash->OUTPUT_LENGTH; - - const MessageAuthenticationCode* mac = retrieve_mac(global_state(), name); - if(mac) - return mac->OUTPUT_LENGTH; - - throw Algorithm_Not_Found(name); - } - -/************************************************* -* Check if a keylength is valid for this algo * -*************************************************/ -bool valid_keylength_for(u32bit key_len, const std::string& name) - { - const BlockCipher* bc = retrieve_block_cipher(global_state(), name); - if(bc) - return bc->valid_keylength(key_len); - - const StreamCipher* sc = retrieve_stream_cipher(global_state(), name); - if(sc) - return sc->valid_keylength(key_len); - - const MessageAuthenticationCode* mac = retrieve_mac(global_state(), name); - if(mac) - return mac->valid_keylength(key_len); - - throw Algorithm_Not_Found(name); - } - -/************************************************* -* Query the MINIMUM_KEYLENGTH of an algorithm * -*************************************************/ -u32bit min_keylength_of(const std::string& name) - { - const BlockCipher* bc = retrieve_block_cipher(global_state(), name); - if(bc) - return bc->MINIMUM_KEYLENGTH; - - const StreamCipher* sc = retrieve_stream_cipher(global_state(), name); - if(sc) - return sc->MINIMUM_KEYLENGTH; - - const MessageAuthenticationCode* mac = retrieve_mac(global_state(), name); - if(mac) - return mac->MINIMUM_KEYLENGTH; - - throw Algorithm_Not_Found(name); - } - -/************************************************* -* Query the MAXIMUM_KEYLENGTH of an algorithm * -*************************************************/ -u32bit max_keylength_of(const std::string& name) - { - const BlockCipher* bc = retrieve_block_cipher(global_state(), name); - if(bc) - return bc->MAXIMUM_KEYLENGTH; - - const StreamCipher* sc = retrieve_stream_cipher(global_state(), name); - if(sc) - return sc->MAXIMUM_KEYLENGTH; - - const MessageAuthenticationCode* mac = retrieve_mac(global_state(), name); - if(mac) - return mac->MAXIMUM_KEYLENGTH; - - throw Algorithm_Not_Found(name); - } - -/************************************************* -* Query the KEYLENGTH_MULTIPLE of an algorithm * -*************************************************/ -u32bit keylength_multiple_of(const std::string& name) - { - const BlockCipher* bc = retrieve_block_cipher(global_state(), name); - if(bc) - return bc->KEYLENGTH_MULTIPLE; - - const StreamCipher* sc = retrieve_stream_cipher(global_state(), name); - if(sc) - return sc->KEYLENGTH_MULTIPLE; - - const MessageAuthenticationCode* mac = retrieve_mac(global_state(), name); - if(mac) - return mac->KEYLENGTH_MULTIPLE; - - throw Algorithm_Not_Found(name); - } - -} diff --git a/src/core/lookup.h b/src/core/lookup.h deleted file mode 100644 index 016ad4618..000000000 --- a/src/core/lookup.h +++ /dev/null @@ -1,98 +0,0 @@ -/************************************************* -* Algorithm Lookup Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_LOOKUP_H__ -#define BOTAN_LOOKUP_H__ - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Botan { - -/************************************************* -* Retrieve an object from the lookup table * -*************************************************/ -BOTAN_DLL const BlockCipher* -retrieve_block_cipher(Library_State&, const std::string&); - -BOTAN_DLL const StreamCipher* -retrieve_stream_cipher(Library_State&, const std::string&); - -BOTAN_DLL const HashFunction* -retrieve_hash(Library_State&, const std::string&); - -BOTAN_DLL const MessageAuthenticationCode* -retrieve_mac(Library_State&, const std::string&); - -BOTAN_DLL const S2K* retrieve_s2k(Library_State&, const std::string&); - -BOTAN_DLL const BlockCipherModePaddingMethod* -retrieve_bc_pad(Library_State&, const std::string&); - -/************************************************* -* Get an algorithm object * -*************************************************/ -BOTAN_DLL BlockCipher* get_block_cipher(const std::string&); -BOTAN_DLL StreamCipher* get_stream_cipher(const std::string&); -BOTAN_DLL HashFunction* get_hash(const std::string&); -BOTAN_DLL MessageAuthenticationCode* get_mac(const std::string&); -BOTAN_DLL S2K* get_s2k(const std::string&); -BOTAN_DLL const BlockCipherModePaddingMethod* get_bc_pad(const std::string&); - -/************************************************* -* Get an EMSA/EME/KDF/MGF function * -*************************************************/ -BOTAN_DLL EME* get_eme(const std::string&); -BOTAN_DLL EMSA* get_emsa(const std::string&); -BOTAN_DLL MGF* get_mgf(const std::string&); -BOTAN_DLL KDF* get_kdf(const std::string&); - -/************************************************* -* Get a cipher object * -*************************************************/ -BOTAN_DLL Keyed_Filter* get_cipher(Library_State&, - const std::string&, - const SymmetricKey&, - const InitializationVector&, - Cipher_Dir); - -BOTAN_DLL Keyed_Filter* get_cipher(Library_State&, - const std::string&, - const SymmetricKey&, - Cipher_Dir); - -BOTAN_DLL Keyed_Filter* get_cipher(Library_State&, - const std::string&, Cipher_Dir); - -/************************************************* -* Check to see if an algorithm exists * -*************************************************/ -BOTAN_DLL bool have_algorithm(const std::string&); - -BOTAN_DLL bool have_block_cipher(const std::string&); -BOTAN_DLL bool have_stream_cipher(const std::string&); -BOTAN_DLL bool have_hash(const std::string&); -BOTAN_DLL bool have_mac(const std::string&); - -/************************************************* -* Query information about an algorithm * -*************************************************/ -BOTAN_DLL u32bit block_size_of(const std::string&); -BOTAN_DLL u32bit output_length_of(const std::string&); - -BOTAN_DLL bool valid_keylength_for(u32bit, const std::string&); -BOTAN_DLL u32bit min_keylength_of(const std::string&); -BOTAN_DLL u32bit max_keylength_of(const std::string&); -BOTAN_DLL u32bit keylength_multiple_of(const std::string&); - -} - -#endif diff --git a/src/core/oids.cpp b/src/core/oids.cpp deleted file mode 100644 index 0823625ea..000000000 --- a/src/core/oids.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/************************************************* -* OID Registry Source File * -* (C) 1999-2008 Jack Lloyd * -*************************************************/ - -#include -#include - -namespace Botan { - -namespace OIDS { - -/************************************************* -* Register an OID to string mapping * -*************************************************/ -void add_oid(const OID& oid, const std::string& name) - { - const std::string oid_str = oid.as_string(); - - if(!global_state().is_set("oid2str", oid_str)) - global_state().set("oid2str", oid_str, name); - if(!global_state().is_set("str2oid", name)) - global_state().set("str2oid", name, oid_str); - } - -/************************************************* -* Do an OID to string lookup * -*************************************************/ -std::string lookup(const OID& oid) - { - std::string name = global_state().get("oid2str", oid.as_string()); - if(name == "") - return oid.as_string(); - return name; - } - -/************************************************* -* Do a string to OID lookup * -*************************************************/ -OID lookup(const std::string& name) - { - std::string value = global_state().get("str2oid", name); - if(value != "") - return OID(value); - - try - { - return OID(name); - } - catch(Exception) - { - throw Lookup_Error("No object identifier found for " + name); - } - } - -/************************************************* -* Check to see if an OID exists in the table * -*************************************************/ -bool have_oid(const std::string& name) - { - return global_state().is_set("str2oid", name); - } - -/************************************************* -* Check to see if an OID exists in the table * -*************************************************/ -bool name_of(const OID& oid, const std::string& name) - { - return (oid == lookup(name)); - } - -} - -} diff --git a/src/core/oids.h b/src/core/oids.h deleted file mode 100644 index b5be0e01f..000000000 --- a/src/core/oids.h +++ /dev/null @@ -1,36 +0,0 @@ -/************************************************* -* OID Registry Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_OIDS_H__ -#define BOTAN_OIDS_H__ - -#include - -namespace Botan { - -namespace OIDS { - -/************************************************* -* Register an OID to string mapping * -*************************************************/ -BOTAN_DLL void add_oid(const OID&, const std::string&); - -/************************************************* -* See if an OID exists in the internal table * -*************************************************/ -BOTAN_DLL bool have_oid(const std::string&); - -/************************************************* -* Perform OID<->string mappings * -*************************************************/ -BOTAN_DLL std::string lookup(const OID&); -BOTAN_DLL OID lookup(const std::string&); -BOTAN_DLL bool name_of(const OID&, const std::string&); - -} - -} - -#endif diff --git a/src/core/policy.cpp b/src/core/policy.cpp deleted file mode 100644 index 39810760b..000000000 --- a/src/core/policy.cpp +++ /dev/null @@ -1,492 +0,0 @@ -/************************************************* -* Default Policy Source File * -* (C) 1999-2008 Jack Lloyd * -*************************************************/ - -#include - -namespace Botan { - -namespace { - -/************************************************* -* OID loading helper function * -*************************************************/ -void add_oid(Library_State& config, - const std::string& oid_str, - const std::string& name) - { - if(!config.is_set("oid2str", oid_str)) - config.set("oid2str", oid_str, name); - if(!config.is_set("str2oid", name)) - config.set("str2oid", name, oid_str); - } - -/************************************************* -* Load all of the default OIDs * -*************************************************/ -void set_default_oids(Library_State& config) - { - add_oid(config, "1.2.840.113549.1.1.1", "RSA"); - add_oid(config, "2.5.8.1.1", "RSA"); - add_oid(config, "1.2.840.10040.4.1", "DSA"); - add_oid(config, "1.2.840.10046.2.1", "DH"); - add_oid(config, "1.3.6.1.4.1.3029.1.2.1", "ELG"); - add_oid(config, "1.3.6.1.4.1.25258.1.1", "RW"); - add_oid(config, "1.3.6.1.4.1.25258.1.2", "NR"); - - add_oid(config, "1.3.14.3.2.7", "DES/CBC"); - add_oid(config, "1.2.840.113549.3.7", "TripleDES/CBC"); - add_oid(config, "1.2.840.113549.3.2", "RC2/CBC"); - add_oid(config, "1.2.840.113533.7.66.10", "CAST-128/CBC"); - add_oid(config, "2.16.840.1.101.3.4.1.2", "AES-128/CBC"); - add_oid(config, "2.16.840.1.101.3.4.1.22", "AES-192/CBC"); - add_oid(config, "2.16.840.1.101.3.4.1.42", "AES-256/CBC"); - - add_oid(config, "1.2.840.113549.2.5", "MD5"); - add_oid(config, "1.3.6.1.4.1.11591.12.2", "Tiger(24,3)"); - - add_oid(config, "1.3.14.3.2.26", "SHA-160"); - add_oid(config, "2.16.840.1.101.3.4.2.4", "SHA-224"); - add_oid(config, "2.16.840.1.101.3.4.2.1", "SHA-256"); - add_oid(config, "2.16.840.1.101.3.4.2.2", "SHA-384"); - add_oid(config, "2.16.840.1.101.3.4.2.3", "SHA-512"); - - add_oid(config, "1.2.840.113549.1.9.16.3.6", "KeyWrap.TripleDES"); - add_oid(config, "1.2.840.113549.1.9.16.3.7", "KeyWrap.RC2"); - add_oid(config, "1.2.840.113533.7.66.15", "KeyWrap.CAST-128"); - add_oid(config, "2.16.840.1.101.3.4.1.5", "KeyWrap.AES-128"); - add_oid(config, "2.16.840.1.101.3.4.1.25", "KeyWrap.AES-192"); - add_oid(config, "2.16.840.1.101.3.4.1.45", "KeyWrap.AES-256"); - - add_oid(config, "1.2.840.113549.1.9.16.3.8", "Compression.Zlib"); - - add_oid(config, "1.2.840.113549.1.1.1", "RSA/EME-PKCS1-v1_5"); - add_oid(config, "1.2.840.113549.1.1.2", "RSA/EMSA3(MD2)"); - add_oid(config, "1.2.840.113549.1.1.4", "RSA/EMSA3(MD5)"); - add_oid(config, "1.2.840.113549.1.1.5", "RSA/EMSA3(SHA-160)"); - add_oid(config, "1.2.840.113549.1.1.11", "RSA/EMSA3(SHA-256)"); - add_oid(config, "1.2.840.113549.1.1.12", "RSA/EMSA3(SHA-384)"); - add_oid(config, "1.2.840.113549.1.1.13", "RSA/EMSA3(SHA-512)"); - add_oid(config, "1.3.36.3.3.1.2", "RSA/EMSA3(RIPEMD-160)"); - - add_oid(config, "1.2.840.10040.4.3", "DSA/EMSA1(SHA-160)"); - add_oid(config, "2.16.840.1.101.3.4.3.1", "DSA/EMSA1(SHA-224)"); - add_oid(config, "2.16.840.1.101.3.4.3.2", "DSA/EMSA1(SHA-256)"); - - add_oid(config, "1.3.6.1.4.1.25258.2.1.1.1", "RW/EMSA2(RIPEMD-160)"); - add_oid(config, "1.3.6.1.4.1.25258.2.1.1.2", "RW/EMSA2(SHA-160)"); - add_oid(config, "1.3.6.1.4.1.25258.2.1.1.3", "RW/EMSA2(SHA-224)"); - add_oid(config, "1.3.6.1.4.1.25258.2.1.1.4", "RW/EMSA2(SHA-256)"); - add_oid(config, "1.3.6.1.4.1.25258.2.1.1.5", "RW/EMSA2(SHA-384)"); - add_oid(config, "1.3.6.1.4.1.25258.2.1.1.6", "RW/EMSA2(SHA-512)"); - - add_oid(config, "1.3.6.1.4.1.25258.2.1.2.1", "RW/EMSA4(RIPEMD-160)"); - add_oid(config, "1.3.6.1.4.1.25258.2.1.2.2", "RW/EMSA4(SHA-160)"); - add_oid(config, "1.3.6.1.4.1.25258.2.1.2.3", "RW/EMSA4(SHA-224)"); - add_oid(config, "1.3.6.1.4.1.25258.2.1.2.4", "RW/EMSA4(SHA-256)"); - add_oid(config, "1.3.6.1.4.1.25258.2.1.2.5", "RW/EMSA4(SHA-384)"); - add_oid(config, "1.3.6.1.4.1.25258.2.1.2.6", "RW/EMSA4(SHA-512)"); - - add_oid(config, "1.3.6.1.4.1.25258.2.2.1.1", "NR/EMSA2(RIPEMD-160)"); - add_oid(config, "1.3.6.1.4.1.25258.2.2.1.2", "NR/EMSA2(SHA-160)"); - add_oid(config, "1.3.6.1.4.1.25258.2.2.1.3", "NR/EMSA2(SHA-224)"); - add_oid(config, "1.3.6.1.4.1.25258.2.2.1.4", "NR/EMSA2(SHA-256)"); - add_oid(config, "1.3.6.1.4.1.25258.2.2.1.5", "NR/EMSA2(SHA-384)"); - add_oid(config, "1.3.6.1.4.1.25258.2.2.1.6", "NR/EMSA2(SHA-512)"); - - add_oid(config, "2.5.4.3", "X520.CommonName"); - add_oid(config, "2.5.4.4", "X520.Surname"); - add_oid(config, "2.5.4.5", "X520.SerialNumber"); - add_oid(config, "2.5.4.6", "X520.Country"); - add_oid(config, "2.5.4.7", "X520.Locality"); - add_oid(config, "2.5.4.8", "X520.State"); - add_oid(config, "2.5.4.10", "X520.Organization"); - add_oid(config, "2.5.4.11", "X520.OrganizationalUnit"); - add_oid(config, "2.5.4.12", "X520.Title"); - add_oid(config, "2.5.4.42", "X520.GivenName"); - add_oid(config, "2.5.4.43", "X520.Initials"); - add_oid(config, "2.5.4.44", "X520.GenerationalQualifier"); - add_oid(config, "2.5.4.46", "X520.DNQualifier"); - add_oid(config, "2.5.4.65", "X520.Pseudonym"); - - add_oid(config, "1.2.840.113549.1.5.12", "PKCS5.PBKDF2"); - add_oid(config, "1.2.840.113549.1.5.1", "PBE-PKCS5v15(MD2,DES/CBC)"); - add_oid(config, "1.2.840.113549.1.5.4", "PBE-PKCS5v15(MD2,RC2/CBC)"); - add_oid(config, "1.2.840.113549.1.5.3", "PBE-PKCS5v15(MD5,DES/CBC)"); - add_oid(config, "1.2.840.113549.1.5.6", "PBE-PKCS5v15(MD5,RC2/CBC)"); - add_oid(config, "1.2.840.113549.1.5.10", "PBE-PKCS5v15(SHA-160,DES/CBC)"); - add_oid(config, "1.2.840.113549.1.5.11", "PBE-PKCS5v15(SHA-160,RC2/CBC)"); - add_oid(config, "1.2.840.113549.1.5.13", "PBE-PKCS5v20"); - - add_oid(config, "1.2.840.113549.1.9.1", "PKCS9.EmailAddress"); - add_oid(config, "1.2.840.113549.1.9.2", "PKCS9.UnstructuredName"); - add_oid(config, "1.2.840.113549.1.9.3", "PKCS9.ContentType"); - add_oid(config, "1.2.840.113549.1.9.4", "PKCS9.MessageDigest"); - add_oid(config, "1.2.840.113549.1.9.7", "PKCS9.ChallengePassword"); - add_oid(config, "1.2.840.113549.1.9.14", "PKCS9.ExtensionRequest"); - - add_oid(config, "1.2.840.113549.1.7.1", "CMS.DataContent"); - add_oid(config, "1.2.840.113549.1.7.2", "CMS.SignedData"); - add_oid(config, "1.2.840.113549.1.7.3", "CMS.EnvelopedData"); - add_oid(config, "1.2.840.113549.1.7.5", "CMS.DigestedData"); - add_oid(config, "1.2.840.113549.1.7.6", "CMS.EncryptedData"); - add_oid(config, "1.2.840.113549.1.9.16.1.2", "CMS.AuthenticatedData"); - add_oid(config, "1.2.840.113549.1.9.16.1.9", "CMS.CompressedData"); - - add_oid(config, "2.5.29.14", "X509v3.SubjectKeyIdentifier"); - add_oid(config, "2.5.29.15", "X509v3.KeyUsage"); - add_oid(config, "2.5.29.17", "X509v3.SubjectAlternativeName"); - add_oid(config, "2.5.29.18", "X509v3.IssuerAlternativeName"); - add_oid(config, "2.5.29.19", "X509v3.BasicConstraints"); - add_oid(config, "2.5.29.20", "X509v3.CRLNumber"); - add_oid(config, "2.5.29.21", "X509v3.ReasonCode"); - add_oid(config, "2.5.29.23", "X509v3.HoldInstructionCode"); - add_oid(config, "2.5.29.24", "X509v3.InvalidityDate"); - add_oid(config, "2.5.29.32", "X509v3.CertificatePolicies"); - add_oid(config, "2.5.29.35", "X509v3.AuthorityKeyIdentifier"); - add_oid(config, "2.5.29.36", "X509v3.PolicyConstraints"); - add_oid(config, "2.5.29.37", "X509v3.ExtendedKeyUsage"); - - add_oid(config, "2.5.29.32.0", "X509v3.AnyPolicy"); - - add_oid(config, "1.3.6.1.5.5.7.3.1", "PKIX.ServerAuth"); - add_oid(config, "1.3.6.1.5.5.7.3.2", "PKIX.ClientAuth"); - add_oid(config, "1.3.6.1.5.5.7.3.3", "PKIX.CodeSigning"); - add_oid(config, "1.3.6.1.5.5.7.3.4", "PKIX.EmailProtection"); - add_oid(config, "1.3.6.1.5.5.7.3.5", "PKIX.IPsecEndSystem"); - add_oid(config, "1.3.6.1.5.5.7.3.6", "PKIX.IPsecTunnel"); - add_oid(config, "1.3.6.1.5.5.7.3.7", "PKIX.IPsecUser"); - add_oid(config, "1.3.6.1.5.5.7.3.8", "PKIX.TimeStamping"); - add_oid(config, "1.3.6.1.5.5.7.3.9", "PKIX.OCSPSigning"); - - add_oid(config, "1.3.6.1.5.5.7.8.5", "PKIX.XMPPAddr"); - } - -/************************************************* -* Set the default algorithm aliases * -*************************************************/ -void set_default_aliases(Library_State& config) - { - config.add_alias("OpenPGP.Cipher.1", "IDEA"); - config.add_alias("OpenPGP.Cipher.2", "TripleDES"); - config.add_alias("OpenPGP.Cipher.3", "CAST-128"); - config.add_alias("OpenPGP.Cipher.4", "Blowfish"); - config.add_alias("OpenPGP.Cipher.5", "SAFER-SK(13)"); - config.add_alias("OpenPGP.Cipher.7", "AES-128"); - config.add_alias("OpenPGP.Cipher.8", "AES-192"); - config.add_alias("OpenPGP.Cipher.9", "AES-256"); - config.add_alias("OpenPGP.Cipher.10", "Twofish"); - - config.add_alias("OpenPGP.Digest.1", "MD5"); - config.add_alias("OpenPGP.Digest.2", "SHA-1"); - config.add_alias("OpenPGP.Digest.3", "RIPEMD-160"); - config.add_alias("OpenPGP.Digest.5", "MD2"); - config.add_alias("OpenPGP.Digest.6", "Tiger(24,3)"); - config.add_alias("OpenPGP.Digest.7", "HAVAL(20,5)"); - config.add_alias("OpenPGP.Digest.8", "SHA-256"); - - config.add_alias("TLS.Digest.0", "Parallel(MD5,SHA-160)"); - - config.add_alias("EME-PKCS1-v1_5", "PKCS1v15"); - config.add_alias("OAEP-MGF1", "EME1"); - config.add_alias("EME-OAEP", "EME1"); - config.add_alias("X9.31", "EMSA2"); - config.add_alias("EMSA-PKCS1-v1_5", "EMSA3"); - config.add_alias("PSS-MGF1", "EMSA4"); - config.add_alias("EMSA-PSS", "EMSA4"); - - config.add_alias("Rijndael", "AES"); - config.add_alias("3DES", "TripleDES"); - config.add_alias("DES-EDE", "TripleDES"); - config.add_alias("CAST5", "CAST-128"); - config.add_alias("SHA1", "SHA-160"); - config.add_alias("SHA-1", "SHA-160"); - config.add_alias("SEAL", "SEAL-3.0-BE"); - config.add_alias("MARK-4", "ARC4(256)"); - config.add_alias("OMAC", "CMAC"); - } - -/************************************************* -* Set the default configuration toggles * -*************************************************/ -void set_default_config(Library_State& config) - { - config.set_option("base/default_allocator", "malloc"); - - config.set_option("pk/test/public", "basic"); - config.set_option("pk/test/private", "basic"); - config.set_option("pk/test/private_gen", "all"); - - config.set_option("x509/exts/basic_constraints", "critical"); - config.set_option("x509/exts/subject_key_id", "yes"); - config.set_option("x509/exts/authority_key_id", "yes"); - config.set_option("x509/exts/subject_alternative_name", "yes"); - config.set_option("x509/exts/issuer_alternative_name", "no"); - config.set_option("x509/exts/key_usage", "critical"); - config.set_option("x509/exts/extended_key_usage", "yes"); - config.set_option("x509/exts/crl_number", "yes"); - } - -/************************************************* -* Set the built-in discrete log groups * -*************************************************/ -void set_default_dl_groups(Library_State& config) - { - config.set("dl", "modp/ietf/768", - "-----BEGIN X942 DH PARAMETERS-----" - "MIHIAmEA///////////JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxObIlFK" - "CHmONATd75UZs806QxswKwpt8l8UN0/hNW1tUcJF5IW1dmJefsb0TELppjo2IP//" - "////////AgECAmB//////////+SH7VEQtGEaYmMxRcBuDmiUgScERTPmOgEF31Md" - "ic2RKKUEPMcaAm73yozZ5p0hjZgVhTb5L4obp/Catrao4SLyQtq7MS8/Y3omIXTT" - "HRsQf/////////8=" - "-----END X942 DH PARAMETERS-----"); - - config.set("dl", "modp/ietf/1024", - "-----BEGIN X942 DH PARAMETERS-----" - "MIIBCgKBgQD//////////8kP2qIhaMI0xMZii4DcHNEpAk4IimfMdAILvqY7E5si" - "UUoIeY40BN3vlRmzzTpDGzArCm3yXxQ3T+E1bW1RwkXkhbV2Yl5+xvRMQummN+1r" - "C/9ctvQGt+3uOGv7Womfpa6fJBF8Sx/mSShmUezmU4H//////////wIBAgKBgH//" - "////////5IftURC0YRpiYzFFwG4OaJSBJwRFM+Y6AQXfUx2JzZEopQQ8xxoCbvfK" - "jNnmnSGNmBWFNvkvihun8Jq2tqjhIvJC2rsxLz9jeiYhdNMb9rWF/65begNb9vcc" - "Nf2tRM/S10+SCL4lj/MklDMo9nMpwP//////////" - "-----END X942 DH PARAMETERS-----"); - - config.set("dl", "modp/ietf/1536", - "-----BEGIN X942 DH PARAMETERS-----" - "MIIBigKBwQD//////////8kP2qIhaMI0xMZii4DcHNEpAk4IimfMdAILvqY7E5si" - "UUoIeY40BN3vlRmzzTpDGzArCm3yXxQ3T+E1bW1RwkXkhbV2Yl5+xvRMQummN+1r" - "C/9ctvQGt+3uOGv7Womfpa6fJBF8Sx/mSShmUezkWz3CAHy4oWO/BZjaSDYcVdOa" - "aRY/qP0kz1+DZV0j3KOtlhxi81YghVK7ntUpB3CWlm1nDDVOSryYBPF0bAjKI3Mn" - "//////////8CAQICgcB//////////+SH7VEQtGEaYmMxRcBuDmiUgScERTPmOgEF" - "31Mdic2RKKUEPMcaAm73yozZ5p0hjZgVhTb5L4obp/Catrao4SLyQtq7MS8/Y3om" - "IXTTG/a1hf+uW3oDW/b3HDX9rUTP0tdPkgi+JY/zJJQzKPZyLZ7hAD5cULHfgsxt" - "JBsOKunNNIsf1H6SZ6/Bsq6R7lHWyw4xeasQQqldz2qUg7hLSzazhhqnJV5MAni6" - "NgRlEbmT//////////8=" - "-----END X942 DH PARAMETERS-----"); - - config.set("dl", "modp/ietf/2048", - "-----BEGIN X942 DH PARAMETERS-----" - "MIICDAKCAQEA///////////JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxOb" - "IlFKCHmONATd75UZs806QxswKwpt8l8UN0/hNW1tUcJF5IW1dmJefsb0TELppjft" - "awv/XLb0Brft7jhr+1qJn6WunyQRfEsf5kkoZlHs5Fs9wgB8uKFjvwWY2kg2HFXT" - "mmkWP6j9JM9fg2VdI9yjrZYcYvNWIIVSu57VKQdwlpZtZww1Tkq8mATxdGwIyhgh" - "fDKQXkYuNs474553LBgOhgObJ4Oi7Aeij7XFXfBvTFLJ3ivL9pVYFxg5lUl86pVq" - "5RXSJhiY+gUQFXKOWoqsqmj//////////wIBAgKCAQB//////////+SH7VEQtGEa" - "YmMxRcBuDmiUgScERTPmOgEF31Mdic2RKKUEPMcaAm73yozZ5p0hjZgVhTb5L4ob" - "p/Catrao4SLyQtq7MS8/Y3omIXTTG/a1hf+uW3oDW/b3HDX9rUTP0tdPkgi+JY/z" - "JJQzKPZyLZ7hAD5cULHfgsxtJBsOKunNNIsf1H6SZ6/Bsq6R7lHWyw4xeasQQqld" - "z2qUg7hLSzazhhqnJV5MAni6NgRlDBC+GUgvIxcbZx3xzzuWDAdDAc2TwdF2A9FH" - "2uKu+DemKWTvFeX7SqwLjBzKpL51SrVyiukTDEx9AogKuUctRVZVNH//////////" - "-----END X942 DH PARAMETERS-----"); - - config.set("dl", "modp/ietf/3072", - "-----BEGIN X942 DH PARAMETERS-----" - "MIIDDAKCAYEA///////////JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxOb" - "IlFKCHmONATd75UZs806QxswKwpt8l8UN0/hNW1tUcJF5IW1dmJefsb0TELppjft" - "awv/XLb0Brft7jhr+1qJn6WunyQRfEsf5kkoZlHs5Fs9wgB8uKFjvwWY2kg2HFXT" - "mmkWP6j9JM9fg2VdI9yjrZYcYvNWIIVSu57VKQdwlpZtZww1Tkq8mATxdGwIyhgh" - "fDKQXkYuNs474553LBgOhgObJ4Oi7Aeij7XFXfBvTFLJ3ivL9pVYFxg5lUl86pVq" - "5RXSJhiY+gUQFXKOWoqqxC2tMxcNBFB6M6hVIavfHLpk7PuFBFjb7wqK6nFXXQYM" - "fbOXD4Wm4eTHq/WujNsJM9cejJTgSiVhnc7j0iYa0u5r8S/6BtmKCGTYdgJzPshq" - "ZFIfKxgXeyAMu+EXV3phXWx3CYjAutlG4gjiT6B05asxQ9tb/OD9EI5LgtEgqTrS" - "yv//////////AgECAoIBgH//////////5IftURC0YRpiYzFFwG4OaJSBJwRFM+Y6" - "AQXfUx2JzZEopQQ8xxoCbvfKjNnmnSGNmBWFNvkvihun8Jq2tqjhIvJC2rsxLz9j" - "eiYhdNMb9rWF/65begNb9vccNf2tRM/S10+SCL4lj/MklDMo9nItnuEAPlxQsd+C" - "zG0kGw4q6c00ix/UfpJnr8GyrpHuUdbLDjF5qxBCqV3PapSDuEtLNrOGGqclXkwC" - "eLo2BGUMEL4ZSC8jFxtnHfHPO5YMB0MBzZPB0XYD0Ufa4q74N6YpZO8V5ftKrAuM" - "HMqkvnVKtXKK6RMMTH0CiAq5Ry1FVWIW1pmLhoIoPRnUKpDV745dMnZ9woIsbfeF" - "RXU4q66DBj7Zy4fC03DyY9X610ZthJnrj0ZKcCUSsM7ncekTDWl3NfiX/QNsxQQy" - "bDsBOZ9kNTIpD5WMC72QBl3wi6u9MK62O4TEYF1so3EEcSfQOnLVmKHtrf5wfohH" - "JcFokFSdaWV//////////w==" - "-----END X942 DH PARAMETERS-----"); - - config.set("dl", "modp/ietf/4096", - "-----BEGIN X942 DH PARAMETERS-----" - "MIIEDAKCAgEA///////////JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxOb" - "IlFKCHmONATd75UZs806QxswKwpt8l8UN0/hNW1tUcJF5IW1dmJefsb0TELppjft" - "awv/XLb0Brft7jhr+1qJn6WunyQRfEsf5kkoZlHs5Fs9wgB8uKFjvwWY2kg2HFXT" - "mmkWP6j9JM9fg2VdI9yjrZYcYvNWIIVSu57VKQdwlpZtZww1Tkq8mATxdGwIyhgh" - "fDKQXkYuNs474553LBgOhgObJ4Oi7Aeij7XFXfBvTFLJ3ivL9pVYFxg5lUl86pVq" - "5RXSJhiY+gUQFXKOWoqqxC2tMxcNBFB6M6hVIavfHLpk7PuFBFjb7wqK6nFXXQYM" - "fbOXD4Wm4eTHq/WujNsJM9cejJTgSiVhnc7j0iYa0u5r8S/6BtmKCGTYdgJzPshq" - "ZFIfKxgXeyAMu+EXV3phXWx3CYjAutlG4gjiT6B05asxQ9tb/OD9EI5LgtEgqSEI" - "ARpyPBKnh+bXiHGaEL26WyaZwycYavTiPBqUaDS2FQvaJYPpyirUTOjbu8LbBN6O" - "+S6O/BQfvsqmKHxZR05rwF2ZspZPoJDDoiM7oYZRW+ftH2EpcM7i16+4G912IXBI" - "HNAGkSfVsFqpk7TqmI2P3cGG/7fckKbAj030Nck0BjGZ//////////8CAQICggIA" - "f//////////kh+1RELRhGmJjMUXAbg5olIEnBEUz5joBBd9THYnNkSilBDzHGgJu" - "98qM2eadIY2YFYU2+S+KG6fwmra2qOEi8kLauzEvP2N6JiF00xv2tYX/rlt6A1v2" - "9xw1/a1Ez9LXT5IIviWP8ySUMyj2ci2e4QA+XFCx34LMbSQbDirpzTSLH9R+kmev" - "wbKuke5R1ssOMXmrEEKpXc9qlIO4S0s2s4YapyVeTAJ4ujYEZQwQvhlILyMXG2cd" - "8c87lgwHQwHNk8HRdgPRR9rirvg3pilk7xXl+0qsC4wcyqS+dUq1corpEwxMfQKI" - "CrlHLUVVYhbWmYuGgig9GdQqkNXvjl0ydn3Cgixt94VFdTirroMGPtnLh8LTcPJj" - "1frXRm2EmeuPRkpwJRKwzudx6RMNaXc1+Jf9A2zFBDJsOwE5n2Q1MikPlYwLvZAG" - "XfCLq70wrrY7hMRgXWyjcQRxJ9A6ctWYoe2t/nB+iEclwWiQVJCEAI05HglTw/Nr" - "xDjNCF7dLZNM4ZOMNXpxHg1KNBpbCoXtEsH05RVqJnRt3eFtgm9HfJdHfgoP32VT" - "FD4so6c14C7M2Usn0Ehh0RGd0MMorfP2j7CUuGdxa9fcDe67ELgkDmgDSJPq2C1U" - "ydp1TEbH7uDDf9vuSFNgR6b6GuSaAxjM//////////8=" - "-----END X942 DH PARAMETERS-----"); - - config.set("dl", "modp/ietf/6144", - "-----BEGIN X942 DH PARAMETERS-----" - "MIIGDAKCAwEA///////////JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxOb" - "IlFKCHmONATd75UZs806QxswKwpt8l8UN0/hNW1tUcJF5IW1dmJefsb0TELppjft" - "awv/XLb0Brft7jhr+1qJn6WunyQRfEsf5kkoZlHs5Fs9wgB8uKFjvwWY2kg2HFXT" - "mmkWP6j9JM9fg2VdI9yjrZYcYvNWIIVSu57VKQdwlpZtZww1Tkq8mATxdGwIyhgh" - "fDKQXkYuNs474553LBgOhgObJ4Oi7Aeij7XFXfBvTFLJ3ivL9pVYFxg5lUl86pVq" - "5RXSJhiY+gUQFXKOWoqqxC2tMxcNBFB6M6hVIavfHLpk7PuFBFjb7wqK6nFXXQYM" - "fbOXD4Wm4eTHq/WujNsJM9cejJTgSiVhnc7j0iYa0u5r8S/6BtmKCGTYdgJzPshq" - "ZFIfKxgXeyAMu+EXV3phXWx3CYjAutlG4gjiT6B05asxQ9tb/OD9EI5LgtEgqSEI" - "ARpyPBKnh+bXiHGaEL26WyaZwycYavTiPBqUaDS2FQvaJYPpyirUTOjbu8LbBN6O" - "+S6O/BQfvsqmKHxZR05rwF2ZspZPoJDDoiM7oYZRW+ftH2EpcM7i16+4G912IXBI" - "HNAGkSfVsFqpk7TqmI2P3cGG/7fckKbAj030Nck0AoSSNsP6tNJ8cCbB1NyyYCZG" - "3sl1HnY9uje9+P+UBq2eUw7l2zgvQTABrrBqU+2QJ9gxF5cnsIZaiRjaPtvrz5sU" - "7UTObLrO1Lsb238UR+bMJUszIFFRK9evQm+49AE3jNK/WYPKAcZLkuzwMuoV0XId" - "A/SC185udP721V5wL0aYDIK1qEAxkAscnlnnyX++x+jzI6l6fjbMiL4PHUW3/1ha" - "xUvUB7IrQVSqzI9tfr9I4dgUzF7SD4A34KeXFe7ym+MoBqHVi7fF2nb1UKo9ih+/" - "8OsZzLGjE9Vc2lbJ7C7yljI4f+jXbjwEaAQ+j2Y/SGDuEr8tWwt0dNbmlPkebcxA" - "JP//////////AoIDAH//////////5IftURC0YRpiYzFFwG4OaJSBJwRFM+Y6AQXf" - "Ux2JzZEopQQ8xxoCbvfKjNnmnSGNmBWFNvkvihun8Jq2tqjhIvJC2rsxLz9jeiYh" - "dNMb9rWF/65begNb9vccNf2tRM/S10+SCL4lj/MklDMo9nItnuEAPlxQsd+CzG0k" - "Gw4q6c00ix/UfpJnr8GyrpHuUdbLDjF5qxBCqV3PapSDuEtLNrOGGqclXkwCeLo2" - "BGUMEL4ZSC8jFxtnHfHPO5YMB0MBzZPB0XYD0Ufa4q74N6YpZO8V5ftKrAuMHMqk" - "vnVKtXKK6RMMTH0CiAq5Ry1FVWIW1pmLhoIoPRnUKpDV745dMnZ9woIsbfeFRXU4" - "q66DBj7Zy4fC03DyY9X610ZthJnrj0ZKcCUSsM7ncekTDWl3NfiX/QNsxQQybDsB" - "OZ9kNTIpD5WMC72QBl3wi6u9MK62O4TEYF1so3EEcSfQOnLVmKHtrf5wfohHJcFo" - "kFSQhACNOR4JU8Pza8Q4zQhe3S2TTOGTjDV6cR4NSjQaWwqF7RLB9OUVaiZ0bd3h" - "bYJvR3yXR34KD99lUxQ+LKOnNeAuzNlLJ9BIYdERndDDKK3z9o+wlLhncWvX3A3u" - "uxC4JA5oA0iT6tgtVMnadUxGx+7gw3/b7khTYEem+hrkmgFCSRth/VppPjgTYOpu" - "WTATI29kuo87Ht0b3vx/ygNWzymHcu2cF6CYANdYNSn2yBPsGIvLk9hDLUSMbR9t" - "9efNinaiZzZdZ2pdje2/iiPzZhKlmZAoqJXr16E33HoAm8ZpX6zB5QDjJcl2eBl1" - "Cui5DoH6QWvnNzp/e2qvOBejTAZBWtQgGMgFjk8s8+S/32P0eZHUvT8bZkRfB46i" - "2/+sLWKl6gPZFaCqVWZHtr9fpHDsCmYvaQfAG/BTy4r3eU3xlANQ6sXb4u07eqhV" - "HsUP3/h1jOZY0Ynqrm0rZPYXeUsZHD/0a7ceAjQCH0ezH6Qwdwlflq2Fujprc0p8" - "jzbmIBJ//////////wIBAg==" - "-----END X942 DH PARAMETERS-----"); - - config.set("dl", "modp/ietf/8192", - "-----BEGIN X942 DH PARAMETERS-----" - "MIIIDAKCBAEA///////////JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxOb" - "IlFKCHmONATd75UZs806QxswKwpt8l8UN0/hNW1tUcJF5IW1dmJefsb0TELppjft" - "awv/XLb0Brft7jhr+1qJn6WunyQRfEsf5kkoZlHs5Fs9wgB8uKFjvwWY2kg2HFXT" - "mmkWP6j9JM9fg2VdI9yjrZYcYvNWIIVSu57VKQdwlpZtZww1Tkq8mATxdGwIyhgh" - "fDKQXkYuNs474553LBgOhgObJ4Oi7Aeij7XFXfBvTFLJ3ivL9pVYFxg5lUl86pVq" - "5RXSJhiY+gUQFXKOWoqqxC2tMxcNBFB6M6hVIavfHLpk7PuFBFjb7wqK6nFXXQYM" - "fbOXD4Wm4eTHq/WujNsJM9cejJTgSiVhnc7j0iYa0u5r8S/6BtmKCGTYdgJzPshq" - "ZFIfKxgXeyAMu+EXV3phXWx3CYjAutlG4gjiT6B05asxQ9tb/OD9EI5LgtEgqSEI" - "ARpyPBKnh+bXiHGaEL26WyaZwycYavTiPBqUaDS2FQvaJYPpyirUTOjbu8LbBN6O" - "+S6O/BQfvsqmKHxZR05rwF2ZspZPoJDDoiM7oYZRW+ftH2EpcM7i16+4G912IXBI" - "HNAGkSfVsFqpk7TqmI2P3cGG/7fckKbAj030Nck0AoSSNsP6tNJ8cCbB1NyyYCZG" - "3sl1HnY9uje9+P+UBq2eUw7l2zgvQTABrrBqU+2QJ9gxF5cnsIZaiRjaPtvrz5sU" - "7UTObLrO1Lsb238UR+bMJUszIFFRK9evQm+49AE3jNK/WYPKAcZLkuzwMuoV0XId" - "A/SC185udP721V5wL0aYDIK1qEAxkAscnlnnyX++x+jzI6l6fjbMiL4PHUW3/1ha" - "xUvUB7IrQVSqzI9tfr9I4dgUzF7SD4A34KeXFe7ym+MoBqHVi7fF2nb1UKo9ih+/" - "8OsZzLGjE9Vc2lbJ7C7yljI4f+jXbjwEaAQ+j2Y/SGDuEr8tWwt0dNbmlPkebb4R" - "WXSjkm8S/uXkOHd8tqky34zYvsTQc7kxujvIMraNndMAdB+nv4r8R+0ldvaTa6Qk" - "ZjqrY5xa5PVoNCO0dCvxyXgjjxbL451lLeP9uL78hIrZIiIuBKQDfAcT61eoGiPw" - "xzRz/GRs6jBrS8vIhi+Dhd36nUt/osCH6HloMwPtW906Bis89bOieKZtKhP4P0T4" - "Ld8xDuB0q2o2RZfomaAlXcFk8xzFCEaFHfmrSBld7X6hsdUQvX7nTXP682vDHs+i" - "aDWQRvTrh5+SQAlDi0gcbNeImgAu1e44K8kZDab8Am5HlVjkR1Z36aqeMFDidlaU" - "38gfVuiAuW5xYMmA3Zjt09///////////wKCBAB//////////+SH7VEQtGEaYmMx" - "RcBuDmiUgScERTPmOgEF31Mdic2RKKUEPMcaAm73yozZ5p0hjZgVhTb5L4obp/Ca" - "trao4SLyQtq7MS8/Y3omIXTTG/a1hf+uW3oDW/b3HDX9rUTP0tdPkgi+JY/zJJQz" - "KPZyLZ7hAD5cULHfgsxtJBsOKunNNIsf1H6SZ6/Bsq6R7lHWyw4xeasQQqldz2qU" - "g7hLSzazhhqnJV5MAni6NgRlDBC+GUgvIxcbZx3xzzuWDAdDAc2TwdF2A9FH2uKu" - "+DemKWTvFeX7SqwLjBzKpL51SrVyiukTDEx9AogKuUctRVViFtaZi4aCKD0Z1CqQ" - "1e+OXTJ2fcKCLG33hUV1OKuugwY+2cuHwtNw8mPV+tdGbYSZ649GSnAlErDO53Hp" - "Ew1pdzX4l/0DbMUEMmw7ATmfZDUyKQ+VjAu9kAZd8IurvTCutjuExGBdbKNxBHEn" - "0Dpy1Zih7a3+cH6IRyXBaJBUkIQAjTkeCVPD82vEOM0IXt0tk0zhk4w1enEeDUo0" - "GlsKhe0SwfTlFWomdG3d4W2Cb0d8l0d+Cg/fZVMUPiyjpzXgLszZSyfQSGHREZ3Q" - "wyit8/aPsJS4Z3Fr19wN7rsQuCQOaANIk+rYLVTJ2nVMRsfu4MN/2+5IU2BHpvoa" - "5JoBQkkbYf1aaT44E2DqblkwEyNvZLqPOx7dG978f8oDVs8ph3LtnBegmADXWDUp" - "9sgT7BiLy5PYQy1EjG0fbfXnzYp2omc2XWdqXY3tv4oj82YSpZmQKKiV69ehN9x6" - "AJvGaV+sweUA4yXJdngZdQrouQ6B+kFr5zc6f3tqrzgXo0wGQVrUIBjIBY5PLPPk" - "v99j9HmR1L0/G2ZEXweOotv/rC1ipeoD2RWgqlVmR7a/X6Rw7ApmL2kHwBvwU8uK" - "93lN8ZQDUOrF2+LtO3qoVR7FD9/4dYzmWNGJ6q5tK2T2F3lLGRw/9Gu3HgI0Ah9H" - "sx+kMHcJX5athbo6a3NKfI823wisulHJN4l/cvIcO75bVJlvxmxfYmg53JjdHeQZ" - "W0bO6YA6D9PfxX4j9pK7e0m10hIzHVWxzi1yerQaEdo6FfjkvBHHi2XxzrKW8f7c" - "X35CRWyRERcCUgG+A4n1q9QNEfhjmjn+MjZ1GDWl5eRDF8HC7v1Opb/RYEP0PLQZ" - "gfat7p0DFZ562dE8UzaVCfwfonwW75iHcDpVtRsiy/RM0BKu4LJ5jmKEI0KO/NWk" - "DK72v1DY6ohev3Omuf15teGPZ9E0GsgjenXDz8kgBKHFpA42a8RNABdq9xwV5IyG" - "034BNyPKrHIjqzv01U8YKHE7K0pv5A+rdEBctziwZMBuzHbp7///////////AgEC" - "-----END X942 DH PARAMETERS-----"); - - config.set("dl", "dsa/jce/512", - "-----BEGIN DSA PARAMETERS-----" - "MIGdAkEA/KaCzo4Syrom78z3EQ5SbbB4sF7ey80etKII864WF64B81uRpH5t9jQT" - "xeEu0ImbzRMqzVDZkVG9xD7nN1kuFwIVAJYu3cw2nLqOuyYO5rahJtk0bjjFAkEA" - "3gtU76vylwh+5iPVylWIxkgo70/eT/uuHs0gBndrBbEbgeo83pvDlkwWh8UyW/Q9" - "fM76DQqGvl3/3dDRFD3NdQ==" - "-----END DSA PARAMETERS-----"); - - config.set("dl", "dsa/jce/768", - "-----BEGIN DSA PARAMETERS-----" - "MIHdAmEA6eZCWZ01XzfJf/01ZxILjiXJzUPpJ7OpZw++xdiQFBki0sOzrSSACTeZ" - "hp0ehGqrSfqwrSbSzmoiIZ1HC859d31KIfvpwnC1f2BwAvPO+Dk2lM9F7jaIwRqM" - "VqsSej2vAhUAnNvYTJ8awvOND4D0KrlS5zOL9RECYQDe7p717RUWzn5pXmcrjO5F" - "5s17NuDmOF+JS6hhY/bz5sbU6KgRRtQBfe/dccvZD6Akdlm4i3zByJT0gmn9Txqs" - "CjBTjf9rP8ds+xMcnnlltYhYqwpDtVczWRKoqlR/lWg=" - "-----END DSA PARAMETERS-----"); - - config.set("dl", "dsa/jce/1024", - "-----BEGIN DSA PARAMETERS-----" - "MIIBHgKBgQD9f1OBHXUSKVLfSpwu7OTn9hG3UjzvRADDHj+AtlEmaUVdQCJR+1k9" - "jVj6v8X1ujD2y5tVbNeBO4AdNG/yZmC3a5lQpaSfn+gEexAiwk+7qdf+t8Yb+DtX" - "58aophUPBPuD9tPFHsMCNVQTWhaRMvZ1864rYdcq7/IiAxmd0UgBxwIVAJdgUI8V" - "IwvMspK5gqLrhAvwWBz1AoGARpYDUS4wJ4zTlHWV2yLuyYJqYyKtyXNE9B10DDJX" - "JMj577qn1NgD/4xgnc0QDrxb38+tfGpCX66nhuogUOvpg1HqH9of3yTWlHqmuaoj" - "dmlTgC9NfUqOy6BtGXaKJJH/sW0O+cQ6mbX3FnL/bwoktETQc20E04oaEyLa9s3Y" - "jJ0=" - "-----END DSA PARAMETERS-----"); - - config.set("dl", "dsa/botan/2048", - "-----BEGIN DSA PARAMETERS-----" - "MIICLAKCAQEAkcSKT9+898Aq6V59oSYSK13Shk9Vm4fo50oobVL1m9HeaN/WRdDg" - "DGDAgAMYkZgDdO61lKUyv9Z7mgnqxLhmOgeRDmjzlGX7cEDSXfE5MuusQ0elMOy6" - "YchU+biA08DDZgCAWHxFVm2t4mvVo5S+CTtMDyS1r/747GxbPlf7iQJam8FnaZMh" - "MeFtPJTvyrGNDfBhIDzFPmEDvHLVWUv9QMplOA9EqahR3LB1SV/AM6ilgHGhvXj+" - "BS9mVVZI60txnSr+i0iA+NrW8VgYuhePiSdMhwvpuW6wjEbEAEDMLv4d+xsYaN0x" - "nePDSjKmOrbrEiQgmkGWgMx5AtFyjU354QIhAIzX1FD4bwrZTu5M5GmodW0evRBY" - "JBlD6v+ws1RYXpJNAoIBAA2fXgdhtNvRgz1qsalhoJlsXyIwP3LYTBQPZ8Qx2Uq1" - "cVvqgaDJjTnOS8941rnryJXTT+idlAkdWEhhXvFfXobxHZb2yWniA936WDVkIKSc" - "tES1lbkBqTPP4HZ7WU8YoHt/kd7NukRriJkPePL/kfL+fNQ/0uRtGOraH3u2YCxh" - "f27zpLKE8v2boQo2BC3o+oeiyjZZf+yBFXoUheRAQd8CgwERy4gLvm7UlIFIhvll" - "zcMTX1zPE4Nyi/ZbgG+WksCxDWxMCcdabKO0ATyxarLBBfa+I66pAA6rIXiYX5cs" - "mAV+HIbkTnIYaI6krg82NtzKdFydzU5q/7Z8y8E9YTE=" - "-----END DSA PARAMETERS-----"); - - config.set("dl", "dsa/botan/3072", - "-----BEGIN DSA PARAMETERS-----" - "MIIDLAKCAYEA5LUIgHWWY1heFCRgyi2d/xMviuTIQN2jomZoiRJP5WOLhOiim3rz" - "+hIJvmv8S1By7Tsrc4e68/hX9HioAijvNgC3az3Pth0g00RlslBtLK+H3259wM6R" - "vS0Wekb2rcwxxTHk+cervbkq3fNbCoBsZikqX14X6WTdCZkDczrEKKs12A6m9oW/" - "uovkBo5UGK5eytno/wc94rY+Tn6tNciptwtb1Hz7iNNztm83kxk5sKtxvVWVgJCG" - "2gFVM30YWg5Ps2pRmxtiArhZHmACRJzxzTpmOE9tIHOxzXO+ypO68eGmEX0COPIi" - "rh7X/tGFqJDn9n+rj+uXU8wTSlGD3+h64llfe1wtn7tCJJ/dWVE+HTOWs+sv2GaE" - "8oWoRI/nV6ApiBxAdguU75Gb35dAw4OJWZ7FGm6btRmo4GhJHpzgovz+PLYNZs8N" - "+tIKjsaEBIaEphREV1vRck1zUrRKdgB3s71r04XOWwpyUMwL92jagpI4Buuc+7E4" - "hDcxthggjHWbAiEAs+vTZOxp74zzuvZDt1c0sWM5suSeXN4bWcHp+0DuDFsCggGA" - "K+0h7vg5ZKIwrom7px2ffDnFL8gim047x+WUTTKdoQ8BDqyee69sAJ/E6ylgcj4r" - "Vt9GY+TDrIAOkljeL3ZJ0gZ4KJP4Ze/KSY0u7zAHTqXop6smJxKk2UovOwuaku5A" - "D7OKPMWaXcfkNtXABLIuNQKDgbUck0B+sy1K4P1Cy0XhLQ7O6KJiOO3iCCp7FSIR" - "PGbO+NdFxs88uUX4TS9N4W1Epx3hmCcOE/A1U8iLjTI60LlIob8hA6lJl5tu0W+1" - "88lT2Vt8jojKZ9z1pjb7nKOdkkIV96iE7Wx+48ltjZcVQnl0t8Q1EoLhPTdz99KL" - "RS8QiSoTx1hzKN6kgntrNpsqjcFyrcWD9R8qZZjFSD5bxGewL5HQWcQC0Y4sJoD3" - "dqoG9JKAoscsF8xC1bbnQMXEsas8UcLtCSviotiwU65Xc9FCXtKwjwbi3VBZLfGk" - "eMFVkc39EVZP+I/zi3IdQjkv2kcyEtz9jS2IqXagCv/m//tDCjWeZMorNRyiQSOU" - "-----END DSA PARAMETERS-----"); - } -} - -/************************************************* -* Set the default policy * -*************************************************/ -void Library_State::load_default_config() - { - set_default_config(*this); - set_default_aliases(*this); - set_default_oids(*this); - set_default_dl_groups(*this); - } - -} diff --git a/src/core/selftest/info.txt b/src/core/selftest/info.txt new file mode 100644 index 000000000..e786437d5 --- /dev/null +++ b/src/core/selftest/info.txt @@ -0,0 +1,24 @@ +realname "Selftests" + +define SELFTESTS + +load_on auto + + +selftest.cpp +selftest.h + + + +hex +des +aes +sha1 +sha2 +hmac +ecb +cbc +cfb +ofb +ctr + diff --git a/src/core/selftest/selftest.cpp b/src/core/selftest/selftest.cpp new file mode 100644 index 000000000..0dede1c9d --- /dev/null +++ b/src/core/selftest/selftest.cpp @@ -0,0 +1,163 @@ +/************************************************* +* Startup Self Tests Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include +#include + +namespace Botan { + +namespace { + +/************************************************* +* Perform a Known Answer Test * +*************************************************/ +void do_kat(const std::string& in, const std::string& out, + const std::string& algo_name, Filter* filter) + { + if(out.length()) + { + Pipe pipe(new Hex_Decoder, filter, new Hex_Encoder); + pipe.process_msg(in); + + if(out != pipe.read_all_as_string()) + throw Self_Test_Failure("FIPS-140 " + algo_name + " test"); + } + } + +/************************************************* +* Perform a KAT for a cipher * +*************************************************/ +void cipher_kat(const std::string& in, const std::string& out, + const std::string& key, const std::string& iv, + const std::string& cipher) + { + do_kat(in, out, cipher, + get_cipher(global_state(), cipher, key, iv, ENCRYPTION)); + do_kat(out, in, cipher, + get_cipher(global_state(), cipher, key, iv, DECRYPTION)); + } + +/************************************************* +* Perform a KAT for a cipher * +*************************************************/ +void cipher_kat(const std::string& cipher, const std::string& key, + const std::string& iv, const std::string& in, + const std::string& ecb_out, const std::string& cbc_out, + const std::string& cfb_out, const std::string& ofb_out, + const std::string& ctr_out) + { + if(!have_block_cipher(cipher)) + return; + + cipher_kat(in, ecb_out, key, "", cipher + "/ECB"); + cipher_kat(in, cbc_out, key, iv, cipher + "/CBC/NoPadding"); + cipher_kat(in, cfb_out, key, iv, cipher + "/CFB"); + cipher_kat(in, ofb_out, key, iv, cipher + "/OFB"); + cipher_kat(in, ctr_out, key, iv, cipher + "/CTR-BE"); + } + +/************************************************* +* Perform a KAT for a hash * +*************************************************/ +void hash_kat(const std::string& hash, const std::string& in, + const std::string& out) + { + if(!have_hash(hash)) + return; + do_kat(in, out, hash, new Hash_Filter(hash)); + } + +/************************************************* +* Perform a KAT for a MAC * +*************************************************/ +void mac_kat(const std::string& mac, const std::string& in, + const std::string& out, const std::string& key) + { + if(!have_mac(mac)) + return; + do_kat(in, out, mac, new MAC_Filter(mac, key)); + } + +} + +/************************************************* +* Perform FIPS 140 Self Tests * +*************************************************/ +bool passes_self_tests() + { + try { + cipher_kat("DES", "0123456789ABCDEF", "1234567890ABCDEF", + "4E6F77206973207468652074696D6520666F7220616C6C20", + "3FA40E8A984D48156A271787AB8883F9893D51EC4B563B53", + "E5C7CDDE872BF27C43E934008C389C0F683788499A7C05F6", + "F3096249C7F46E51A69E839B1A92F78403467133898EA622", + "F3096249C7F46E5135F24A242EEB3D3F3D6D5BE3255AF8C3", + "F3096249C7F46E51163A8CA0FFC94C27FA2F80F480B86F75"); + + cipher_kat("TripleDES", + "385D7189A5C3D485E1370AA5D408082B5CCCCB5E19F2D90E", + "C141B5FCCD28DC8A", + "6E1BD7C6120947A464A6AAB293A0F89A563D8D40D3461B68", + "64EAAD4ACBB9CEAD6C7615E7C7E4792FE587D91F20C7D2F4", + "6235A461AFD312973E3B4F7AA7D23E34E03371F8E8C376C9", + "E26BA806A59B0330DE40CA38E77A3E494BE2B212F6DD624B", + "E26BA806A59B03307DE2BCC25A08BA40A8BA335F5D604C62", + "E26BA806A59B03303C62C2EFF32D3ACDD5D5F35EBCC53371"); + + cipher_kat("AES", + "2B7E151628AED2A6ABF7158809CF4F3C", + "000102030405060708090A0B0C0D0E0F", + "6BC1BEE22E409F96E93D7E117393172A" + "AE2D8A571E03AC9C9EB76FAC45AF8E51", + "3AD77BB40D7A3660A89ECAF32466EF97" + "F5D3D58503B9699DE785895A96FDBAAF", + "7649ABAC8119B246CEE98E9B12E9197D" + "5086CB9B507219EE95DB113A917678B2", + "3B3FD92EB72DAD20333449F8E83CFB4A" + "C8A64537A0B3A93FCDE3CDAD9F1CE58B", + "3B3FD92EB72DAD20333449F8E83CFB4A" + "7789508D16918F03F53C52DAC54ED825", + "3B3FD92EB72DAD20333449F8E83CFB4A" + "010C041999E03F36448624483E582D0E"); + + hash_kat("SHA-1", "", "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709"); + hash_kat("SHA-1", "616263", "A9993E364706816ABA3E25717850C26C9CD0D89D"); + hash_kat("SHA-1", + "6162636462636465636465666465666765666768666768696768696A" + "68696A6B696A6B6C6A6B6C6D6B6C6D6E6C6D6E6F6D6E6F706E6F7071", + "84983E441C3BD26EBAAE4AA1F95129E5E54670F1"); + + hash_kat("SHA-256", "", + "E3B0C44298FC1C149AFBF4C8996FB924" + "27AE41E4649B934CA495991B7852B855"); + hash_kat("SHA-256", "616263", + "BA7816BF8F01CFEA414140DE5DAE2223" + "B00361A396177A9CB410FF61F20015AD"); + hash_kat("SHA-256", + "6162636462636465636465666465666765666768666768696768696A" + "68696A6B696A6B6C6A6B6C6D6B6C6D6E6C6D6E6F6D6E6F706E6F7071", + "248D6A61D20638B8E5C026930C3E6039" + "A33CE45964FF2167F6ECEDD419DB06C1"); + + mac_kat("HMAC(SHA-1)", "4869205468657265", + "B617318655057264E28BC0B6FB378C8EF146BE00", + "0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B"); + + mac_kat("HMAC(SHA-256)", "4869205468657265", + "198A607EB44BFBC69903A0F1CF2BBDC5" + "BA0AA3F3D9AE3C1C7A3B1696A0B68CF7", + "0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B" + "0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B"); + } + catch(std::exception& e) + { + return false; + } + + return true; + } + +} diff --git a/src/core/selftest/selftest.h b/src/core/selftest/selftest.h new file mode 100644 index 000000000..ff011a32c --- /dev/null +++ b/src/core/selftest/selftest.h @@ -0,0 +1,20 @@ +/************************************************* +* Startup Self Test Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_SELF_TEST_H__ +#define BOTAN_SELF_TEST_H__ + +#include + +namespace Botan { + +/************************************************* +* Self Tests * +*************************************************/ +BOTAN_DLL bool passes_self_tests(); + +} + +#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 eb3a12702..000000000 --- a/src/mutex/noop_mutex/mux_noop.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/************************************************* -* No-Op Mutex Factory Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#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 a5b802cc0..000000000 --- a/src/mutex/noop_mutex/mux_noop.h +++ /dev/null @@ -1,24 +0,0 @@ -/************************************************* -* No-Op Mutex Factory Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#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 d003fa298..000000000 --- a/src/mutex/pthreads/mux_pthr.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/************************************************* -* Pthread Mutex Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#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 efdabfed4..000000000 --- a/src/mutex/pthreads/mux_pthr.h +++ /dev/null @@ -1,24 +0,0 @@ -/************************************************* -* Pthread Mutex Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_MUTEX_PTHREAD_H__ -#define BOTAN_MUTEX_PTHREAD_H__ - -#include - -namespace Botan { - -/************************************************* -* Pthread Mutex Factory * -*************************************************/ -class 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 421b771c7..000000000 --- a/src/mutex/qt_mutex/mux_qt.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/************************************************* -* Qt Thread Mutex Source File * -* (C) 2004-2007 Justin Karneges * -* 2004-2007 Jack Lloyd * -*************************************************/ - -#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 fffdc78ae..000000000 --- a/src/mutex/qt_mutex/mux_qt.h +++ /dev/null @@ -1,25 +0,0 @@ -/************************************************* -* Qt Mutex Header File * -* (C) 2004-2007 Justin Karneges * -* 2004-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_MUTEX_QT_H__ -#define BOTAN_MUTEX_QT_H__ - -#include - -namespace Botan { - -/************************************************* -* Qt Mutex * -*************************************************/ -class 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 d235ff73c..000000000 --- a/src/mutex/win32_crit_section/info.txt +++ /dev/null @@ -1,16 +0,0 @@ -realname "Win32 Mutex" - -define MUTEX_WIN32 -modset win32 - -load_on auto - - -mux_win32.cpp -mux_win32.h - - - -cygwin -windows - 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 622a707fa..000000000 --- a/src/mutex/win32_crit_section/mux_win32.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/************************************************* -* Win32 Mutex Source File * -* (C) 2006 Luca Piccarreta * -* 2006-2007 Jack Lloyd * -*************************************************/ - -#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 20b245967..000000000 --- a/src/mutex/win32_crit_section/mux_win32.h +++ /dev/null @@ -1,24 +0,0 @@ -/************************************************* -* Win32 Mutex Header File * -* (C) 2006 Luca Piccarreta * -* 2006-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_MUTEX_WIN32_H__ -#define BOTAN_MUTEX_WIN32_H__ - -#include - -namespace Botan { - -/************************************************* -* Win32 Mutex Factory * -*************************************************/ -class Win32_Mutex_Factory : public Mutex_Factory - { - public: - Mutex* make(); - }; -} - -#endif diff --git a/src/selftest/info.txt b/src/selftest/info.txt deleted file mode 100644 index e786437d5..000000000 --- a/src/selftest/info.txt +++ /dev/null @@ -1,24 +0,0 @@ -realname "Selftests" - -define SELFTESTS - -load_on auto - - -selftest.cpp -selftest.h - - - -hex -des -aes -sha1 -sha2 -hmac -ecb -cbc -cfb -ofb -ctr - diff --git a/src/selftest/selftest.cpp b/src/selftest/selftest.cpp deleted file mode 100644 index 0dede1c9d..000000000 --- a/src/selftest/selftest.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/************************************************* -* Startup Self Tests Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include -#include - -namespace Botan { - -namespace { - -/************************************************* -* Perform a Known Answer Test * -*************************************************/ -void do_kat(const std::string& in, const std::string& out, - const std::string& algo_name, Filter* filter) - { - if(out.length()) - { - Pipe pipe(new Hex_Decoder, filter, new Hex_Encoder); - pipe.process_msg(in); - - if(out != pipe.read_all_as_string()) - throw Self_Test_Failure("FIPS-140 " + algo_name + " test"); - } - } - -/************************************************* -* Perform a KAT for a cipher * -*************************************************/ -void cipher_kat(const std::string& in, const std::string& out, - const std::string& key, const std::string& iv, - const std::string& cipher) - { - do_kat(in, out, cipher, - get_cipher(global_state(), cipher, key, iv, ENCRYPTION)); - do_kat(out, in, cipher, - get_cipher(global_state(), cipher, key, iv, DECRYPTION)); - } - -/************************************************* -* Perform a KAT for a cipher * -*************************************************/ -void cipher_kat(const std::string& cipher, const std::string& key, - const std::string& iv, const std::string& in, - const std::string& ecb_out, const std::string& cbc_out, - const std::string& cfb_out, const std::string& ofb_out, - const std::string& ctr_out) - { - if(!have_block_cipher(cipher)) - return; - - cipher_kat(in, ecb_out, key, "", cipher + "/ECB"); - cipher_kat(in, cbc_out, key, iv, cipher + "/CBC/NoPadding"); - cipher_kat(in, cfb_out, key, iv, cipher + "/CFB"); - cipher_kat(in, ofb_out, key, iv, cipher + "/OFB"); - cipher_kat(in, ctr_out, key, iv, cipher + "/CTR-BE"); - } - -/************************************************* -* Perform a KAT for a hash * -*************************************************/ -void hash_kat(const std::string& hash, const std::string& in, - const std::string& out) - { - if(!have_hash(hash)) - return; - do_kat(in, out, hash, new Hash_Filter(hash)); - } - -/************************************************* -* Perform a KAT for a MAC * -*************************************************/ -void mac_kat(const std::string& mac, const std::string& in, - const std::string& out, const std::string& key) - { - if(!have_mac(mac)) - return; - do_kat(in, out, mac, new MAC_Filter(mac, key)); - } - -} - -/************************************************* -* Perform FIPS 140 Self Tests * -*************************************************/ -bool passes_self_tests() - { - try { - cipher_kat("DES", "0123456789ABCDEF", "1234567890ABCDEF", - "4E6F77206973207468652074696D6520666F7220616C6C20", - "3FA40E8A984D48156A271787AB8883F9893D51EC4B563B53", - "E5C7CDDE872BF27C43E934008C389C0F683788499A7C05F6", - "F3096249C7F46E51A69E839B1A92F78403467133898EA622", - "F3096249C7F46E5135F24A242EEB3D3F3D6D5BE3255AF8C3", - "F3096249C7F46E51163A8CA0FFC94C27FA2F80F480B86F75"); - - cipher_kat("TripleDES", - "385D7189A5C3D485E1370AA5D408082B5CCCCB5E19F2D90E", - "C141B5FCCD28DC8A", - "6E1BD7C6120947A464A6AAB293A0F89A563D8D40D3461B68", - "64EAAD4ACBB9CEAD6C7615E7C7E4792FE587D91F20C7D2F4", - "6235A461AFD312973E3B4F7AA7D23E34E03371F8E8C376C9", - "E26BA806A59B0330DE40CA38E77A3E494BE2B212F6DD624B", - "E26BA806A59B03307DE2BCC25A08BA40A8BA335F5D604C62", - "E26BA806A59B03303C62C2EFF32D3ACDD5D5F35EBCC53371"); - - cipher_kat("AES", - "2B7E151628AED2A6ABF7158809CF4F3C", - "000102030405060708090A0B0C0D0E0F", - "6BC1BEE22E409F96E93D7E117393172A" - "AE2D8A571E03AC9C9EB76FAC45AF8E51", - "3AD77BB40D7A3660A89ECAF32466EF97" - "F5D3D58503B9699DE785895A96FDBAAF", - "7649ABAC8119B246CEE98E9B12E9197D" - "5086CB9B507219EE95DB113A917678B2", - "3B3FD92EB72DAD20333449F8E83CFB4A" - "C8A64537A0B3A93FCDE3CDAD9F1CE58B", - "3B3FD92EB72DAD20333449F8E83CFB4A" - "7789508D16918F03F53C52DAC54ED825", - "3B3FD92EB72DAD20333449F8E83CFB4A" - "010C041999E03F36448624483E582D0E"); - - hash_kat("SHA-1", "", "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709"); - hash_kat("SHA-1", "616263", "A9993E364706816ABA3E25717850C26C9CD0D89D"); - hash_kat("SHA-1", - "6162636462636465636465666465666765666768666768696768696A" - "68696A6B696A6B6C6A6B6C6D6B6C6D6E6C6D6E6F6D6E6F706E6F7071", - "84983E441C3BD26EBAAE4AA1F95129E5E54670F1"); - - hash_kat("SHA-256", "", - "E3B0C44298FC1C149AFBF4C8996FB924" - "27AE41E4649B934CA495991B7852B855"); - hash_kat("SHA-256", "616263", - "BA7816BF8F01CFEA414140DE5DAE2223" - "B00361A396177A9CB410FF61F20015AD"); - hash_kat("SHA-256", - "6162636462636465636465666465666765666768666768696768696A" - "68696A6B696A6B6C6A6B6C6D6B6C6D6E6C6D6E6F6D6E6F706E6F7071", - "248D6A61D20638B8E5C026930C3E6039" - "A33CE45964FF2167F6ECEDD419DB06C1"); - - mac_kat("HMAC(SHA-1)", "4869205468657265", - "B617318655057264E28BC0B6FB378C8EF146BE00", - "0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B"); - - mac_kat("HMAC(SHA-256)", "4869205468657265", - "198A607EB44BFBC69903A0F1CF2BBDC5" - "BA0AA3F3D9AE3C1C7A3B1696A0B68CF7", - "0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B" - "0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B"); - } - catch(std::exception& e) - { - return false; - } - - return true; - } - -} diff --git a/src/selftest/selftest.h b/src/selftest/selftest.h deleted file mode 100644 index ff011a32c..000000000 --- a/src/selftest/selftest.h +++ /dev/null @@ -1,20 +0,0 @@ -/************************************************* -* Startup Self Test Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_SELF_TEST_H__ -#define BOTAN_SELF_TEST_H__ - -#include - -namespace Botan { - -/************************************************* -* Self Tests * -*************************************************/ -BOTAN_DLL bool passes_self_tests(); - -} - -#endif diff --git a/src/timer/cpu_counter/info.txt b/src/timer/cpu_counter/info.txt deleted file mode 100644 index eef6be5a2..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_base - diff --git a/src/timer/cpu_counter/tm_hard.cpp b/src/timer/cpu_counter/tm_hard.cpp deleted file mode 100644 index 2f7516930..000000000 --- a/src/timer/cpu_counter/tm_hard.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/************************************************* -* Hardware Timer Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#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 678513f81..000000000 --- a/src/timer/cpu_counter/tm_hard.h +++ /dev/null @@ -1,24 +0,0 @@ -/************************************************* -* Hardware Timer Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_TIMER_HARDWARE_H__ -#define BOTAN_TIMER_HARDWARE_H__ - -#include - -namespace Botan { - -/************************************************* -* Hardware Timer * -*************************************************/ -class Hardware_Timer : public Timer - { - public: - u64bit clock() const; - }; - -} - -#endif diff --git a/src/timer/gettimeofday/info.txt b/src/timer/gettimeofday/info.txt deleted file mode 100644 index c079dfd58..000000000 --- a/src/timer/gettimeofday/info.txt +++ /dev/null @@ -1,32 +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 -hpux -irix -linux -netbsd -openbsd -qnx -solaris -tru64 - - - -timer_base - - diff --git a/src/timer/gettimeofday/tm_unix.cpp b/src/timer/gettimeofday/tm_unix.cpp deleted file mode 100644 index 654297753..000000000 --- a/src/timer/gettimeofday/tm_unix.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/************************************************* -* Unix Timer Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#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 fd24a1563..000000000 --- a/src/timer/gettimeofday/tm_unix.h +++ /dev/null @@ -1,24 +0,0 @@ -/************************************************* -* Unix Timer Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_TIMER_UNIX_H__ -#define BOTAN_TIMER_UNIX_H__ - -#include - -namespace Botan { - -/************************************************* -* Unix Timer * -*************************************************/ -class Unix_Timer : public Timer - { - public: - u64bit clock() const; - }; - -} - -#endif diff --git a/src/timer/posix_rt/info.txt b/src/timer/posix_rt/info.txt deleted file mode 100644 index fb1870988..000000000 --- a/src/timer/posix_rt/info.txt +++ /dev/null @@ -1,28 +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 -#netbsd -#openbsd - - - -timer_base - - diff --git a/src/timer/posix_rt/tm_posix.cpp b/src/timer/posix_rt/tm_posix.cpp deleted file mode 100644 index 601b2b43d..000000000 --- a/src/timer/posix_rt/tm_posix.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/************************************************* -* POSIX Timer Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#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 fc3ccdc74..000000000 --- a/src/timer/posix_rt/tm_posix.h +++ /dev/null @@ -1,24 +0,0 @@ -/************************************************* -* POSIX Timer Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_TIMER_POSIX_H__ -#define BOTAN_TIMER_POSIX_H__ - -#include - -namespace Botan { - -/************************************************* -* POSIX Timer * -*************************************************/ -class POSIX_Timer : public Timer - { - public: - u64bit clock() const; - }; - -} - -#endif diff --git a/src/timer/timer_base/info.txt b/src/timer/timer_base/info.txt deleted file mode 100644 index 3637d4c94..000000000 --- a/src/timer/timer_base/info.txt +++ /dev/null @@ -1,10 +0,0 @@ -realname "Timer Base Class" - -define TIMER - -load_on auto - - -timers.cpp -timers.h - diff --git a/src/timer/timer_base/timers.cpp b/src/timer/timer_base/timers.cpp deleted file mode 100644 index 4f482916f..000000000 --- a/src/timer/timer_base/timers.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/************************************************* -* Timestamp Functions Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include -#include -#include - -namespace Botan { - -/************************************************* -* Get the system clock * -*************************************************/ -u64bit system_time() - { - return static_cast(std::time(0)); - } - -/************************************************* -* Default Timer clock reading * -*************************************************/ -u64bit Timer::clock() const - { - return combine_timers(std::time(0), std::clock(), CLOCKS_PER_SEC); - } - -/************************************************* -* Read the clock and return the output * -*************************************************/ -u32bit Timer::slow_poll(byte out[], u32bit length) - { - const u64bit clock_value = this->clock(); - - for(u32bit j = 0; j != sizeof(clock_value); ++j) - out[j % length] ^= get_byte(j, clock_value); - - return (length < 8) ? length : 8; - } - -/************************************************* -* Combine a two time values into a single one * -*************************************************/ -u64bit Timer::combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz) - { - static const u64bit NANOSECONDS_UNITS = 1000000000; - parts *= (NANOSECONDS_UNITS / parts_hz); - return ((seconds * NANOSECONDS_UNITS) + parts); - } - -} diff --git a/src/timer/timer_base/timers.h b/src/timer/timer_base/timers.h deleted file mode 100644 index 253f71f6b..000000000 --- a/src/timer/timer_base/timers.h +++ /dev/null @@ -1,29 +0,0 @@ -/************************************************* -* Timestamp Functions Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_TIMERS_H__ -#define BOTAN_TIMERS_H__ - -#include - -namespace Botan { - -/************************************************* -* Timer Interface * -*************************************************/ -class BOTAN_DLL Timer : public EntropySource - { - public: - virtual u64bit clock() const; - u32bit slow_poll(byte[], u32bit); - - virtual ~Timer() {} - protected: - static u64bit combine_timers(u32bit, u32bit, u32bit); - }; - -} - -#endif diff --git a/src/timer/win32_query_perf_ctr/info.txt b/src/timer/win32_query_perf_ctr/info.txt deleted file mode 100644 index e956f99c5..000000000 --- a/src/timer/win32_query_perf_ctr/info.txt +++ /dev/null @@ -1,25 +0,0 @@ -realname "Win32 Timer" - -define TIMER_WIN32 -modset win32 - -load_on auto - - -tm_win32.cpp -tm_win32.h - - - -cygwin -windows - - - -windows -> user32 - - - -timer_base - - 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 58f7b0f55..000000000 --- a/src/timer/win32_query_perf_ctr/tm_win32.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/************************************************* -* Win32 Timer Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#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 67b045e78..000000000 --- a/src/timer/win32_query_perf_ctr/tm_win32.h +++ /dev/null @@ -1,24 +0,0 @@ -/************************************************* -* Win32 Timer Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_TIMER_WIN32_H__ -#define BOTAN_TIMER_WIN32_H__ - -#include - -namespace Botan { - -/************************************************* -* Win32 Timer * -*************************************************/ -class Win32_Timer : public Timer - { - public: - u64bit clock() const; - }; - -} - -#endif diff --git a/src/utils/mutex/noop_mutex/info.txt b/src/utils/mutex/noop_mutex/info.txt new file mode 100644 index 000000000..1f49f5e1c --- /dev/null +++ b/src/utils/mutex/noop_mutex/info.txt @@ -0,0 +1,10 @@ +realname "No-Op Mutex" + +load_on auto + +define MUTEX_NOOP + + +mux_noop.cpp +mux_noop.h + diff --git a/src/utils/mutex/noop_mutex/mux_noop.cpp b/src/utils/mutex/noop_mutex/mux_noop.cpp new file mode 100644 index 000000000..eb3a12702 --- /dev/null +++ b/src/utils/mutex/noop_mutex/mux_noop.cpp @@ -0,0 +1,48 @@ +/************************************************* +* No-Op Mutex Factory Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include + +namespace Botan { + +/************************************************* +* No-Op Mutex Factory * +*************************************************/ +Mutex* Noop_Mutex_Factory::make() + { + class Noop_Mutex : public Mutex + { + public: + class Mutex_State_Error : public Internal_Error + { + public: + Mutex_State_Error(const std::string& where) : + Internal_Error("Noop_Mutex::" + where + ": " + + "Mutex is already " + where + "ed") {} + }; + + void lock() + { + if(locked) + throw Mutex_State_Error("lock"); + locked = true; + } + + void unlock() + { + if(!locked) + throw Mutex_State_Error("unlock"); + locked = false; + } + + Noop_Mutex() { locked = false; } + private: + bool locked; + }; + + return new Noop_Mutex; + } + +} diff --git a/src/utils/mutex/noop_mutex/mux_noop.h b/src/utils/mutex/noop_mutex/mux_noop.h new file mode 100644 index 000000000..a5b802cc0 --- /dev/null +++ b/src/utils/mutex/noop_mutex/mux_noop.h @@ -0,0 +1,24 @@ +/************************************************* +* No-Op Mutex Factory Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_NOOP_MUTEX_FACTORY_H__ +#define BOTAN_NOOP_MUTEX_FACTORY_H__ + +#include + +namespace Botan { + +/************************************************* +* No-Op Mutex Factory * +*************************************************/ +class BOTAN_DLL Noop_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; + +} + +#endif diff --git a/src/utils/mutex/pthreads/info.txt b/src/utils/mutex/pthreads/info.txt new file mode 100644 index 000000000..88de70de0 --- /dev/null +++ b/src/utils/mutex/pthreads/info.txt @@ -0,0 +1,29 @@ +realname "Pthread Mutex" + +define MUTEX_PTHREAD + +load_on auto + + +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/utils/mutex/pthreads/mux_pthr.cpp b/src/utils/mutex/pthreads/mux_pthr.cpp new file mode 100644 index 000000000..d003fa298 --- /dev/null +++ b/src/utils/mutex/pthreads/mux_pthr.cpp @@ -0,0 +1,56 @@ +/************************************************* +* Pthread Mutex Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#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/utils/mutex/pthreads/mux_pthr.h b/src/utils/mutex/pthreads/mux_pthr.h new file mode 100644 index 000000000..efdabfed4 --- /dev/null +++ b/src/utils/mutex/pthreads/mux_pthr.h @@ -0,0 +1,24 @@ +/************************************************* +* Pthread Mutex Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_MUTEX_PTHREAD_H__ +#define BOTAN_MUTEX_PTHREAD_H__ + +#include + +namespace Botan { + +/************************************************* +* Pthread Mutex Factory * +*************************************************/ +class Pthread_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; + +} + +#endif diff --git a/src/utils/mutex/qt_mutex/info.txt b/src/utils/mutex/qt_mutex/info.txt new file mode 100644 index 000000000..a21108c79 --- /dev/null +++ b/src/utils/mutex/qt_mutex/info.txt @@ -0,0 +1,18 @@ +realname "Qt Mutex" + +define MUTEX_QT + +note "You'll probably have to add -I/-L flags to the Makefile to find Qt" + +load_on request + + +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/utils/mutex/qt_mutex/mux_qt.cpp b/src/utils/mutex/qt_mutex/mux_qt.cpp new file mode 100644 index 000000000..421b771c7 --- /dev/null +++ b/src/utils/mutex/qt_mutex/mux_qt.cpp @@ -0,0 +1,33 @@ +/************************************************* +* Qt Thread Mutex Source File * +* (C) 2004-2007 Justin Karneges * +* 2004-2007 Jack Lloyd * +*************************************************/ + +#include +#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/utils/mutex/qt_mutex/mux_qt.h b/src/utils/mutex/qt_mutex/mux_qt.h new file mode 100644 index 000000000..fffdc78ae --- /dev/null +++ b/src/utils/mutex/qt_mutex/mux_qt.h @@ -0,0 +1,25 @@ +/************************************************* +* Qt Mutex Header File * +* (C) 2004-2007 Justin Karneges * +* 2004-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_MUTEX_QT_H__ +#define BOTAN_MUTEX_QT_H__ + +#include + +namespace Botan { + +/************************************************* +* Qt Mutex * +*************************************************/ +class Qt_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; + +} + +#endif diff --git a/src/utils/mutex/win32_crit_section/info.txt b/src/utils/mutex/win32_crit_section/info.txt new file mode 100644 index 000000000..d235ff73c --- /dev/null +++ b/src/utils/mutex/win32_crit_section/info.txt @@ -0,0 +1,16 @@ +realname "Win32 Mutex" + +define MUTEX_WIN32 +modset win32 + +load_on auto + + +mux_win32.cpp +mux_win32.h + + + +cygwin +windows + diff --git a/src/utils/mutex/win32_crit_section/mux_win32.cpp b/src/utils/mutex/win32_crit_section/mux_win32.cpp new file mode 100644 index 000000000..622a707fa --- /dev/null +++ b/src/utils/mutex/win32_crit_section/mux_win32.cpp @@ -0,0 +1,32 @@ +/************************************************* +* Win32 Mutex Source File * +* (C) 2006 Luca Piccarreta * +* 2006-2007 Jack Lloyd * +*************************************************/ + +#include +#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/utils/mutex/win32_crit_section/mux_win32.h b/src/utils/mutex/win32_crit_section/mux_win32.h new file mode 100644 index 000000000..20b245967 --- /dev/null +++ b/src/utils/mutex/win32_crit_section/mux_win32.h @@ -0,0 +1,24 @@ +/************************************************* +* Win32 Mutex Header File * +* (C) 2006 Luca Piccarreta * +* 2006-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_MUTEX_WIN32_H__ +#define BOTAN_MUTEX_WIN32_H__ + +#include + +namespace Botan { + +/************************************************* +* Win32 Mutex Factory * +*************************************************/ +class Win32_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; +} + +#endif diff --git a/src/utils/timer/cpu_counter/info.txt b/src/utils/timer/cpu_counter/info.txt new file mode 100644 index 000000000..eef6be5a2 --- /dev/null +++ b/src/utils/timer/cpu_counter/info.txt @@ -0,0 +1,36 @@ +realname "Hardware Timer" + +define TIMER_HARDWARE + +load_on asm_ok + + +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_base + diff --git a/src/utils/timer/cpu_counter/tm_hard.cpp b/src/utils/timer/cpu_counter/tm_hard.cpp new file mode 100644 index 000000000..2f7516930 --- /dev/null +++ b/src/utils/timer/cpu_counter/tm_hard.cpp @@ -0,0 +1,49 @@ +/************************************************* +* Hardware Timer Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include + +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/utils/timer/cpu_counter/tm_hard.h b/src/utils/timer/cpu_counter/tm_hard.h new file mode 100644 index 000000000..678513f81 --- /dev/null +++ b/src/utils/timer/cpu_counter/tm_hard.h @@ -0,0 +1,24 @@ +/************************************************* +* Hardware Timer Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_TIMER_HARDWARE_H__ +#define BOTAN_TIMER_HARDWARE_H__ + +#include + +namespace Botan { + +/************************************************* +* Hardware Timer * +*************************************************/ +class Hardware_Timer : public Timer + { + public: + u64bit clock() const; + }; + +} + +#endif diff --git a/src/utils/timer/gettimeofday/info.txt b/src/utils/timer/gettimeofday/info.txt new file mode 100644 index 000000000..c079dfd58 --- /dev/null +++ b/src/utils/timer/gettimeofday/info.txt @@ -0,0 +1,32 @@ +realname "Unix Timer" + +define TIMER_UNIX + +load_on auto +modset unix,beos + + +tm_unix.cpp +tm_unix.h + + + +aix +beos +cygwin +darwin +freebsd +hpux +irix +linux +netbsd +openbsd +qnx +solaris +tru64 + + + +timer_base + + diff --git a/src/utils/timer/gettimeofday/tm_unix.cpp b/src/utils/timer/gettimeofday/tm_unix.cpp new file mode 100644 index 000000000..654297753 --- /dev/null +++ b/src/utils/timer/gettimeofday/tm_unix.cpp @@ -0,0 +1,22 @@ +/************************************************* +* Unix Timer Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#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/utils/timer/gettimeofday/tm_unix.h b/src/utils/timer/gettimeofday/tm_unix.h new file mode 100644 index 000000000..fd24a1563 --- /dev/null +++ b/src/utils/timer/gettimeofday/tm_unix.h @@ -0,0 +1,24 @@ +/************************************************* +* Unix Timer Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_TIMER_UNIX_H__ +#define BOTAN_TIMER_UNIX_H__ + +#include + +namespace Botan { + +/************************************************* +* Unix Timer * +*************************************************/ +class Unix_Timer : public Timer + { + public: + u64bit clock() const; + }; + +} + +#endif diff --git a/src/utils/timer/posix_rt/info.txt b/src/utils/timer/posix_rt/info.txt new file mode 100644 index 000000000..fb1870988 --- /dev/null +++ b/src/utils/timer/posix_rt/info.txt @@ -0,0 +1,28 @@ +realname "POSIX Timer" + +define TIMER_POSIX + +load_on auto + + +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 +#netbsd +#openbsd + + + +timer_base + + diff --git a/src/utils/timer/posix_rt/tm_posix.cpp b/src/utils/timer/posix_rt/tm_posix.cpp new file mode 100644 index 000000000..601b2b43d --- /dev/null +++ b/src/utils/timer/posix_rt/tm_posix.cpp @@ -0,0 +1,31 @@ +/************************************************* +* POSIX Timer Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#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/utils/timer/posix_rt/tm_posix.h b/src/utils/timer/posix_rt/tm_posix.h new file mode 100644 index 000000000..fc3ccdc74 --- /dev/null +++ b/src/utils/timer/posix_rt/tm_posix.h @@ -0,0 +1,24 @@ +/************************************************* +* POSIX Timer Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_TIMER_POSIX_H__ +#define BOTAN_TIMER_POSIX_H__ + +#include + +namespace Botan { + +/************************************************* +* POSIX Timer * +*************************************************/ +class POSIX_Timer : public Timer + { + public: + u64bit clock() const; + }; + +} + +#endif diff --git a/src/utils/timer/timer_base/info.txt b/src/utils/timer/timer_base/info.txt new file mode 100644 index 000000000..3637d4c94 --- /dev/null +++ b/src/utils/timer/timer_base/info.txt @@ -0,0 +1,10 @@ +realname "Timer Base Class" + +define TIMER + +load_on auto + + +timers.cpp +timers.h + diff --git a/src/utils/timer/timer_base/timers.cpp b/src/utils/timer/timer_base/timers.cpp new file mode 100644 index 000000000..4f482916f --- /dev/null +++ b/src/utils/timer/timer_base/timers.cpp @@ -0,0 +1,52 @@ +/************************************************* +* Timestamp Functions Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include +#include +#include + +namespace Botan { + +/************************************************* +* Get the system clock * +*************************************************/ +u64bit system_time() + { + return static_cast(std::time(0)); + } + +/************************************************* +* Default Timer clock reading * +*************************************************/ +u64bit Timer::clock() const + { + return combine_timers(std::time(0), std::clock(), CLOCKS_PER_SEC); + } + +/************************************************* +* Read the clock and return the output * +*************************************************/ +u32bit Timer::slow_poll(byte out[], u32bit length) + { + const u64bit clock_value = this->clock(); + + for(u32bit j = 0; j != sizeof(clock_value); ++j) + out[j % length] ^= get_byte(j, clock_value); + + return (length < 8) ? length : 8; + } + +/************************************************* +* Combine a two time values into a single one * +*************************************************/ +u64bit Timer::combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz) + { + static const u64bit NANOSECONDS_UNITS = 1000000000; + parts *= (NANOSECONDS_UNITS / parts_hz); + return ((seconds * NANOSECONDS_UNITS) + parts); + } + +} diff --git a/src/utils/timer/timer_base/timers.h b/src/utils/timer/timer_base/timers.h new file mode 100644 index 000000000..253f71f6b --- /dev/null +++ b/src/utils/timer/timer_base/timers.h @@ -0,0 +1,29 @@ +/************************************************* +* Timestamp Functions Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_TIMERS_H__ +#define BOTAN_TIMERS_H__ + +#include + +namespace Botan { + +/************************************************* +* Timer Interface * +*************************************************/ +class BOTAN_DLL Timer : public EntropySource + { + public: + virtual u64bit clock() const; + u32bit slow_poll(byte[], u32bit); + + virtual ~Timer() {} + protected: + static u64bit combine_timers(u32bit, u32bit, u32bit); + }; + +} + +#endif diff --git a/src/utils/timer/win32_query_perf_ctr/info.txt b/src/utils/timer/win32_query_perf_ctr/info.txt new file mode 100644 index 000000000..e956f99c5 --- /dev/null +++ b/src/utils/timer/win32_query_perf_ctr/info.txt @@ -0,0 +1,25 @@ +realname "Win32 Timer" + +define TIMER_WIN32 +modset win32 + +load_on auto + + +tm_win32.cpp +tm_win32.h + + + +cygwin +windows + + + +windows -> user32 + + + +timer_base + + diff --git a/src/utils/timer/win32_query_perf_ctr/tm_win32.cpp b/src/utils/timer/win32_query_perf_ctr/tm_win32.cpp new file mode 100644 index 000000000..58f7b0f55 --- /dev/null +++ b/src/utils/timer/win32_query_perf_ctr/tm_win32.cpp @@ -0,0 +1,21 @@ +/************************************************* +* Win32 Timer Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include + +namespace Botan { + +/************************************************* +* Get the timestamp * +*************************************************/ +u64bit Win32_Timer::clock() const + { + LARGE_INTEGER tv; + ::QueryPerformanceCounter(&tv); + return tv.QuadPart; + } + +} diff --git a/src/utils/timer/win32_query_perf_ctr/tm_win32.h b/src/utils/timer/win32_query_perf_ctr/tm_win32.h new file mode 100644 index 000000000..67b045e78 --- /dev/null +++ b/src/utils/timer/win32_query_perf_ctr/tm_win32.h @@ -0,0 +1,24 @@ +/************************************************* +* Win32 Timer Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_TIMER_WIN32_H__ +#define BOTAN_TIMER_WIN32_H__ + +#include + +namespace Botan { + +/************************************************* +* Win32 Timer * +*************************************************/ +class Win32_Timer : public Timer + { + public: + u64bit clock() const; + }; + +} + +#endif -- cgit v1.2.3