diff options
author | lloyd <[email protected]> | 2013-12-25 23:58:19 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2013-12-25 23:58:19 +0000 |
commit | dd30b21bc05abaee34d7ca6600bbdfc4456edbd1 (patch) | |
tree | dd7d8ea78755bca6830186858d4ade2294a7f943 /src | |
parent | 63ba27496318bb92f620a09ca69d40b1d617e927 (diff) |
Split up libstate/get_enc.cpp
Diffstat (limited to 'src')
-rw-r--r-- | src/kdf/kdf.cpp | 81 | ||||
-rw-r--r-- | src/kdf/kdf.h | 7 | ||||
-rw-r--r-- | src/libstate/lookup.cpp | 13 | ||||
-rw-r--r-- | src/libstate/lookup.h | 28 | ||||
-rw-r--r-- | src/pk_pad/eme.h | 7 | ||||
-rw-r--r-- | src/pk_pad/emsa.h | 8 | ||||
-rw-r--r-- | src/pk_pad/get_pk_pad.cpp (renamed from src/libstate/get_enc.cpp) | 92 |
7 files changed, 119 insertions, 117 deletions
diff --git a/src/kdf/kdf.cpp b/src/kdf/kdf.cpp new file mode 100644 index 000000000..84a0cdd15 --- /dev/null +++ b/src/kdf/kdf.cpp @@ -0,0 +1,81 @@ +/* +* KDF Retrieval +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include <botan/lookup.h> +#include <botan/libstate.h> +#include <botan/scan_name.h> + +#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 { + +KDF* get_kdf(const std::string& algo_spec) + { + SCAN_Name request(algo_spec); + + Algorithm_Factory& af = global_state().algorithm_factory(); + + if(request.algo_name() == "Raw") + return nullptr; // No KDF + +#if defined(BOTAN_HAS_KDF1) + if(request.algo_name() == "KDF1" && request.arg_count() == 1) + return new KDF1(af.make_hash_function(request.arg(0))); +#endif + +#if defined(BOTAN_HAS_KDF2) + if(request.algo_name() == "KDF2" && request.arg_count() == 1) + return new KDF2(af.make_hash_function(request.arg(0))); +#endif + +#if defined(BOTAN_HAS_X942_PRF) + if(request.algo_name() == "X9.42-PRF" && request.arg_count() == 1) + return new X942_PRF(request.arg(0)); // OID +#endif + +#if defined(BOTAN_HAS_SSL_V3_PRF) + if(request.algo_name() == "SSL3-PRF" && request.arg_count() == 0) + return new SSL3_PRF; +#endif + +#if defined(BOTAN_HAS_TLS_V10_PRF) + if(request.algo_name() == "TLS-PRF" && request.arg_count() == 0) + return new TLS_PRF; +#endif + +#if defined(BOTAN_HAS_TLS_V10_PRF) + if(request.algo_name() == "TLS-PRF" && request.arg_count() == 0) + return new TLS_PRF; +#endif + +#if defined(BOTAN_HAS_TLS_V12_PRF) + if(request.algo_name() == "TLS-12-PRF" && request.arg_count() == 1) + return new TLS_12_PRF(af.make_mac("HMAC(" + request.arg(0) + ")")); +#endif + + throw Algorithm_Not_Found(algo_spec); + } + +} diff --git a/src/kdf/kdf.h b/src/kdf/kdf.h index c8aaf5d4a..b0f6e1dc3 100644 --- a/src/kdf/kdf.h +++ b/src/kdf/kdf.h @@ -124,6 +124,13 @@ class BOTAN_DLL MGF virtual ~MGF() {} }; +/** +* Factory method for KDF (key derivation function) +* @param algo_spec the name of the KDF to create +* @return pointer to newly allocated object of that type +*/ +BOTAN_DLL KDF* get_kdf(const std::string& algo_spec); + } #endif diff --git a/src/libstate/lookup.cpp b/src/libstate/lookup.cpp index 24a46e3e9..85f93bb95 100644 --- a/src/libstate/lookup.cpp +++ b/src/libstate/lookup.cpp @@ -12,6 +12,19 @@ namespace Botan { /* +* Get a PBKDF algorithm by name +*/ +PBKDF* get_pbkdf(const std::string& algo_spec) + { + Algorithm_Factory& af = global_state().algorithm_factory(); + + if(PBKDF* pbkdf = af.make_pbkdf(algo_spec)) + return pbkdf; + + throw Algorithm_Not_Found(algo_spec); + } + +/* * Query if an algorithm exists */ bool have_algorithm(const std::string& name) diff --git a/src/libstate/lookup.h b/src/libstate/lookup.h index 7387a3471..e0024c224 100644 --- a/src/libstate/lookup.h +++ b/src/libstate/lookup.h @@ -147,34 +147,6 @@ inline PBKDF* get_s2k(const std::string& algo_spec) } /* -* 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 algo_spec the name of the EME to create -* @return pointer to newly allocated object of that type -*/ -BOTAN_DLL EME* get_eme(const std::string& algo_spec); - -/** -* Factory method for EMSA (message-encoding methods for signatures -* with appendix) objects -* @param algo_spec the name of the EME to create -* @return pointer to newly allocated object of that type -*/ -BOTAN_DLL EMSA* get_emsa(const std::string& algo_spec); - -/** -* Factory method for KDF (key derivation function) -* @param algo_spec the name of the KDF to create -* @return pointer to newly allocated object of that type -*/ -BOTAN_DLL KDF* get_kdf(const std::string& algo_spec); - -/* * Get a cipher object */ diff --git a/src/pk_pad/eme.h b/src/pk_pad/eme.h index 6f8acaa23..358b4f144 100644 --- a/src/pk_pad/eme.h +++ b/src/pk_pad/eme.h @@ -97,6 +97,13 @@ class BOTAN_DLL EME size_t key_length) const = 0; }; +/** +* Factory method for EME (message-encoding methods for encryption) objects +* @param algo_spec the name of the EME to create +* @return pointer to newly allocated object of that type +*/ +BOTAN_DLL EME* get_eme(const std::string& algo_spec); + } #endif diff --git a/src/pk_pad/emsa.h b/src/pk_pad/emsa.h index 821ca782f..5db01ec12 100644 --- a/src/pk_pad/emsa.h +++ b/src/pk_pad/emsa.h @@ -55,6 +55,14 @@ class BOTAN_DLL EMSA virtual ~EMSA() {} }; +/** +* Factory method for EMSA (message-encoding methods for signatures +* with appendix) objects +* @param algo_spec the name of the EME to create +* @return pointer to newly allocated object of that type +*/ +BOTAN_DLL EMSA* get_emsa(const std::string& algo_spec); + } #endif diff --git a/src/libstate/get_enc.cpp b/src/pk_pad/get_pk_pad.cpp index 00297464b..8c27b1fa1 100644 --- a/src/libstate/get_enc.cpp +++ b/src/pk_pad/get_pk_pad.cpp @@ -1,18 +1,15 @@ /* -* PBKDF/EMSA/EME/KDF/MGF Retrieval +* EMSA/EME Retrieval * (C) 1999-2007 Jack Lloyd * * Distributed under the terms of the Botan license */ -#include <botan/lookup.h> +#include <botan/emsa.h> +#include <botan/eme.h> #include <botan/libstate.h> #include <botan/scan_name.h> -#if defined(BOTAN_HAS_MGF1) - #include <botan/mgf1.h> -#endif - #if defined(BOTAN_HAS_EMSA1) #include <botan/emsa1.h> #endif @@ -45,42 +42,9 @@ #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 a PBKDF algorithm by name -*/ -PBKDF* get_pbkdf(const std::string& algo_spec) - { - Algorithm_Factory& af = global_state().algorithm_factory(); - - if(PBKDF* pbkdf = af.make_pbkdf(algo_spec)) - return pbkdf; - - throw Algorithm_Not_Found(algo_spec); - } - -/* * Get an EMSA by name */ EMSA* get_emsa(const std::string& algo_spec) @@ -172,54 +136,4 @@ EME* get_eme(const std::string& algo_spec) throw Algorithm_Not_Found(algo_spec); } -/* -* Get an KDF by name -*/ -KDF* get_kdf(const std::string& algo_spec) - { - SCAN_Name request(algo_spec); - - Algorithm_Factory& af = global_state().algorithm_factory(); - - if(request.algo_name() == "Raw") - return nullptr; // No KDF - -#if defined(BOTAN_HAS_KDF1) - if(request.algo_name() == "KDF1" && request.arg_count() == 1) - return new KDF1(af.make_hash_function(request.arg(0))); -#endif - -#if defined(BOTAN_HAS_KDF2) - if(request.algo_name() == "KDF2" && request.arg_count() == 1) - return new KDF2(af.make_hash_function(request.arg(0))); -#endif - -#if defined(BOTAN_HAS_X942_PRF) - if(request.algo_name() == "X9.42-PRF" && request.arg_count() == 1) - return new X942_PRF(request.arg(0)); // OID -#endif - -#if defined(BOTAN_HAS_SSL_V3_PRF) - if(request.algo_name() == "SSL3-PRF" && request.arg_count() == 0) - return new SSL3_PRF; -#endif - -#if defined(BOTAN_HAS_TLS_V10_PRF) - if(request.algo_name() == "TLS-PRF" && request.arg_count() == 0) - return new TLS_PRF; -#endif - -#if defined(BOTAN_HAS_TLS_V10_PRF) - if(request.algo_name() == "TLS-PRF" && request.arg_count() == 0) - return new TLS_PRF; -#endif - -#if defined(BOTAN_HAS_TLS_V12_PRF) - if(request.algo_name() == "TLS-12-PRF" && request.arg_count() == 1) - return new TLS_12_PRF(af.make_mac("HMAC(" + request.arg(0) + ")")); -#endif - - throw Algorithm_Not_Found(algo_spec); - } - } |