diff options
author | lloyd <[email protected]> | 2008-09-28 17:35:11 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-28 17:35:11 +0000 |
commit | 8c085b3c40c30607ca5cac10d04062355fcad187 (patch) | |
tree | 4fe7387db56f4422c997b88f2a92e52f669c2de4 | |
parent | da412e1f1169d4b51bbef84eb2948b73416bd48a (diff) |
Modularize EMSA
-rw-r--r-- | include/emsa.h | 122 | ||||
-rw-r--r-- | modules/pk_pad/emsa1/emsa1.cpp (renamed from src/emsa1.cpp) | 0 | ||||
-rw-r--r-- | modules/pk_pad/emsa2/emsa2.cpp (renamed from src/emsa2.cpp) | 0 | ||||
-rw-r--r-- | modules/pk_pad/emsa3/emsa3.cpp (renamed from src/emsa3.cpp) | 0 | ||||
-rw-r--r-- | modules/pk_pad/emsa4/emsa4.cpp (renamed from src/emsa4.cpp) | 0 | ||||
-rw-r--r-- | modules/pk_pad/emsa_raw/emsa_raw.cpp (renamed from src/emsa_raw.cpp) | 0 | ||||
-rw-r--r-- | src/def_alg.cpp | 24 | ||||
-rw-r--r-- | src/get_enc.cpp | 72 |
8 files changed, 65 insertions, 153 deletions
diff --git a/include/emsa.h b/include/emsa.h deleted file mode 100644 index 44f9210d1..000000000 --- a/include/emsa.h +++ /dev/null @@ -1,122 +0,0 @@ -/************************************************* -* EMSA Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_EMSA_H__ -#define BOTAN_EMSA_H__ - -#include <botan/pk_util.h> - -namespace Botan { - -/************************************************* -* EMSA1 * -*************************************************/ -class BOTAN_DLL EMSA1 : public EMSA - { - public: - EMSA1(const std::string&); - ~EMSA1() { delete hash; } - private: - void update(const byte[], u32bit); - SecureVector<byte> raw_data(); - - SecureVector<byte> encoding_of(const MemoryRegion<byte>&, u32bit, - RandomNumberGenerator& rng); - - bool verify(const MemoryRegion<byte>&, const MemoryRegion<byte>&, - u32bit) throw(); - - HashFunction* hash; - }; - -/************************************************* -* EMSA2 * -*************************************************/ -class BOTAN_DLL EMSA2 : public EMSA - { - public: - EMSA2(const std::string&); - ~EMSA2() { delete hash; } - private: - void update(const byte[], u32bit); - SecureVector<byte> raw_data(); - - SecureVector<byte> encoding_of(const MemoryRegion<byte>&, u32bit, - RandomNumberGenerator& rng); - - bool verify(const MemoryRegion<byte>&, const MemoryRegion<byte>&, - u32bit) throw(); - - SecureVector<byte> empty_hash; - HashFunction* hash; - byte hash_id; - }; - -/************************************************* -* EMSA3 * -*************************************************/ -class BOTAN_DLL EMSA3 : public EMSA - { - public: - EMSA3(const std::string&); - ~EMSA3() { delete hash; } - private: - void update(const byte[], u32bit); - - SecureVector<byte> raw_data(); - - SecureVector<byte> encoding_of(const MemoryRegion<byte>&, u32bit, - RandomNumberGenerator& rng); - - bool verify(const MemoryRegion<byte>&, const MemoryRegion<byte>&, - u32bit) throw(); - - HashFunction* hash; - SecureVector<byte> hash_id; - }; - -/************************************************* -* EMSA4 * -*************************************************/ -class BOTAN_DLL EMSA4 : public EMSA - { - public: - EMSA4(const std::string&, const std::string&); - EMSA4(const std::string&, const std::string&, u32bit); - ~EMSA4() { delete hash; delete mgf; } - private: - void update(const byte[], u32bit); - SecureVector<byte> raw_data(); - - SecureVector<byte> encoding_of(const MemoryRegion<byte>&, u32bit, - RandomNumberGenerator& rng); - bool verify(const MemoryRegion<byte>&, const MemoryRegion<byte>&, - u32bit) throw(); - - const u32bit SALT_SIZE; - HashFunction* hash; - const MGF* mgf; - }; - -/************************************************* -* EMSA-Raw * -*************************************************/ -class BOTAN_DLL EMSA_Raw : public EMSA - { - private: - void update(const byte[], u32bit); - SecureVector<byte> raw_data(); - - SecureVector<byte> encoding_of(const MemoryRegion<byte>&, u32bit, - RandomNumberGenerator&); - bool verify(const MemoryRegion<byte>&, const MemoryRegion<byte>&, - u32bit) throw(); - - SecureVector<byte> message; - }; - -} - -#endif diff --git a/src/emsa1.cpp b/modules/pk_pad/emsa1/emsa1.cpp index 8977356e8..8977356e8 100644 --- a/src/emsa1.cpp +++ b/modules/pk_pad/emsa1/emsa1.cpp diff --git a/src/emsa2.cpp b/modules/pk_pad/emsa2/emsa2.cpp index 825329e7e..825329e7e 100644 --- a/src/emsa2.cpp +++ b/modules/pk_pad/emsa2/emsa2.cpp diff --git a/src/emsa3.cpp b/modules/pk_pad/emsa3/emsa3.cpp index 35a9f6fe3..35a9f6fe3 100644 --- a/src/emsa3.cpp +++ b/modules/pk_pad/emsa3/emsa3.cpp diff --git a/src/emsa4.cpp b/modules/pk_pad/emsa4/emsa4.cpp index 6fb63fe0a..6fb63fe0a 100644 --- a/src/emsa4.cpp +++ b/modules/pk_pad/emsa4/emsa4.cpp diff --git a/src/emsa_raw.cpp b/modules/pk_pad/emsa_raw/emsa_raw.cpp index 037e22375..037e22375 100644 --- a/src/emsa_raw.cpp +++ b/modules/pk_pad/emsa_raw/emsa_raw.cpp diff --git a/src/def_alg.cpp b/src/def_alg.cpp index 64e27d480..6842d36d6 100644 --- a/src/def_alg.cpp +++ b/src/def_alg.cpp @@ -7,6 +7,13 @@ #include <botan/libstate.h> #include <botan/parsing.h> +#include <botan/cmac.h> +#include <botan/hmac.h> +#include <botan/par_hash.h> +#include <botan/mode_pad.h> +#include <botan/pgp_s2k.h> +#include <botan/pkcs5.h> + #ifdef BOTAN_HAS_AES #include <botan/aes.h> #endif @@ -173,11 +180,9 @@ #include <botan/whrlpool.h> #endif -#include <botan/par_hash.h> - -#include <botan/cbc_mac.h> -#include <botan/cmac.h> -#include <botan/hmac.h> +#ifdef BOTAN_HAS_CBC_MAC + #include <botan/cbc_mac.h> +#endif #ifdef BOTAN_HAS_SSL3_MAC #include <botan/ssl3_mac.h> @@ -187,10 +192,6 @@ #include <botan/x919_mac.h> #endif -#include <botan/mode_pad.h> -#include <botan/pgp_s2k.h> -#include <botan/pkcs5.h> - namespace Botan { /************************************************* @@ -456,7 +457,6 @@ Default_Engine::find_hash(const std::string& algo_spec) const HANDLE_TYPE_NO_ARGS("Whirlpool", Whirlpool); #endif - if(algo_name == "Parallel") { if(name.size() < 2) @@ -464,6 +464,7 @@ Default_Engine::find_hash(const std::string& algo_spec) const name.erase(name.begin()); return new Parallel(name); } + return 0; } @@ -478,7 +479,10 @@ Default_Engine::find_mac(const std::string& algo_spec) const return 0; const std::string algo_name = global_state().deref_alias(name[0]); +#ifdef BOTAN_HAS_CBC_MAC HANDLE_TYPE_ONE_STRING("CBC-MAC", CBC_MAC); +#endif + HANDLE_TYPE_ONE_STRING("CMAC", CMAC); HANDLE_TYPE_ONE_STRING("HMAC", HMAC); diff --git a/src/get_enc.cpp b/src/get_enc.cpp index 31c1e06aa..98cba0ad2 100644 --- a/src/get_enc.cpp +++ b/src/get_enc.cpp @@ -6,12 +6,31 @@ #include <botan/lookup.h> #include <botan/libstate.h> #include <botan/parsing.h> -#include <botan/emsa.h> #include <botan/eme.h> #include <botan/kdf.h> #include <botan/mgf1.h> #include <botan/util.h> +#ifdef BOTAN_HAS_EMSA1 + #include <botan/emsa1.h> +#endif + +#ifdef BOTAN_HAS_EMSA2 + #include <botan/emsa2.h> +#endif + +#ifdef BOTAN_HAS_EMSA3 + #include <botan/emsa3.h> +#endif + +#ifdef BOTAN_HAS_EMSA4 + #include <botan/emsa4.h> +#endif + +#ifdef BOTAN_HAS_EMSA_RAW + #include <botan/emsa_raw.h> +#endif + namespace Botan { /************************************************* @@ -22,27 +41,40 @@ 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]); +#ifdef BOTAN_HAS_EMSA_RAW if(emsa_name == "Raw") { if(name.size() == 1) return new EMSA_Raw; } - else if(emsa_name == "EMSA1") +#endif + +#ifdef BOTAN_HAS_EMSA1 + if(emsa_name == "EMSA1") { if(name.size() == 2) return new EMSA1(name[1]); } - else if(emsa_name == "EMSA2") +#endif + +#ifdef BOTAN_HAS_EMSA2 + if(emsa_name == "EMSA2") { if(name.size() == 2) return new EMSA2(name[1]); } - else if(emsa_name == "EMSA3") +#endif + +#ifdef BOTAN_HAS_EMSA3 + if(emsa_name == "EMSA3") { if(name.size() == 2) return new EMSA3(name[1]); } - else if(emsa_name == "EMSA4") +#endif + +#ifdef BOTAN_HAS_EMSA4 + if(emsa_name == "EMSA4") { if(name.size() == 2) return new EMSA4(name[1], "MGF1"); @@ -51,10 +83,9 @@ EMSA* get_emsa(const std::string& algo_spec) if(name.size() == 4) return new EMSA4(name[1], name[2], to_u32bit(name[3])); } - else - throw Algorithm_Not_Found(algo_spec); +#endif - throw Invalid_Algorithm_Name(algo_spec); + throw Algorithm_Not_Found(algo_spec); } /************************************************* @@ -70,17 +101,16 @@ EME* get_eme(const std::string& algo_spec) if(name.size() == 1) return new EME_PKCS1v15; } - else if(eme_name == "EME1") + + if(eme_name == "EME1") { if(name.size() == 2) return new EME1(name[1], "MGF1"); if(name.size() == 3) return new EME1(name[1], name[2]); } - else - throw Algorithm_Not_Found(algo_spec); - throw Invalid_Algorithm_Name(algo_spec); + throw Algorithm_Not_Found(algo_spec); } /************************************************* @@ -96,30 +126,32 @@ KDF* get_kdf(const std::string& algo_spec) if(name.size() == 2) return new KDF1(name[1]); } - else if(kdf_name == "KDF2") + + if(kdf_name == "KDF2") { if(name.size() == 2) return new KDF2(name[1]); } - else if(kdf_name == "X9.42-PRF") + + if(kdf_name == "X9.42-PRF") { if(name.size() == 2) return new X942_PRF(name[1]); } + if(kdf_name == "TLS-PRF") { if(name.size() == 1) return new TLS_PRF; } - else if(kdf_name == "SSL3-PRF") + + if(kdf_name == "SSL3-PRF") { if(name.size() == 1) return new SSL3_PRF; } - else - throw Algorithm_Not_Found(algo_spec); - throw Invalid_Algorithm_Name(algo_spec); + throw Algorithm_Not_Found(algo_spec); } /************************************************* @@ -135,10 +167,8 @@ MGF* get_mgf(const std::string& algo_spec) if(name.size() == 2) return new MGF1(get_hash(name[1])); } - else - throw Algorithm_Not_Found(algo_spec); - throw Invalid_Algorithm_Name(algo_spec); + throw Algorithm_Not_Found(algo_spec); } } |