diff options
author | lloyd <[email protected]> | 2008-11-08 18:05:43 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-11-08 18:05:43 +0000 |
commit | c57058b459d7a7422d60ef0cd6d8dc899d21400e (patch) | |
tree | 27255f243cb357a19bbf83d5e1b69824b4385489 /src/libstate | |
parent | 39362b98af2bb84e7a436b9c1ff59a7bf023157f (diff) |
Split def_alg.cpp into lookup_{cipher,hash,misc}.cpp
Diffstat (limited to 'src/libstate')
-rw-r--r-- | src/libstate/info.txt | 4 | ||||
-rw-r--r-- | src/libstate/lookup_cipher.cpp (renamed from src/libstate/def_alg.cpp) | 308 | ||||
-rw-r--r-- | src/libstate/lookup_hash.cpp | 211 | ||||
-rw-r--r-- | src/libstate/lookup_misc.cpp | 179 |
4 files changed, 394 insertions, 308 deletions
diff --git a/src/libstate/info.txt b/src/libstate/info.txt index a5c0a1c8a..8e4168ebb 100644 --- a/src/libstate/info.txt +++ b/src/libstate/info.txt @@ -10,7 +10,9 @@ s2k </requires> <add> -def_alg.cpp +lookup_cipher.cpp +lookup_hash.cpp +lookup_misc.cpp def_mode.cpp def_powm.cpp eng_base.cpp diff --git a/src/libstate/def_alg.cpp b/src/libstate/lookup_cipher.cpp index 3c3cc5f7a..ac66c1c40 100644 --- a/src/libstate/def_alg.cpp +++ b/src/libstate/lookup_cipher.cpp @@ -1,5 +1,5 @@ /************************************************* -* Default Engine Algorithms Source File * +* Cipher Lookup * * (C) 1999-2007 Jack Lloyd * *************************************************/ @@ -127,119 +127,6 @@ #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 { /************************************************* @@ -442,199 +329,6 @@ Default_Engine::find_stream_cipher(const std::string& algo_spec) const /************************************************* * 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) - if(algo_name == "OpenPGP-S2K") - { - if(name.size() == 2) - return new OpenPGP_S2K(get_hash(name[1])); - throw Invalid_Algorithm_Name(algo_spec); - } -#endif - - return 0; - } - -/************************************************* -* Look for an algorithm with this name * -*************************************************/ BlockCipherModePaddingMethod* Default_Engine::find_bc_pad(const std::string& algo_spec) const { diff --git a/src/libstate/lookup_hash.cpp b/src/libstate/lookup_hash.cpp new file mode 100644 index 000000000..14ca5a859 --- /dev/null +++ b/src/libstate/lookup_hash.cpp @@ -0,0 +1,211 @@ +/************************************************* +* Hash Algorithms Lookup * +* (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_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 + +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_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); \ + } + +/************************************************* +* 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; + } + +} diff --git a/src/libstate/lookup_misc.cpp b/src/libstate/lookup_misc.cpp new file mode 100644 index 000000000..22bfdd918 --- /dev/null +++ b/src/libstate/lookup_misc.cpp @@ -0,0 +1,179 @@ +/************************************************* +* MAC/PBKDF/Other Algorithms Lookup * +* (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_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); \ + } + +/************************************************* +* 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) + if(algo_name == "OpenPGP-S2K") + { + if(name.size() == 2) + return new OpenPGP_S2K(get_hash(name[1])); + throw Invalid_Algorithm_Name(algo_spec); + } +#endif + + return 0; + } + +} |