diff options
author | lloyd <[email protected]> | 2008-09-28 21:27:57 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-28 21:27:57 +0000 |
commit | 0e0fb8fd1f0aa2906b7452ae011a2ebe2ad35389 (patch) | |
tree | 1f4e5504e3f965158225ae2f4d181aa0ca527701 | |
parent | 9ebc60c266c37722e83ca7482f1516fc3e8bf6d3 (diff) |
Modularize PBEs (password-based encryption schemes)
-rw-r--r-- | src/get_pbe.cpp | 25 | ||||
-rw-r--r-- | src/pbe/pbes1/pbes1.cpp (renamed from src/pbes1.cpp) | 0 | ||||
-rw-r--r-- | src/pbe/pbes1/pbes1.h (renamed from include/pbe_pkcs.h) | 34 | ||||
-rw-r--r-- | src/pbe/pbes2/pbes2.cpp (renamed from src/pbes2.cpp) | 0 |
4 files changed, 25 insertions, 34 deletions
diff --git a/src/get_pbe.cpp b/src/get_pbe.cpp index aef7756fb..0839d4d98 100644 --- a/src/get_pbe.cpp +++ b/src/get_pbe.cpp @@ -3,11 +3,19 @@ * (C) 1999-2007 Jack Lloyd * *************************************************/ +#include <botan/pbe.h> #include <botan/oids.h> #include <botan/lookup.h> -#include <botan/pbe_pkcs.h> #include <botan/parsing.h> +#if defined(BOTAN_HAS_PBE_PKCS_V15) + #include <botan/pbes1.h> +#endif + +#if defined(BOTAN_HAS_PBE_PKCS_V20) + #include <botan/pbes2.h> +#endif + namespace Botan { /************************************************* @@ -27,10 +35,15 @@ PBE* get_pbe(const std::string& pbe_name) PBE* pbe_obj = 0; - if(pbe == "PBE-PKCS5v15") +#if defined(BOTAN_HAS_PBE_PKCS_V15) + if(!pbe_obj && pbe == "PBE-PKCS5v15") pbe_obj = new PBE_PKCS5v15(digest, cipher, ENCRYPTION); - else if(pbe == "PBE-PKCS5v20") +#endif + +#if defined(BOTAN_HAS_PBE_PKCS_V20) + if(!pbe_obj && pbe == "PBE-PKCS5v20") pbe_obj = new PBE_PKCS5v20(digest, cipher); +#endif if(!pbe_obj) throw Algorithm_Not_Found(pbe_name); @@ -52,6 +65,7 @@ PBE* get_pbe(const OID& pbe_oid, DataSource& params) if(pbe_algo == "PBE-PKCS5v15") { +#if defined(BOTAN_HAS_PBE_PKCS_V15) if(algo_name.size() != 3) throw Invalid_Algorithm_Name(pbe_oid.as_string()); const std::string digest = algo_name[1]; @@ -59,9 +73,14 @@ PBE* get_pbe(const OID& pbe_oid, DataSource& params) PBE* pbe = new PBE_PKCS5v15(digest, cipher, DECRYPTION); pbe->decode_params(params); return pbe; +#endif } else if(pbe_algo == "PBE-PKCS5v20") + { +#if defined(BOTAN_HAS_PBE_PKCS_V20) return new PBE_PKCS5v20(params); +#endif + } throw Algorithm_Not_Found(pbe_oid.as_string()); } diff --git a/src/pbes1.cpp b/src/pbe/pbes1/pbes1.cpp index 84b34eed6..84b34eed6 100644 --- a/src/pbes1.cpp +++ b/src/pbe/pbes1/pbes1.cpp diff --git a/include/pbe_pkcs.h b/src/pbe/pbes1/pbes1.h index 82f797b7b..89d611b4e 100644 --- a/include/pbe_pkcs.h +++ b/src/pbe/pbes1/pbes1.h @@ -1,10 +1,10 @@ /************************************************* -* PKCS PBE Header File * +* PKCS #5 v1.5 PBE Header File * * (C) 1999-2007 Jack Lloyd * *************************************************/ -#ifndef BOTAN_PBE_PKCS_H__ -#define BOTAN_PBE_PKCS_H__ +#ifndef BOTAN_PBE_PKCS_V15_H__ +#define BOTAN_PBE_PKCS_V15_H__ #include <botan/pbe.h> #include <botan/pipe.h> @@ -37,34 +37,6 @@ class BOTAN_DLL PBE_PKCS5v15 : public PBE Pipe pipe; }; -/************************************************* -* PKCS#5 v2.0 PBE * -*************************************************/ -class BOTAN_DLL PBE_PKCS5v20 : public PBE - { - public: - void write(const byte[], u32bit); - void start_msg(); - void end_msg(); - PBE_PKCS5v20(DataSource&); - PBE_PKCS5v20(const std::string&, const std::string&); - private: - void set_key(const std::string&); - void new_params(RandomNumberGenerator& rng); - MemoryVector<byte> encode_params() const; - void decode_params(DataSource&); - OID get_oid() const; - - void flush_pipe(bool); - bool known_cipher(const std::string&) const; - - const Cipher_Dir direction; - std::string digest, cipher, cipher_algo; - SecureVector<byte> salt, key, iv; - u32bit iterations, key_length; - Pipe pipe; - }; - } #endif diff --git a/src/pbes2.cpp b/src/pbe/pbes2/pbes2.cpp index d3533f14f..d3533f14f 100644 --- a/src/pbes2.cpp +++ b/src/pbe/pbes2/pbes2.cpp |