aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstate
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstate')
-rw-r--r--src/libstate/def_alg.cpp660
-rw-r--r--src/libstate/def_mode.cpp177
-rw-r--r--src/libstate/def_powm.cpp22
-rw-r--r--src/libstate/eng_base.cpp252
-rw-r--r--src/libstate/eng_def.h72
-rw-r--r--src/libstate/engine.cpp431
-rw-r--r--src/libstate/engine.h209
-rw-r--r--src/libstate/get_enc.cpp240
-rw-r--r--src/libstate/info.txt27
-rw-r--r--src/libstate/init.h124
-rw-r--r--src/libstate/init_def.cpp60
-rw-r--r--src/libstate/init_opt.cpp102
-rw-r--r--src/libstate/libstate.cpp294
-rw-r--r--src/libstate/libstate.h142
-rw-r--r--src/libstate/look_add.h28
-rw-r--r--src/libstate/lookup.cpp239
-rw-r--r--src/libstate/lookup.h244
-rw-r--r--src/libstate/modules.cpp126
-rw-r--r--src/libstate/modules.h54
-rw-r--r--src/libstate/oid_lookup/info.txt15
-rw-r--r--src/libstate/oid_lookup/oids.cpp74
-rw-r--r--src/libstate/oid_lookup/oids.h56
-rw-r--r--src/libstate/policy.cpp513
23 files changed, 4161 insertions, 0 deletions
diff --git a/src/libstate/def_alg.cpp b/src/libstate/def_alg.cpp
new file mode 100644
index 000000000..6f89fa121
--- /dev/null
+++ b/src/libstate/def_alg.cpp
@@ -0,0 +1,660 @@
+/*************************************************
+* Default Engine Algorithms Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/eng_def.h>
+#include <botan/lookup.h>
+#include <botan/libstate.h>
+#include <botan/parsing.h>
+#include <memory>
+
+#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>
+ #include <botan/desx.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/sha2_32.h>
+ #include <botan/sha2_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 = get_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);
+
+ std::auto_ptr<HashFunction> hash(get_hash(name[1]));
+ if(!hash.get())
+ throw Algorithm_Not_Found(name[1]);
+
+ std::auto_ptr<StreamCipher> sc(get_stream_cipher(name[2]));
+ if(!sc.get())
+ throw Algorithm_Not_Found(name[2]);
+
+ return new Lion(hash.release(), sc.release(), 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-224", SHA_224);
+ 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 defined(BOTAN_HAS_PARALLEL_HASH)
+ if(algo_name == "Parallel")
+ {
+ if(name.size() < 2)
+ throw Invalid_Algorithm_Name(algo_spec);
+ name.erase(name.begin());
+ return new Parallel(name);
+ }
+#endif
+
+ 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)
+ if(algo_name == "CBC-MAC")
+ {
+ if(name.size() == 2)
+ return new CBC_MAC(get_block_cipher(name[1]));
+ throw Invalid_Algorithm_Name(algo_spec);
+ }
+#endif
+
+#if defined(BOTAN_HAS_CMAC)
+ if(algo_name == "CMAC")
+ {
+ if(name.size() == 2)
+ return new CMAC(get_block_cipher(name[1]));
+ throw Invalid_Algorithm_Name(algo_spec);
+ }
+#endif
+
+#if defined(BOTAN_HAS_HMAC)
+ if(algo_name == "HMAC")
+ {
+ if(name.size() == 2)
+ return new HMAC(get_hash(name[1]));
+ throw Invalid_Algorithm_Name(algo_spec);
+ }
+#endif
+
+#if defined(BOTAN_HAS_SSL3_MAC)
+ if(algo_name == "SSL3-MAC")
+ {
+ if(name.size() == 2)
+ return new SSL3_MAC(get_hash(name[1]));
+ throw Invalid_Algorithm_Name(algo_spec);
+ }
+#endif
+
+#if defined(BOTAN_HAS_ANSI_X919_MAC)
+ if(algo_name == "X9.19-MAC")
+ {
+ if(name.size() == 1)
+ return new ANSI_X919_MAC(get_block_cipher("DES"));
+ throw Invalid_Algorithm_Name(algo_spec);
+ }
+#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)
+ if(algo_name == "PBKDF1")
+ {
+ if(name.size() == 2)
+ return new PKCS5_PBKDF1(get_hash(name[1]));
+ throw Invalid_Algorithm_Name(algo_spec);
+ }
+#endif
+
+#if defined(BOTAN_HAS_PBKDF2)
+ if(algo_name == "PBKDF2")
+ {
+ if(name.size() == 2)
+ return new PKCS5_PBKDF2(get_mac("HMAC(" + name[1] + ")"));
+ throw Invalid_Algorithm_Name(algo_spec);
+ }
+#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/libstate/def_mode.cpp b/src/libstate/def_mode.cpp
new file mode 100644
index 000000000..b062cc34b
--- /dev/null
+++ b/src/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/libstate/def_powm.cpp b/src/libstate/def_powm.cpp
new file mode 100644
index 000000000..a28438f5b
--- /dev/null
+++ b/src/libstate/def_powm.cpp
@@ -0,0 +1,22 @@
+/*************************************************
+* Modular Exponentiation Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/eng_def.h>
+#include <botan/def_powm.h>
+
+namespace Botan {
+
+/*************************************************
+* Choose a modular exponentation algorithm *
+*************************************************/
+Modular_Exponentiator*
+Default_Engine::mod_exp(const BigInt& n, Power_Mod::Usage_Hints hints) const
+ {
+ if(n.is_odd())
+ return new Montgomery_Exponentiator(n, hints);
+ return new Fixed_Window_Exponentiator(n, hints);
+ }
+
+}
diff --git a/src/libstate/eng_base.cpp b/src/libstate/eng_base.cpp
new file mode 100644
index 000000000..aaaf46723
--- /dev/null
+++ b/src/libstate/eng_base.cpp
@@ -0,0 +1,252 @@
+/*************************************************
+* 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;
+ };
+
+}
+
+/*************************************************
+* 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/libstate/eng_def.h b/src/libstate/eng_def.h
new file mode 100644
index 000000000..36ef14a69
--- /dev/null
+++ b/src/libstate/eng_def.h
@@ -0,0 +1,72 @@
+/*************************************************
+* Default Engine Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_DEFAULT_ENGINE_H__
+#define BOTAN_DEFAULT_ENGINE_H__
+
+#include <botan/engine.h>
+
+namespace Botan {
+
+/*************************************************
+* Default Engine *
+*************************************************/
+class BOTAN_DLL Default_Engine : public Engine
+ {
+ public:
+#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY)
+ IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&,
+ const BigInt&, const BigInt&, const BigInt&,
+ const BigInt&, const BigInt&) const;
+#endif
+
+#if defined(BOTAN_HAS_DSA)
+ DSA_Operation* dsa_op(const DL_Group&, const BigInt&,
+ const BigInt&) const;
+#endif
+
+#if defined(BOTAN_HAS_NYBERG_RUEPPEL)
+ NR_Operation* nr_op(const DL_Group&, const BigInt&, const BigInt&) const;
+#endif
+
+#if defined(BOTAN_HAS_ELGAMAL)
+ ELG_Operation* elg_op(const DL_Group&, const BigInt&,
+ const BigInt&) const;
+#endif
+
+#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
+ DH_Operation* dh_op(const DL_Group&, const BigInt&) const;
+#endif
+
+#if defined(BOTAN_HAS_ECDSA)
+ virtual ECDSA_Operation* ecdsa_op(const EC_Domain_Params&,
+ const BigInt&,
+ const PointGFp&) const;
+#endif
+
+#if defined(BOTAN_HAS_ECKAEG)
+ virtual ECKAEG_Operation* eckaeg_op(const EC_Domain_Params&,
+ const BigInt&,
+ const PointGFp&) const;
+#endif
+
+ Modular_Exponentiator* mod_exp(const BigInt&,
+ Power_Mod::Usage_Hints) const;
+
+ Keyed_Filter* get_cipher(const std::string&, Cipher_Dir);
+ private:
+ BlockCipher* find_block_cipher(const std::string&) const;
+ StreamCipher* find_stream_cipher(const std::string&) const;
+ HashFunction* find_hash(const std::string&) const;
+ MessageAuthenticationCode* find_mac(const std::string&) const;
+
+ class S2K* find_s2k(const std::string&) const;
+ class BlockCipherModePaddingMethod*
+ find_bc_pad(const std::string&) const;
+ };
+
+}
+
+#endif
diff --git a/src/libstate/engine.cpp b/src/libstate/engine.cpp
new file mode 100644
index 000000000..ce32fa3b4
--- /dev/null
+++ b/src/libstate/engine.cpp
@@ -0,0 +1,431 @@
+/*************************************************
+* 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 {
+
+#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY)
+/*************************************************
+* 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");
+ }
+#endif
+
+#if defined(BOTAN_HAS_DSA)
+/*************************************************
+* 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");
+ }
+#endif
+
+#if defined(BOTAN_HAS_NYBERG_RUEPPEL)
+/*************************************************
+* 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");
+ }
+#endif
+
+#if defined(BOTAN_HAS_ELGAMAL)
+/*************************************************
+* 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");
+ }
+#endif
+
+#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
+/*************************************************
+* 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");
+ }
+#endif
+
+#if defined(BOTAN_HAS_ECDSA)
+/*************************************************
+* Acquire an ECDSA op *
+*************************************************/
+ECDSA_Operation* ecdsa_op(const EC_Domain_Params& dom_pars,
+ const BigInt& priv_key,
+ const PointGFp& pub_key)
+ {
+ Library_State::Engine_Iterator i(global_state());
+
+ while(const Engine* engine = i.next())
+ {
+ ECDSA_Operation* op = engine->ecdsa_op(dom_pars, priv_key, pub_key);
+ if(op)
+ return op;
+ }
+
+ throw Lookup_Error("Engine_Core::ecdsa_op: Unable to find a working engine");
+ }
+#endif
+
+#if defined(BOTAN_HAS_ECKAEG)
+/*************************************************
+* Acquire a ECKAEG op *
+*************************************************/
+ECKAEG_Operation* eckaeg_op(const EC_Domain_Params& dom_pars,
+ const BigInt& priv_key,
+ const PointGFp& pub_key)
+ {
+ Library_State::Engine_Iterator i(global_state());
+
+ while(const Engine* engine = i.next())
+ {
+ ECKAEG_Operation* op = engine->eckaeg_op(dom_pars, priv_key, pub_key);
+ if(op)
+ return op;
+ }
+
+ throw Lookup_Error("Engine_Core::eckaeg_op: Unable to find a working engine");
+ }
+#endif
+
+/*************************************************
+* 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(const std::string& algo_spec,
+ Cipher_Dir direction)
+ {
+ Library_State::Engine_Iterator i(global_state());
+
+ 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(const std::string& algo_spec,
+ const SymmetricKey& key,
+ const InitializationVector& iv,
+ Cipher_Dir direction)
+ {
+ Keyed_Filter* cipher = get_cipher(algo_spec, direction);
+ cipher->set_key(key);
+
+ if(iv.length())
+ cipher->set_iv(iv);
+
+ return cipher;
+ }
+
+/*************************************************
+* Get a cipher object *
+*************************************************/
+Keyed_Filter* get_cipher(const std::string& algo_spec,
+ const SymmetricKey& key,
+ Cipher_Dir direction)
+ {
+ return get_cipher(algo_spec,
+ key, InitializationVector(), direction);
+ }
+
+}
diff --git a/src/libstate/engine.h b/src/libstate/engine.h
new file mode 100644
index 000000000..af0fb67e1
--- /dev/null
+++ b/src/libstate/engine.h
@@ -0,0 +1,209 @@
+/*************************************************
+* 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/pow_mod.h>
+#include <botan/basefilt.h>
+#include <botan/enums.h>
+#include <utility>
+#include <map>
+
+#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY)
+ #include <botan/if_op.h>
+#endif
+
+#if defined(BOTAN_HAS_DSA)
+ #include <botan/dsa_op.h>
+#endif
+
+#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
+ #include <botan/dh_op.h>
+#endif
+
+#if defined(BOTAN_HAS_NYBERG_RUEPPEL)
+ #include <botan/nr_op.h>
+#endif
+
+#if defined(BOTAN_HAS_ELGAMAL)
+ #include <botan/elg_op.h>
+#endif
+
+#if defined(BOTAN_HAS_ECDSA)
+ #include <botan/ecdsa_op.h>
+ #include <botan/ec_dompar.h>
+#endif
+
+#if defined(BOTAN_HAS_ECKAEG)
+ #include <botan/eckaeg_op.h>
+ #include <botan/ec_dompar.h>
+#endif
+
+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() {}
+ };
+
+#if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY)
+ virtual IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&,
+ const BigInt&, const BigInt&, const BigInt&,
+ const BigInt&, const BigInt&) const
+ { return 0; }
+#endif
+
+#if defined(BOTAN_HAS_DSA)
+ virtual DSA_Operation* dsa_op(const DL_Group&, const BigInt&,
+ const BigInt&) const
+ { return 0; }
+#endif
+
+#if defined(BOTAN_HAS_NYBERG_RUEPPEL)
+ virtual NR_Operation* nr_op(const DL_Group&, const BigInt&,
+ const BigInt&) const
+ { return 0; }
+#endif
+
+#if defined(BOTAN_HAS_ELGAMAL)
+ virtual ELG_Operation* elg_op(const DL_Group&, const BigInt&,
+ const BigInt&) const
+ { return 0; }
+#endif
+
+#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
+ virtual DH_Operation* dh_op(const DL_Group&, const BigInt&) const
+ { return 0; }
+#endif
+
+#if defined(BOTAN_HAS_ECDSA)
+ virtual ECDSA_Operation* ecdsa_op(const EC_Domain_Params&,
+ const BigInt&,
+ const PointGFp&) const
+ { return 0; }
+#endif
+
+#if defined(BOTAN_HAS_ECKAEG)
+ virtual ECKAEG_Operation* eckaeg_op(const EC_Domain_Params&,
+ const BigInt&,
+ const PointGFp&) const
+ { return 0; }
+#endif
+
+ virtual Modular_Exponentiator* mod_exp(const BigInt&,
+ Power_Mod::Usage_Hints) const
+ { return 0; }
+
+ 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 defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY)
+IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&,
+ const BigInt&, const BigInt&, const BigInt&,
+ const BigInt&, const BigInt&);
+#endif
+
+#if defined(BOTAN_HAS_DSA)
+DSA_Operation* dsa_op(const DL_Group&, const BigInt&, const BigInt&);
+#endif
+
+#if defined(BOTAN_HAS_NYBERG_RUEPPEL)
+NR_Operation* nr_op(const DL_Group&, const BigInt&, const BigInt&);
+#endif
+
+#if defined(BOTAN_HAS_ELGAMAL)
+ELG_Operation* elg_op(const DL_Group&, const BigInt&, const BigInt&);
+#endif
+
+#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
+DH_Operation* dh_op(const DL_Group&, const BigInt&);
+#endif
+
+#if defined(BOTAN_HAS_ECDSA)
+ECDSA_Operation* ecdsa_op(const EC_Domain_Params& dom_pars,
+ const BigInt& priv_key,
+ const PointGFp& pub_key);
+#endif
+
+#if defined(BOTAN_HAS_ECKAEG)
+ECKAEG_Operation* eckaeg_op(const EC_Domain_Params& dom_pars,
+ const BigInt& priv_key,
+ const PointGFp& pub_key);
+#endif
+
+}
+
+}
+
+#endif
diff --git a/src/libstate/get_enc.cpp b/src/libstate/get_enc.cpp
new file mode 100644
index 000000000..e42ab784e
--- /dev/null
+++ b/src/libstate/get_enc.cpp
@@ -0,0 +1,240 @@
+/*************************************************
+* 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_EMSA1_BSI)
+ #include <botan/emsa1_bsi.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(get_hash(name[1]));
+ }
+#endif
+
+#if defined(BOTAN_HAS_EMSA1_BSI)
+ if(emsa_name == "EMSA1_BSI")
+ {
+ if(name.size() == 2)
+ return new EMSA1_BSI(get_hash(name[1]));
+ }
+#endif
+
+#if defined(BOTAN_HAS_EMSA2)
+ if(emsa_name == "EMSA2")
+ {
+ if(name.size() == 2)
+ return new EMSA2(get_hash(name[1]));
+ }
+#endif
+
+#if defined(BOTAN_HAS_EMSA3)
+ if(emsa_name == "EMSA3")
+ {
+ if(name.size() == 2)
+ return new EMSA3(get_hash(name[1]));
+ }
+#endif
+
+#if defined(BOTAN_HAS_EMSA4)
+ if(emsa_name == "EMSA4")
+ {
+ // EMSA4 is hardcoded to use MGF1
+ if(name.size() >= 3 && name[2] != "MGF1")
+ throw Algorithm_Not_Found(algo_spec);
+
+ if(name.size() == 2 || name.size() == 3)
+ return new EMSA4(get_hash(name[1]));
+ else if(name.size() == 4)
+ return new EMSA4(get_hash(name[1]), 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)
+ {
+ if(name.size() >= 3)
+ {
+ // EME1 is hardcoded for MGF1
+ if(name[2] != "MGF1")
+ throw Algorithm_Not_Found(algo_spec);
+ }
+
+ return new EME1(get_hash(name[1]));
+ }
+ }
+#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(get_hash(name[1]));
+ }
+#endif
+
+#if defined(BOTAN_HAS_KDF2)
+ if(kdf_name == "KDF2")
+ {
+ if(name.size() == 2)
+ return new KDF2(get_hash(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/libstate/info.txt b/src/libstate/info.txt
new file mode 100644
index 000000000..93c429241
--- /dev/null
+++ b/src/libstate/info.txt
@@ -0,0 +1,27 @@
+realname "Botan Libstate Module"
+
+load_on auto
+
+define LIBSTATE_MODULE
+
+<add>
+def_alg.cpp
+def_mode.cpp
+def_powm.cpp
+eng_base.cpp
+eng_def.h
+engine.cpp
+engine.h
+get_enc.cpp
+init.h
+init_def.cpp
+init_opt.cpp
+libstate.cpp
+libstate.h
+look_add.h
+lookup.cpp
+lookup.h
+modules.cpp
+modules.h
+policy.cpp
+</add>
diff --git a/src/libstate/init.h b/src/libstate/init.h
new file mode 100644
index 000000000..86ef09bac
--- /dev/null
+++ b/src/libstate/init.h
@@ -0,0 +1,124 @@
+/*************************************************
+* 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 {
+
+/**
+* This class represents options for initializing the library.
+*/
+class BOTAN_DLL InitializerOptions
+ {
+ public:
+ /**
+ * Check whether this set of options has thread safety enabled.
+ * @return true if thread safety is enabled
+ */
+ bool thread_safe() const;
+
+ /**
+ * Check whether this set of options has the usage of alternative engines
+ * enabled.
+ * @return true if the usage of alternative engines
+ * is enabled
+ */
+ bool use_engines() const;
+
+ /**
+ * Check whether this set of options has enabled the seeding of the
+ * global RNG at startup.
+ * @return true if the seeding at startup is enabled
+ */
+ bool seed_rng() const;
+
+ /**
+ * Check whether this set of options has enabled the memory
+ * locking feature. This is implemented for Unix and Win32, but
+ * it only reliably works for Unix. There, all SecureVectors and
+ * SecureBuffers are kept from being ever swapped to disk. On
+ * Win32 plattforms, the corresponding pages are locked into the
+ * working set of the process, reducing the chance of being
+ * swapped to disk, but not strictly preventing it.
+ * @return true if the memory locking feature is enabled
+ */
+ bool secure_memory() const;
+
+ /**
+ * Check whether this set of options has the self-test-at-startup
+ * enabled. Same as self_test().
+ * @param return true if the self-test is enabled
+ */
+ bool fips_mode() const;
+
+ /**
+ * Check whether this set of options has the self-test-at-startup enabled.
+ * Same as fips_mode().
+ * @param return true if the self-test is enabled
+ */
+ bool self_test() const;
+
+ /**
+ * Get the full path of the configuration file to be used.
+ */
+ std::string config_file() const;
+
+ /**
+ * Create an initializer options object. The option are set based on the
+ * input string. The options can be set by building a white space separated
+ * list of elements out of the
+ * following set of strings:
+ * "config=<file name>",
+ * "selftest",
+ * "fips140",
+ * "seed_rng",
+ * "use_engines",
+ * "secure_memory",
+ * "thread_safe"
+ *
+ */
+ InitializerOptions(const std::string& options);
+ private:
+ std::map<std::string, std::string> args;
+ };
+
+/**
+* This class represents the Library Initialization/Shutdown Object. It has to
+* exceed the lifetime of any Botan object used in an application.
+*/
+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();
+
+ /**
+ * Construct a library initializer from a string. Does exactly the same
+ * as if an InitializerOptions object created with that string was used as
+ * the argument.
+ * @param args the string determining the desired library configuration
+ */
+ LibraryInitializer(const std::string& args = "") { initialize(args); }
+
+ /**
+ * Construct a library initializer.
+ * @param args the initializer option object specifying the desired
+ * library configuration
+ */
+ LibraryInitializer(const InitializerOptions& args) { initialize(args); }
+
+ ~LibraryInitializer() { deinitialize(); }
+ };
+
+}
+
+#endif
diff --git a/src/libstate/init_def.cpp b/src/libstate/init_def.cpp
new file mode 100644
index 000000000..03f97252e
--- /dev/null
+++ b/src/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/libstate/init_opt.cpp b/src/libstate/init_opt.cpp
new file mode 100644
index 000000000..5c4fbee65
--- /dev/null
+++ b/src/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/libstate/libstate.cpp b/src/libstate/libstate.cpp
new file mode 100644
index 000000000..60bb24fee
--- /dev/null
+++ b/src/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/libstate/libstate.h b/src/libstate/libstate.h
new file mode 100644
index 000000000..74d3d8ef3
--- /dev/null
+++ b/src/libstate/libstate.h
@@ -0,0 +1,142 @@
+/*************************************************
+* 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&);
+
+ /**
+ * Get a parameter value as std::string.
+ * @param section the section of the desired key
+ * @param key the desired keys name
+ * @result the value of the parameter
+ */
+ std::string get(const std::string& section,
+ const std::string& key) const;
+
+ /**
+ * Check whether a certain parameter is set
+ * or not.
+ * @param section the section of the desired key
+ * @param key the desired keys name
+ * @result true if the parameters value is set,
+ * false otherwise
+ */
+ bool is_set(const std::string& section, const std::string& key) const;
+
+ /**
+ * Set a configuration parameter.
+ * @param section the section of the desired key
+ * @param key the desired keys name
+ * @param overwrite if set to true, the parameters value
+ * will be overwritten even if it is already set, otherwise
+ * no existing values will be overwritten.
+ */
+ void set(const std::string& section, const std::string& key,
+ const std::string& value, bool overwrite = true);
+
+ /**
+ * Get a parameters value out of the "conf" section (
+ * referred to as option).
+ * @param key the desired keys name
+ */
+ std::string option(const std::string& key) const;
+
+ /**
+ * Set an option.
+ * @param key the key of the option to set
+ * @param value the value to set
+ */
+ /**
+ * Set an option.
+ * @param key the key of the option to set
+ * @param value the value to set
+ */
+ void set_option(const std::string key, const std::string& value);
+
+ /**
+ * Add a parameter value to the "alias" section.
+ * @param key the name of the parameter which shall have a new alias
+ * @param value the new alias
+ */
+ void add_alias(const std::string&, const std::string&);
+
+ /**
+ * Resolve an alias.
+ * @param alias the alias to resolve.
+ * @return what the alias stands for
+ */
+ std::string deref_alias(const std::string&) const;
+
+ class Mutex* get_mutex() const;
+ 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/libstate/look_add.h b/src/libstate/look_add.h
new file mode 100644
index 000000000..8c170049d
--- /dev/null
+++ b/src/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/libstate/lookup.cpp b/src/libstate/lookup.cpp
new file mode 100644
index 000000000..8e65afb93
--- /dev/null
+++ b/src/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/libstate/lookup.h b/src/libstate/lookup.h
new file mode 100644
index 000000000..75bfbccf3
--- /dev/null
+++ b/src/libstate/lookup.h
@@ -0,0 +1,244 @@
+/*************************************************
+* 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 *
+*************************************************/
+// NOTE: these functions return internally stored objects, library retains ownership
+
+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 *
+*************************************************/
+// NOTE: these functions create and return new objects, letting the caller assume ownership of them
+
+/**
+* Block cipher factory method.
+* @param name the name of the desired block cipher
+* @return the block cipher object
+*/
+BOTAN_DLL BlockCipher* get_block_cipher(const std::string& name);
+
+
+/**
+* Stream cipher factory method.
+* @param name the name of the desired stream cipher
+* @return the stream cipher object
+*/
+BOTAN_DLL StreamCipher* get_stream_cipher(const std::string& name);
+
+/**
+* Hash function factory method.
+* @param name the name of the desired hash function
+* @return the hash function object
+*/
+BOTAN_DLL HashFunction* get_hash(const std::string& name);
+
+/**
+* MAC factory method.
+* @param name the name of the desired MAC
+* @return the MAC object
+*/
+BOTAN_DLL MessageAuthenticationCode* get_mac(const std::string& name);
+
+/**
+* String to key algorithm factory method.
+* @param name the name of the desired string to key (S2K) algorithm
+* @return the string to key algorithm object
+*/
+BOTAN_DLL S2K* get_s2k(const std::string& name);
+
+/**
+* Block cipher padding mode factory/retrieval method.
+* @param name the name of the desired block cipher padding mode
+* @return the block cipher padding mode object
+*/
+BOTAN_DLL const BlockCipherModePaddingMethod* get_bc_pad(const std::string& name);
+
+/*************************************************
+* Get an EMSA/EME/KDF/MGF function *
+*************************************************/
+// NOTE: these functions create and return new objects, letting the caller assume ownership of them
+
+/**
+* Factory method for EME (message-encoding methods for encryption) objects
+* @param name the name of the EME to create
+* @return the desired EME object
+*/
+BOTAN_DLL EME* get_eme(const std::string& name);
+
+/**
+* Factory method for EMSA (message-encoding methods for signatures with appendix) objects
+* @param name the name of the EME to create
+* @return the desired EME object
+*/
+BOTAN_DLL EMSA* get_emsa(const std::string& name);
+
+/**
+* Factory method for MGF (mask generation function)
+* @param name the name of the MGF to create
+* @return the desired MGF object
+*/
+BOTAN_DLL MGF* get_mgf(const std::string& name);
+
+/**
+* Factory method for KDF (key derivation function)
+* @param name the name of the KDF to create
+* @return the desired KDF object
+*/
+BOTAN_DLL KDF* get_kdf(const std::string& name);
+
+/*************************************************
+* Get a cipher object *
+*************************************************/
+
+/**
+* Factory method for general symmetric cipher filters.
+* @param name the name of the desired cipher
+* @param key the key to be used for encryption/decryption performed by the filter
+* @param iv the initialization vector to be used
+* @param dir determines whether the filter will be an encrypting or decrypting
+* filter
+* @return the encryption or decryption filter
+*/
+BOTAN_DLL Keyed_Filter* get_cipher(const std::string& name,
+ const SymmetricKey& key,
+ const InitializationVector& iv,
+ Cipher_Dir dir);
+/**
+* Factory method for general symmetric cipher filters.
+* @param name the name of the desired cipher
+* @param key the key to be used for encryption/decryption performed by the filter
+* @param dir determines whether the filter will be an encrypting or decrypting
+* filter
+* @return the encryption or decryption filter
+*/
+BOTAN_DLL Keyed_Filter* get_cipher(const std::string& name,
+ const SymmetricKey& key,
+ Cipher_Dir dir);
+
+/** Factory method for general symmetric cipher filters. No key will
+* be set in the filter.
+* @param name the name of the desired cipher
+* @param dir determines whether the filter will be an encrypting or decrypting filter
+* @return the encryption or decryption filter
+*/
+BOTAN_DLL Keyed_Filter* get_cipher(const std::string& name, Cipher_Dir dir);
+
+/**
+* Check if an algorithm exists.
+* @param name the name of the algorithm to check for
+* @return true if the algorithm exists, false otherwise
+*/
+BOTAN_DLL bool have_algorithm(const std::string& name);
+
+/**
+* Check if a block cipher algorithm exists.
+* @param name the name of the algorithm to check for
+* @return true if the algorithm exists, false otherwise
+*/
+BOTAN_DLL bool have_block_cipher(const std::string& name);
+
+/**
+* Check if a stream cipher algorithm exists.
+* @param name the name of the algorithm to check for
+* @return true if the algorithm exists, false otherwise
+*/
+BOTAN_DLL bool have_stream_cipher(const std::string& name);
+
+/**
+* Check if a hash algorithm exists.
+* @param name the name of the algorithm to check for
+* @return true if the algorithm exists, false otherwise
+*/
+BOTAN_DLL bool have_hash(const std::string& name);
+
+/**
+* Check if a MAC algorithm exists.
+* @param name the name of the algorithm to check for
+* @return true if the algorithm exists, false otherwise
+*/
+BOTAN_DLL bool have_mac(const std::string& name);
+
+/*************************************************
+* Query information about an algorithm *
+*************************************************/
+
+/**
+* Find out the block size of a certain symmetric algorithm.
+* @param name the name of the algorithm
+* @return the block size of the specified algorithm
+*/
+BOTAN_DLL u32bit block_size_of(const std::string& name);
+
+/**
+* Find out the output length of a certain symmetric algorithm.
+* @param name the name of the algorithm
+* @return the output length of the specified algorithm
+*/
+BOTAN_DLL u32bit output_length_of(const std::string& name);
+
+/**
+* Find out the whether a certain key length is allowd for a given symmetric algorithm.
+* @param keylen the key length in question
+* @param name the name of the algorithm
+* @return true if the key length is valid for that algorithm, false otherwise
+*/
+BOTAN_DLL bool valid_keylength_for(u32bit keylen, const std::string& name);
+
+/**
+* Find out the minimum key size of a certain symmetric algorithm.
+* @param name the name of the algorithm
+* @return the minimum key length of the specified algorithm
+*/
+BOTAN_DLL u32bit min_keylength_of(const std::string& name);
+
+/**
+* Find out the maximum key size of a certain symmetric algorithm.
+* @param name the name of the algorithm
+* @return the maximum key length of the specified algorithm
+*/
+BOTAN_DLL u32bit max_keylength_of(const std::string& name);
+
+/**
+* Find out the size any valid key is a multiple of for a certain algorithm.
+* @param name the name of the algorithm
+* @return the size any valid key is a multiple of
+*/
+BOTAN_DLL u32bit keylength_multiple_of(const std::string& name);
+
+}
+
+#endif
diff --git a/src/libstate/modules.cpp b/src/libstate/modules.cpp
new file mode 100644
index 000000000..bdebc3460
--- /dev/null
+++ b/src/libstate/modules.cpp
@@ -0,0 +1,126 @@
+/*************************************************
+* Module Factory Source File *
+* (C) 1999-2008 Jack Lloyd *
+*************************************************/
+
+#include <botan/modules.h>
+#include <botan/defalloc.h>
+#include <botan/eng_def.h>
+#include <botan/parsing.h>
+
+#if defined(BOTAN_HAS_MUTEX_PTHREAD)
+ #include <botan/mux_pthr.h>
+#elif defined(BOTAN_HAS_MUTEX_WIN32)
+ #include <botan/mux_win32.h>
+#elif defined(BOTAN_HAS_MUTEX_QT)
+ #include <botan/mux_qt.h>
+#endif
+
+#if defined(BOTAN_HAS_MUTEX_NOOP)
+ #include <botan/mux_noop.h>
+#endif
+
+#if defined(BOTAN_HAS_ALLOC_MMAP)
+ #include <botan/mmap_mem.h>
+#endif
+
+#if defined(BOTAN_HAS_ENGINE_GNU_MP)
+ #include <botan/eng_gmp.h>
+#endif
+
+#if defined(BOTAN_HAS_ENGINE_OPENSSL)
+ #include <botan/eng_ossl.h>
+#endif
+
+namespace Botan {
+
+/*************************************************
+* Return a mutex factory, if available *
+*************************************************/
+Mutex_Factory* Builtin_Modules::mutex_factory(bool thread_safe) const
+ {
+ if(!thread_safe)
+ {
+#if defined(BOTAN_HAS_MUTEX_NOOP)
+ return new Noop_Mutex_Factory;
+#endif
+ }
+
+#if defined(BOTAN_HAS_MUTEX_PTHREAD)
+ return new Pthread_Mutex_Factory;
+#elif defined(BOTAN_HAS_MUTEX_WIN32)
+ return new Win32_Mutex_Factory;
+#elif defined(BOTAN_HAS_MUTEX_QT)
+ return new Qt_Mutex_Factory;
+#else
+ return 0;
+#endif
+ }
+
+/*************************************************
+* Find any usable allocators *
+*************************************************/
+std::vector<Allocator*> Builtin_Modules::allocators(Mutex_Factory* mf) const
+ {
+ std::vector<Allocator*> allocators;
+
+#if defined(BOTAN_HAS_ALLOC_MMAP)
+ allocators.push_back(new MemoryMapping_Allocator(mf->make()));
+#endif
+
+ allocators.push_back(new Locking_Allocator(mf->make()));
+ allocators.push_back(new Malloc_Allocator);
+
+ return allocators;
+ }
+
+/*************************************************
+* Return the default allocator *
+*************************************************/
+std::string Builtin_Modules::default_allocator() const
+ {
+ if(should_lock)
+ {
+#if defined(BOTAN_HAS_ALLOC_MMAP)
+ return "mmap";
+#else
+ return "locking";
+#endif
+ }
+ else
+ return "malloc";
+ }
+
+/*************************************************
+* Find any usable engines *
+*************************************************/
+std::vector<Engine*> Builtin_Modules::engines() const
+ {
+ std::vector<Engine*> engines;
+
+ if(use_engines)
+ {
+#if defined(BOTAN_HAS_ENGINE_GNU_MP)
+ engines.push_back(new GMP_Engine);
+#endif
+
+#if defined(BOTAN_HAS_ENGINE_OPENSSL)
+ engines.push_back(new OpenSSL_Engine);
+#endif
+ }
+
+ engines.push_back(new Default_Engine);
+
+ return engines;
+ }
+
+/*************************************************
+* Builtin_Modules Constructor *
+*************************************************/
+Builtin_Modules::Builtin_Modules(const InitializerOptions& args) :
+ should_lock(args.secure_memory()),
+ use_engines(args.use_engines())
+ {
+ }
+
+}
diff --git a/src/libstate/modules.h b/src/libstate/modules.h
new file mode 100644
index 000000000..abbfbb2c6
--- /dev/null
+++ b/src/libstate/modules.h
@@ -0,0 +1,54 @@
+/*************************************************
+* Module Factory Header File *
+* (C) 1999-2008 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_MODULE_FACTORIES_H__
+#define BOTAN_MODULE_FACTORIES_H__
+
+#include <botan/init.h>
+#include <botan/mutex.h>
+#include <string>
+#include <vector>
+
+namespace Botan {
+
+/*************************************************
+* Module Builder Interface *
+*************************************************/
+class BOTAN_DLL Modules
+ {
+ public:
+ virtual class Mutex_Factory* mutex_factory(bool) const = 0;
+
+ virtual std::string default_allocator() const = 0;
+
+ virtual std::vector<class Allocator*>
+ allocators(Mutex_Factory*) const = 0;
+
+ virtual std::vector<class Engine*> engines() const = 0;
+
+ virtual ~Modules() {}
+ };
+
+/*************************************************
+* Built In Modules *
+*************************************************/
+class BOTAN_DLL Builtin_Modules : public Modules
+ {
+ public:
+ class Mutex_Factory* mutex_factory(bool) const;
+
+ std::string default_allocator() const;
+
+ std::vector<class Allocator*> allocators(Mutex_Factory*) const;
+ std::vector<class Engine*> engines() const;
+
+ Builtin_Modules(const InitializerOptions&);
+ private:
+ const bool should_lock, use_engines;
+ };
+
+}
+
+#endif
diff --git a/src/libstate/oid_lookup/info.txt b/src/libstate/oid_lookup/info.txt
new file mode 100644
index 000000000..b5f4ef21f
--- /dev/null
+++ b/src/libstate/oid_lookup/info.txt
@@ -0,0 +1,15 @@
+realname "OID Lookup"
+
+load_on dep
+
+define OID_LOOKUP
+
+<requires>
+#libstate
+#asn1
+</requires>
+
+<add>
+oids.cpp
+oids.h
+</add>
diff --git a/src/libstate/oid_lookup/oids.cpp b/src/libstate/oid_lookup/oids.cpp
new file mode 100644
index 000000000..0823625ea
--- /dev/null
+++ b/src/libstate/oid_lookup/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/libstate/oid_lookup/oids.h b/src/libstate/oid_lookup/oids.h
new file mode 100644
index 000000000..0df95fb36
--- /dev/null
+++ b/src/libstate/oid_lookup/oids.h
@@ -0,0 +1,56 @@
+/*************************************************
+* 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.
+* @param oid the oid to register
+* @param name the name to be associated with the oid
+*/
+BOTAN_DLL void add_oid(const OID& oid, const std::string& name);
+
+/**
+* See if an OID exists in the internal table.
+* @param oid the oid to check for
+* @return true if the oid is registered
+*/
+BOTAN_DLL bool have_oid(const std::string& oid);
+
+/**
+* Resolve an OID
+* @param oid the OID to look up
+* @return the name associated with this OID
+*/
+BOTAN_DLL std::string lookup(const OID& oid);
+
+/**
+* Find the OID to a name. The lookup will be performed in the
+* general OID section of the configuration.
+* @param name the name to resolve
+* @return the OID associated with the specified name
+*/
+BOTAN_DLL OID lookup(const std::string& name);
+
+/**
+* Tests whether the specified OID stands for the specified name.
+* @param oid the OID to check
+* @param name the name to check
+* @return true if the specified OID stands for the specified name
+*/
+BOTAN_DLL bool name_of(const OID& oid, const std::string& name);
+
+}
+
+}
+
+#endif
diff --git a/src/libstate/policy.cpp b/src/libstate/policy.cpp
new file mode 100644
index 000000000..e411ed111
--- /dev/null
+++ b/src/libstate/policy.cpp
@@ -0,0 +1,513 @@
+/*************************************************
+* 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)
+ {
+ /* Public key types */
+ add_oid(config, "1.2.840.113549.1.1.1", "RSA");
+ add_oid(config, "2.5.8.1.1", "RSA"); // RSA alternate
+ 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.2.840.10045.2.1", "ECDSA"); // X9.62
+
+ /* Ciphers */
+ 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");
+
+ /* Hash Functions */
+ 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");
+
+ /* Key Wrap */
+ 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");
+
+ /* Compression */
+ add_oid(config, "1.2.840.113549.1.9.16.3.8", "Compression.Zlib");
+
+ /* Public key signature schemes */
+ 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.2.840.10045.4.1", "ECDSA/EMSA1_BSI(SHA-160)");
+ add_oid(config, "1.2.840.10045.4.3.1", "ECDSA/EMSA1_BSI(SHA-224)");
+ add_oid(config, "1.2.840.10045.4.3.2", "ECDSA/EMSA1_BSI(SHA-256)");
+ add_oid(config, "1.2.840.10045.4.3.3", "ECDSA/EMSA1_BSI(SHA-384)");
+ add_oid(config, "1.2.840.10045.4.3.4", "ECDSA/EMSA1_BSI(SHA-512)");
+
+ add_oid(config, "1.2.840.10045.4.3.1", "ECDSA/EMSA1(SHA-224)");
+ add_oid(config, "1.2.840.10045.4.3.2", "ECDSA/EMSA1(SHA-256)");
+ add_oid(config, "1.2.840.10045.4.3.3", "ECDSA/EMSA1(SHA-384)");
+ add_oid(config, "1.2.840.10045.4.3.4", "ECDSA/EMSA1(SHA-512)");
+
+ 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");
+
+ /* CVC */
+ add_oid(config, "0.4.0.127.0.7.3.1.2.1", "CertificateHolderAuthorizationTemplate");
+ }
+
+/*************************************************
+* 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/XLb0Brft7j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+7gw3/b7khTYEem+hrkmgFCSRth/VppPjgTYOpu"
+ "WTATI29kuo87Ht0b3vx/ygNWzymHcu2cF6CYANdYNSn2yBPsGIvLk9hDLUSMbR9t"
+ "9efNinaiZzZdZ2pdje2/iiPzZhKlmZAoqJXr16E33HoAm8ZpX6zB5QDjJcl2eBl1"
+ "Cui5DoH6QWvnNzp/e2qvOBejTAZBWtQgGMgFjk8s8+S/32P0eZHUvT8bZkRfB46i"
+ "2/+sLWKl6gPZFaCqVWZHtr9fpHDsCmYvaQfAG/BTy4r3eU3xlANQ6sXb4u07eqhV"
+ "HsUP3/h1jOZY0Ynqrm0rZPYXeUsZHD/0a7ceAjQCH0ezH6Qwdwlflq2Fujprc0p8"
+ "jzbmIBJ//////////wIBAg=="
+ "-----END X942 DH PARAMETERS-----");
+
+ config.set("dl", "modp/ietf/8192",
+ "-----BEGIN X942 DH PARAMETERS-----"
+ "MIIIDAKCBAEA///////////JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxOb"
+ "IlFKCHmONATd75UZs806QxswKwpt8l8UN0/hNW1tUcJF5IW1dmJefsb0TELppjft"
+ "awv/XLb0Brft7jhr+1qJn6WunyQRfEsf5kkoZlHs5Fs9wgB8uKFjvwWY2kg2HFXT"
+ "mmkWP6j9JM9fg2VdI9yjrZYcYvNWIIVSu57VKQdwlpZtZww1Tkq8mATxdGwIyhgh"
+ "fDKQXkYuNs474553LBgOhgObJ4Oi7Aeij7XFXfBvTFLJ3ivL9pVYFxg5lUl86pVq"
+ "5RXSJhiY+gUQFXKOWoqqxC2tMxcNBFB6M6hVIavfHLpk7PuFBFjb7wqK6nFXXQYM"
+ "fbOXD4Wm4eTHq/WujNsJM9cejJTgSiVhnc7j0iYa0u5r8S/6BtmKCGTYdgJzPshq"
+ "ZFIfKxgXeyAMu+EXV3phXWx3CYjAutlG4gjiT6B05asxQ9tb/OD9EI5LgtEgqSEI"
+ "ARpyPBKnh+bXiHGaEL26WyaZwycYavTiPBqUaDS2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eRDF8HC7v1Opb/RYEP0PLQZ"
+ "gfat7p0DFZ562dE8UzaVCfwfonwW75iHcDpVtRsiy/RM0BKu4LJ5jmKEI0KO/NWk"
+ "DK72v1DY6ohev3Omuf15teGPZ9E0GsgjenXDz8kgBKHFpA42a8RNABdq9xwV5IyG"
+ "034BNyPKrHIjqzv01U8YKHE7K0pv5A+rdEBctziwZMBuzHbp7///////////AgEC"
+ "-----END X942 DH PARAMETERS-----");
+
+ config.set("dl", "dsa/jce/512",
+ "-----BEGIN DSA PARAMETERS-----"
+ "MIGdAkEA/KaCzo4Syrom78z3EQ5SbbB4sF7ey80etKII864WF64B81uRpH5t9jQT"
+ "xeEu0ImbzRMqzVDZkVG9xD7nN1kuFwIVAJYu3cw2nLqOuyYO5rahJtk0bjjFAkEA"
+ "3gtU76vylwh+5iPVylWIxkgo70/eT/uuHs0gBndrBbEbgeo83pvDlkwWh8UyW/Q9"
+ "fM76DQqGvl3/3dDRFD3NdQ=="
+ "-----END DSA PARAMETERS-----");
+
+ config.set("dl", "dsa/jce/768",
+ "-----BEGIN DSA PARAMETERS-----"
+ "MIHdAmEA6eZCWZ01XzfJf/01ZxILjiXJzUPpJ7OpZw++xdiQFBki0sOzrSSACTeZ"
+ "hp0ehGqrSfqwrSbSzmoiIZ1HC859d31KIfvpwnC1f2BwAvPO+Dk2lM9F7jaIwRqM"
+ "VqsSej2vAhUAnNvYTJ8awvOND4D0KrlS5zOL9RECYQDe7p717RUWzn5pXmcrjO5F"
+ "5s17NuDmOF+JS6hhY/bz5sbU6KgRRtQBfe/dccvZD6Akdlm4i3zByJT0gmn9Txqs"
+ "CjBTjf9rP8ds+xMcnnlltYhYqwpDtVczWRKoqlR/lWg="
+ "-----END DSA PARAMETERS-----");
+
+ config.set("dl", "dsa/jce/1024",
+ "-----BEGIN DSA PARAMETERS-----"
+ "MIIBHgKBgQD9f1OBHXUSKVLfSpwu7OTn9hG3UjzvRADDHj+AtlEmaUVdQCJR+1k9"
+ "jVj6v8X1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8iLjTI60LlIob8hA6lJl5tu0W+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);
+ }
+
+}