diff options
author | lloyd <[email protected]> | 2008-09-30 04:35:34 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-30 04:35:34 +0000 |
commit | 3c55f159b8e2ff80c0f0ab0820de0afc414be7db (patch) | |
tree | 6370650255987e8df89b8ef90f46a5eec92b70ed /src/core/libstate | |
parent | eee6e1e1ec225c3301cef6839225317a8cc9cf4a (diff) |
Split off part of the core module into libstate (basically the whole
lookup/global_state piece).
Move timer and mutex directories into utils/
Diffstat (limited to 'src/core/libstate')
-rw-r--r-- | src/core/libstate/def_alg.cpp | 610 | ||||
-rw-r--r-- | src/core/libstate/def_mode.cpp | 177 | ||||
-rw-r--r-- | src/core/libstate/eng_base.cpp | 306 | ||||
-rw-r--r-- | src/core/libstate/engine.cpp | 382 | ||||
-rw-r--r-- | src/core/libstate/engine.h | 123 | ||||
-rw-r--r-- | src/core/libstate/get_enc.cpp | 219 | ||||
-rw-r--r-- | src/core/libstate/get_pbe.cpp | 87 | ||||
-rw-r--r-- | src/core/libstate/get_pbe.h | 22 | ||||
-rw-r--r-- | src/core/libstate/info.txt | 34 | ||||
-rw-r--r-- | src/core/libstate/init.h | 50 | ||||
-rw-r--r-- | src/core/libstate/init_def.cpp | 60 | ||||
-rw-r--r-- | src/core/libstate/init_opt.cpp | 102 | ||||
-rw-r--r-- | src/core/libstate/libstate.cpp | 294 | ||||
-rw-r--r-- | src/core/libstate/libstate.h | 90 | ||||
-rw-r--r-- | src/core/libstate/look_add.h | 28 | ||||
-rw-r--r-- | src/core/libstate/look_pk.cpp | 74 | ||||
-rw-r--r-- | src/core/libstate/look_pk.h | 38 | ||||
-rw-r--r-- | src/core/libstate/lookup.cpp | 239 | ||||
-rw-r--r-- | src/core/libstate/lookup.h | 98 | ||||
-rw-r--r-- | src/core/libstate/oids.cpp | 74 | ||||
-rw-r--r-- | src/core/libstate/oids.h | 36 | ||||
-rw-r--r-- | src/core/libstate/policy.cpp | 492 |
22 files changed, 3635 insertions, 0 deletions
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 <botan/eng_def.h> +#include <botan/libstate.h> +#include <botan/parsing.h> + +#if defined(BOTAN_HAS_AES) + #include <botan/aes.h> +#endif + +#if defined(BOTAN_HAS_BLOWFISH) + #include <botan/blowfish.h> +#endif + +#if defined(BOTAN_HAS_CAST) + #include <botan/cast128.h> + #include <botan/cast256.h> +#endif + +#if defined(BOTAN_HAS_DES) + #include <botan/des.h> +#endif + +#if defined(BOTAN_HAS_GOST) + #include <botan/gost.h> +#endif + +#if defined(BOTAN_HAS_IDEA) + #include <botan/idea.h> +#endif + +#if defined(BOTAN_HAS_KASUMI) + #include <botan/kasumi.h> +#endif + +#if defined(BOTAN_HAS_LION) + #include <botan/lion.h> +#endif + +#if defined(BOTAN_HAS_LUBY_RACKOFF) + #include <botan/lubyrack.h> +#endif + +#if defined(BOTAN_HAS_MARS) + #include <botan/mars.h> +#endif + +#if defined(BOTAN_HAS_MISTY1) + #include <botan/misty1.h> +#endif + +#if defined(BOTAN_HAS_NOEKEON) + #include <botan/noekeon.h> +#endif + +#if defined(BOTAN_HAS_RC2) + #include <botan/rc2.h> +#endif + +#if defined(BOTAN_HAS_RC5) + #include <botan/rc5.h> +#endif + +#if defined(BOTAN_HAS_RC6) + #include <botan/rc6.h> +#endif + +#if defined(BOTAN_HAS_SAFER) + #include <botan/safer_sk.h> +#endif + +#if defined(BOTAN_HAS_SEED) + #include <botan/seed.h> +#endif + +#if defined(BOTAN_HAS_SERPENT) + #include <botan/serpent.h> +#endif + +#if defined(BOTAN_HAS_SERPENT_IA32) + #include <botan/serp_ia32.h> +#endif + +#if defined(BOTAN_HAS_SKIPJACK) + #include <botan/skipjack.h> +#endif + +#if defined(BOTAN_HAS_SQUARE) + #include <botan/square.h> +#endif + +#if defined(BOTAN_HAS_TEA) + #include <botan/tea.h> +#endif + +#if defined(BOTAN_HAS_TWOFISH) + #include <botan/twofish.h> +#endif + +#if defined(BOTAN_HAS_XTEA) + #include <botan/xtea.h> +#endif + +#if defined(BOTAN_HAS_ARC4) + #include <botan/arc4.h> +#endif + +#if defined(BOTAN_HAS_SALSA20) + #include <botan/salsa20.h> +#endif + +#if defined(BOTAN_HAS_TURING) + #include <botan/turing.h> +#endif + +#if defined(BOTAN_HAS_WID_WAKE) + #include <botan/wid_wake.h> +#endif + +#if defined(BOTAN_HAS_CIPHER_MODE_PADDING) + #include <botan/mode_pad.h> +#endif + +#if defined(BOTAN_HAS_ADLER32) + #include <botan/adler32.h> +#endif + +#if defined(BOTAN_HAS_CRC24) + #include <botan/crc24.h> +#endif + +#if defined(BOTAN_HAS_CRC32) + #include <botan/crc32.h> +#endif + +#if defined(BOTAN_HAS_FORK_256) + #include <botan/fork256.h> +#endif + +#if defined(BOTAN_HAS_HAS_160) + #include <botan/has160.h> +#endif + +#if defined(BOTAN_HAS_MD2) + #include <botan/md2.h> +#endif + +#if defined(BOTAN_HAS_MD4) + #include <botan/md4.h> +#endif + +#if defined(BOTAN_HAS_MD4_IA32) + #include <botan/md4_ia32.h> +#endif + +#if defined(BOTAN_HAS_MD5) + #include <botan/md5.h> +#endif + +#if defined(BOTAN_HAS_MD5_IA32) + #include <botan/md5_ia32.h> +#endif + +#if defined(BOTAN_HAS_RIPEMD_128) + #include <botan/rmd128.h> +#endif + +#if defined(BOTAN_HAS_RIPEMD_160) + #include <botan/rmd160.h> +#endif + +#if defined(BOTAN_HAS_SHA1) + #include <botan/sha160.h> +#endif + +#if defined(BOTAN_HAS_SHA1_IA32) + #include <botan/sha1_ia32.h> +#endif + +#if defined(BOTAN_HAS_SHA1_SSE2) + #include <botan/sha1_sse2.h> +#endif + +#if defined(BOTAN_HAS_SHA1_AMD64) + #include <botan/sha1_amd64.h> +#endif + +#if defined(BOTAN_HAS_SHA2) + #include <botan/sha256.h> + #include <botan/sha_64.h> +#endif + +#if defined(BOTAN_HAS_TIGER) + #include <botan/tiger.h> +#endif + +#if defined(BOTAN_HAS_WHIRLPOOL) + #include <botan/whrlpool.h> +#endif + +#if defined(BOTAN_HAS_PARALLEL_HASH) + #include <botan/par_hash.h> +#endif + +#if defined(BOTAN_HAS_CBC_MAC) + #include <botan/cbc_mac.h> +#endif + +#if defined(BOTAN_HAS_CMAC) + #include <botan/cmac.h> +#endif + +#if defined(BOTAN_HAS_HMAC) + #include <botan/hmac.h> +#endif + +#if defined(BOTAN_HAS_SSL3_MAC) + #include <botan/ssl3_mac.h> +#endif + +#if defined(BOTAN_HAS_ANSI_X919_MAC) + #include <botan/x919_mac.h> +#endif + +#if defined(BOTAN_HAS_PBKDF1) + #include <botan/pbkdf1.h> +#endif + +#if defined(BOTAN_HAS_PBKDF2) + #include <botan/pbkdf2.h> +#endif + +#if defined(BOTAN_HAS_PGPS2K) + #include <botan/pgp_s2k.h> +#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<std::string> 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<std::string> 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<std::string> 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<std::string> 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<std::string> 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<std::string> 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 <botan/eng_def.h> +#include <botan/parsing.h> +#include <botan/filters.h> +#include <botan/lookup.h> + +#if defined(BOTAN_HAS_ECB) + #include <botan/ecb.h> +#endif + +#if defined(BOTAN_HAS_CBC) + #include <botan/cbc.h> +#endif + +#if defined(BOTAN_HAS_CTS) + #include <botan/cts.h> +#endif + +#if defined(BOTAN_HAS_CFB) + #include <botan/cfb.h> +#endif + +#if defined(BOTAN_HAS_OFB) + #include <botan/ofb.h> +#endif + +#if defined(BOTAN_HAS_CTR) + #include <botan/ctr.h> +#endif + +#if defined(BOTAN_HAS_EAX) + #include <botan/eax.h> +#endif + +namespace Botan { + +/************************************************* +* Get a cipher object * +*************************************************/ +Keyed_Filter* Default_Engine::get_cipher(const std::string& algo_spec, + Cipher_Dir direction) + { + std::vector<std::string> 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<std::string> 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 <botan/engine.h> +#include <botan/libstate.h> +#include <botan/stl_util.h> +#include <botan/lookup.h> + +namespace Botan { + +namespace { + +/************************************************* +* Algorithm Cache * +*************************************************/ +template<typename T> +class Algorithm_Cache_Impl : public Engine::Algorithm_Cache<T> + { + 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<std::string, T*>::iterator i = mappings.begin(); + + while(i != mappings.end()) + { + delete i->second; + ++i; + } + delete mutex; + } + private: + Mutex* mutex; + mutable std::map<std::string, T*> 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<BlockCipher>(); + cache_of_sc = new Algorithm_Cache_Impl<StreamCipher>(); + cache_of_hf = new Algorithm_Cache_Impl<HashFunction>(); + cache_of_mac = new Algorithm_Cache_Impl<MessageAuthenticationCode>(); + cache_of_s2k = new Algorithm_Cache_Impl<S2K>(); + cache_of_bc_pad = + new Algorithm_Cache_Impl<BlockCipherModePaddingMethod>(); + } + +/************************************************* +* 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 <botan/engine.h> +#include <botan/libstate.h> +#include <botan/lookup.h> +#include <botan/look_add.h> +#include <botan/eng_def.h> + +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<Default_Engine*>(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<Default_Engine*>(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<Default_Engine*>(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<Default_Engine*>(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<Default_Engine*>(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 <botan/base.h> +#include <botan/mutex.h> +#include <botan/pk_ops.h> +#include <botan/pow_mod.h> +#include <botan/basefilt.h> +#include <botan/enums.h> +#include <utility> +#include <map> + +namespace Botan { + +/************************************************* +* Engine Base Class * +*************************************************/ +class BOTAN_DLL Engine + { + public: + template<typename T> + 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<typename T> + const T* lookup_algo(const Algorithm_Cache<T>* 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<BlockCipher>* cache_of_bc; + Algorithm_Cache<StreamCipher>* cache_of_sc; + Algorithm_Cache<HashFunction>* cache_of_hf; + Algorithm_Cache<MessageAuthenticationCode>* cache_of_mac; + Algorithm_Cache<BlockCipherModePaddingMethod>* cache_of_bc_pad; + Algorithm_Cache<S2K>* 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 <botan/lookup.h> +#include <botan/libstate.h> +#include <botan/parsing.h> +#include <botan/util.h> + +#if defined(BOTAN_HAS_MGF1) + #include <botan/mgf1.h> +#endif + +#if defined(BOTAN_HAS_EMSA1) + #include <botan/emsa1.h> +#endif + +#if defined(BOTAN_HAS_EMSA2) + #include <botan/emsa2.h> +#endif + +#if defined(BOTAN_HAS_EMSA3) + #include <botan/emsa3.h> +#endif + +#if defined(BOTAN_HAS_EMSA4) + #include <botan/emsa4.h> +#endif + +#if defined(BOTAN_HAS_EMSA_RAW) + #include <botan/emsa_raw.h> +#endif + +#if defined(BOTAN_HAS_EME1) + #include <botan/eme1.h> +#endif + +#if defined(BOTAN_HAS_EME_PKCS1v15) + #include <botan/eme_pkcs.h> +#endif + +#if defined(BOTAN_HAS_KDF1) + #include <botan/kdf1.h> +#endif + +#if defined(BOTAN_HAS_KDF2) + #include <botan/kdf2.h> +#endif + +#if defined(BOTAN_HAS_X942_PRF) + #include <botan/prf_x942.h> +#endif + +#if defined(BOTAN_HAS_SSL_V3_PRF) + #include <botan/prf_ssl3.h> +#endif + +#if defined(BOTAN_HAS_TLS_V10_PRF) + #include <botan/prf_tls.h> +#endif + +namespace Botan { + +/************************************************* +* Get an EMSA by name * +*************************************************/ +EMSA* get_emsa(const std::string& algo_spec) + { + std::vector<std::string> 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<std::string> 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<std::string> 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<std::string> 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 <botan/get_pbe.h> +#include <botan/oids.h> +#include <botan/parsing.h> + +#if defined(BOTAN_HAS_PBE_PKCS_V15) + #include <botan/pbes1.h> +#endif + +#if defined(BOTAN_HAS_PBE_PKCS_V20) + #include <botan/pbes2.h> +#endif + +namespace Botan { + +/************************************************* +* Get an encryption PBE, set new parameters * +*************************************************/ +PBE* get_pbe(const std::string& pbe_name) + { + std::vector<std::string> 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<std::string> 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 <botan/pbe.h> +#include <string> + +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 + +<requires> +aes +sha1 +</requires> + +<add> +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 +</add> 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 <botan/build.h> +#include <string> +#include <map> + +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<std::string, std::string> 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 <botan/init.h> +#include <botan/libstate.h> +#include <botan/modules.h> + +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 <botan/init.h> +#include <botan/parsing.h> +#include <botan/stl_util.h> +#include <botan/exceptn.h> + +namespace Botan { + +namespace { + +/************************************************* +* Check for an arbitrary boolean-valued option * +*************************************************/ +bool boolean_arg(const std::map<std::string, std::string>& args, + const std::string& key, bool not_found = false) + { + std::map<std::string, std::string>::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<std::string> 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<std::string> 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 <botan/libstate.h> +#include <botan/modules.h> +#include <botan/engine.h> +#include <botan/stl_util.h> +#include <botan/mutex.h> +#include <botan/charset.h> +#include <botan/lookup.h> +#include <algorithm> + +#if defined(BOTAN_HAS_SELFTEST) + #include <botan/selftest.h> +#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<std::string, Allocator*>(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<std::string, Allocator*>(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<std::string, std::string>(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<std::string, std::string>::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<Allocator*> 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<Engine*> 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<Engine>()); + + 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 <botan/base.h> +#include <botan/init.h> +#include <string> +#include <vector> +#include <map> + +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<std::string, std::string> config; + class Mutex* config_lock; + + class Mutex* allocator_lock; + std::map<std::string, Allocator*> alloc_factory; + mutable Allocator* cached_default_allocator; + std::vector<Allocator*> allocators; + + class Mutex* engine_lock; + std::vector<class Engine*> 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 <botan/base.h> +#include <botan/libstate.h> +#include <botan/mode_pad.h> +#include <botan/s2k.h> + +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 <botan/look_pk.h> +#include <botan/lookup.h> + +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 <botan/pubkey.h> + +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 <botan/lookup.h> +#include <botan/libstate.h> + +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 <botan/base.h> +#include <botan/enums.h> +#include <botan/filters.h> +#include <botan/mode_pad.h> +#include <botan/kdf.h> +#include <botan/pk_pad.h> +#include <botan/libstate.h> +#include <botan/s2k.h> + +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 <botan/oids.h> +#include <botan/libstate.h> + +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 <botan/asn1_oid.h> + +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 <botan/libstate.h> + +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-----" + "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" + "jzbmIBJ//////////wIBAg==" + "-----END X942 DH PARAMETERS-----"); + + config.set("dl", "modp/ietf/8192", + "-----BEGIN X942 DH PARAMETERS-----" + "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" + "-----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); + } + +} |