# # # rename "botan/init.cpp" # to "botan/init_def.cpp" # # add_file "botan/eng_def.h" # content [22f1fd366a3b8480b4101127aaca73ead0efda57] # # patch "botan/def_alg.cpp" # from [4159950766418fa2c83cde48483ab8e895ec95c6] # to [b3f2228ad990d77ed9f3c44715153b2993cb5cf5] # # patch "botan/init_def.cpp" # from [9ea095587401c32f31aadec310130f6865711409] # to [c920737920ee420d5112e0f370444c0ef3b8700f] # # patch "botan/mem_pool.cpp" # from [05fc27f4a05b71ab53b2f5f5fd0fb9bbe57f9909] # to [3a792af63a26df94d6fa8696215d6b6b014f655e] # # patch "botan/pk_algs.cpp" # from [004d3768624059675382b2c999587af76e10c943] # to [4eaf5dca76443211e7486ca651ae5521d7cb7181] # ============================================================ --- botan/eng_def.h 22f1fd366a3b8480b4101127aaca73ead0efda57 +++ botan/eng_def.h 22f1fd366a3b8480b4101127aaca73ead0efda57 @@ -0,0 +1,46 @@ +/************************************************* +* Default Engine Header File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#ifndef BOTAN_DEFAULT_ENGINE_H__ +#define BOTAN_DEFAULT_ENGINE_H__ + +#include + +namespace Botan { + +/************************************************* +* Default Engine * +*************************************************/ +class Default_Engine : public Engine + { + public: + IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&) const; + DSA_Operation* dsa_op(const DL_Group&, const BigInt&, + const BigInt&) const; + NR_Operation* nr_op(const DL_Group&, const BigInt&, const BigInt&) const; + ELG_Operation* elg_op(const DL_Group&, const BigInt&, + const BigInt&) const; + DH_Operation* dh_op(const DL_Group&, const BigInt&) const; + + Modular_Exponentiator* mod_exp(const BigInt&, + Power_Mod::Usage_Hints) const; + + Keyed_Filter* get_cipher(const std::string&, Cipher_Dir); + private: + BlockCipher* find_block_cipher(const std::string&) const; + StreamCipher* find_stream_cipher(const std::string&) const; + HashFunction* find_hash(const std::string&) const; + MessageAuthenticationCode* find_mac(const std::string&) const; + + class S2K* find_s2k(const std::string&) const; + class BlockCipherModePaddingMethod* + find_bc_pad(const std::string&) const; + }; + +} + +#endif ============================================================ --- botan/def_alg.cpp 4159950766418fa2c83cde48483ab8e895ec95c6 +++ botan/def_alg.cpp b3f2228ad990d77ed9f3c44715153b2993cb5cf5 @@ -1,63 +1,24 @@ /************************************************* * Default Engine Algorithms Source File * * (C) 1999-2006 The Botan Project * *************************************************/ -#include +#include #include #include #include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include #include #include -#include -#include -#include -#include -#include #include -#include #include -#include #include namespace Botan { @@ -118,36 +79,10 @@ HANDLE_TYPE_NO_ARGS("AES-128", AES_128); HANDLE_TYPE_NO_ARGS("AES-192", AES_192); HANDLE_TYPE_NO_ARGS("AES-256", AES_256); - HANDLE_TYPE_NO_ARGS("Blowfish", Blowfish); - HANDLE_TYPE_NO_ARGS("CAST-128", CAST_128); - HANDLE_TYPE_NO_ARGS("CAST-256", CAST_256); HANDLE_TYPE_NO_ARGS("DES", DES); HANDLE_TYPE_NO_ARGS("DESX", DESX); HANDLE_TYPE_NO_ARGS("TripleDES", TripleDES); - HANDLE_TYPE_NO_ARGS("GOST", GOST); - HANDLE_TYPE_NO_ARGS("IDEA", IDEA); - HANDLE_TYPE_NO_ARGS("KASUMI", KASUMI); - HANDLE_TYPE_ONE_STRING("Luby-Rackoff", LubyRackoff); - HANDLE_TYPE_NO_ARGS("MARS", MARS); - HANDLE_TYPE_ONE_U32BIT("MISTY1", MISTY1, 8); - HANDLE_TYPE_NO_ARGS("RC2", RC2); - HANDLE_TYPE_ONE_U32BIT("RC5", RC5, 12); - HANDLE_TYPE_NO_ARGS("RC6", RC6); - HANDLE_TYPE_ONE_U32BIT("SAFER-SK", SAFER_SK, 10); - HANDLE_TYPE_NO_ARGS("SEED", SEED); - HANDLE_TYPE_NO_ARGS("Serpent", Serpent); - HANDLE_TYPE_NO_ARGS("Skipjack", Skipjack); - HANDLE_TYPE_NO_ARGS("Square", Square); - HANDLE_TYPE_NO_ARGS("TEA", TEA); - HANDLE_TYPE_NO_ARGS("Twofish", Twofish); - HANDLE_TYPE_NO_ARGS("XTEA", XTEA); - 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])); - } return 0; } @@ -164,8 +99,6 @@ HANDLE_TYPE_ONE_U32BIT("ARC4", ARC4, 0); HANDLE_TYPE_ONE_U32BIT("RC4_drop", ARC4, 768); - HANDLE_TYPE_NO_ARGS("Turing", Turing); - HANDLE_TYPE_NO_ARGS("WiderWake4+1-BE", WiderWake_41_BE); return 0; } @@ -181,30 +114,9 @@ return 0; const std::string algo_name = deref_alias(name[0]); - HANDLE_TYPE_NO_ARGS("Adler32", Adler32); - HANDLE_TYPE_NO_ARGS("CRC24", CRC24); HANDLE_TYPE_NO_ARGS("CRC32", CRC32); - HANDLE_TYPE_NO_ARGS("FORK-256", FORK_256); - HANDLE_TYPE_NO_ARGS("HAS-160", HAS_160); - HANDLE_TYPE_NO_ARGS("MD2", MD2); - HANDLE_TYPE_NO_ARGS("MD4", MD4); - HANDLE_TYPE_NO_ARGS("MD5", MD5); - HANDLE_TYPE_NO_ARGS("RIPEMD-128", RIPEMD_128); - HANDLE_TYPE_NO_ARGS("RIPEMD-160", RIPEMD_160); HANDLE_TYPE_NO_ARGS("SHA-160", SHA_160); HANDLE_TYPE_NO_ARGS("SHA-256", SHA_256); - HANDLE_TYPE_NO_ARGS("SHA-384", SHA_384); - HANDLE_TYPE_NO_ARGS("SHA-512", SHA_512); - HANDLE_TYPE_TWO_U32BIT("Tiger", Tiger, 24); - HANDLE_TYPE_NO_ARGS("Whirlpool", Whirlpool); - - if(algo_name == "Parallel") - { - if(name.size() < 2) - throw Invalid_Algorithm_Name(algo_spec); - name.erase(name.begin()); - return new Parallel(name); - } return 0; } @@ -219,9 +131,7 @@ return 0; const std::string algo_name = deref_alias(name[0]); - HANDLE_TYPE_ONE_STRING("CMAC", CMAC); HANDLE_TYPE_ONE_STRING("HMAC", HMAC); - HANDLE_TYPE_NO_ARGS("X9.19-MAC", ANSI_X919_MAC); return 0; } @@ -239,7 +149,6 @@ HANDLE_TYPE_ONE_STRING("PBKDF1", PKCS5_PBKDF1); HANDLE_TYPE_ONE_STRING("PBKDF2", PKCS5_PBKDF2); - HANDLE_TYPE_ONE_STRING("OpenPGP-S2K", OpenPGP_S2K); return 0; } ============================================================ --- botan/init.cpp 9ea095587401c32f31aadec310130f6865711409 +++ botan/init_def.cpp c920737920ee420d5112e0f370444c0ef3b8700f @@ -1,5 +1,5 @@ /************************************************* -* Initialization Function Source File * +* Default Initialization Function Source File * * (C) 1999-2006 The Botan Project * *************************************************/ @@ -9,25 +9,13 @@ #include #include #include -#include +#include #include #include namespace Botan { /************************************************* -* Botan's global state * -*************************************************/ -Library_State* global_lib_state = 0; - -Library_State& global_state() - { - if(!global_lib_state) - throw Invalid_State("Library was not intialized correctly"); - return (*global_lib_state); - } - -/************************************************* * Library Initialization * *************************************************/ LibraryInitializer::LibraryInitializer(const std::string& arg_string) @@ -94,37 +82,35 @@ throw Exception("LibraryInitializer: thread safety impossible"); } - Library_State* state = new Library_State(mutex_factory, - Modules::get_timer()); + set_global_state(new Library_State(mutex_factory, + Modules::get_timer())); - global_lib_state = state; + global_state().add_allocator("malloc", new Malloc_Allocator); + global_state().add_allocator("locking", new Locking_Allocator); - state->add_allocator("malloc", new Malloc_Allocator); - state->add_allocator("locking", new Locking_Allocator); - if(arg_set(args, "secure_memory")) { std::map allocators = Modules::get_allocators(); for(std::map::iterator i = allocators.begin(); i != allocators.end(); ++i) - state->add_allocator(i->first, i->second); + global_state().add_allocator(i->first, i->second); } if(arg_set(args, "config") && args["config"] != "") - Config::load(args["config"], *state); + Config::load(args["config"], global_state()); if(arg_set(args, "use_engines")) { std::vector engines = Modules::get_engines(); for(u32bit j = 0; j != engines.size(); ++j) - state->add_engine(engines[j]); + global_state().add_engine(engines[j]); } - state->add_engine(new Default_Engine); + global_state().add_engine(new Default_Engine); - state->set_prng(new ANSI_X931_RNG); + global_state().set_prng(new ANSI_X931_RNG); std::vector sources = Modules::get_entropy_sources(); for(u32bit j = 0; j != sources.size(); ++j) - state->add_entropy_source(sources[j], true); + global_state().add_entropy_source(sources[j], true); const u32bit min_entropy = Config::get_u32bit("rng/min_entropy"); @@ -133,7 +119,8 @@ u32bit total_bits = 0; for(u32bit j = 0; j != 4; ++j) { - total_bits += state->seed_prng(true, min_entropy - total_bits); + total_bits += global_state().seed_prng(true, + min_entropy - total_bits); if(total_bits >= min_entropy) break; } @@ -144,8 +131,7 @@ if(!FIPS140::passes_self_tests()) { - delete global_lib_state; - global_lib_state = 0; + set_global_state(0); throw Self_Test_Failure("FIPS-140 startup tests"); } } @@ -155,8 +141,7 @@ *************************************************/ void deinitialize() { - delete global_lib_state; - global_lib_state = 0; + set_global_state(0); } } ============================================================ --- botan/mem_pool.cpp 05fc27f4a05b71ab53b2f5f5fd0fb9bbe57f9909 +++ botan/mem_pool.cpp 3a792af63a26df94d6fa8696215d6b6b014f655e @@ -246,10 +246,11 @@ assert(last_used != blocks.end()); - std::vector::iterator i = last_used + 1; + std::vector::iterator i = last_used; - while(i != last_used) + do { + i++; if(i == blocks.end()) i = blocks.begin(); @@ -260,8 +261,8 @@ return mem; } - ++i; } + while(i != last_used); return 0; } ============================================================ --- botan/pk_algs.cpp 004d3768624059675382b2c999587af76e10c943 +++ botan/pk_algs.cpp 4eaf5dca76443211e7486ca651ae5521d7cb7181 @@ -5,11 +5,6 @@ #include #include -#include -#include -#include -#include -#include namespace Botan { @@ -19,11 +14,6 @@ X509_PublicKey* get_public_key(const std::string& alg_name) { if(alg_name == "RSA") return new RSA_PublicKey; - else if(alg_name == "DSA") return new DSA_PublicKey; - else if(alg_name == "DH") return new DH_PublicKey; - else if(alg_name == "NR") return new NR_PublicKey; - else if(alg_name == "RW") return new RW_PublicKey; - else if(alg_name == "ELG") return new ElGamal_PublicKey; else return 0; } @@ -34,11 +24,6 @@ PKCS8_PrivateKey* get_private_key(const std::string& alg_name) { if(alg_name == "RSA") return new RSA_PrivateKey; - else if(alg_name == "DSA") return new DSA_PrivateKey; - else if(alg_name == "DH") return new DH_PrivateKey; - else if(alg_name == "NR") return new NR_PrivateKey; - else if(alg_name == "RW") return new RW_PrivateKey; - else if(alg_name == "ELG") return new ElGamal_PrivateKey; else return 0; }