aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-28 21:27:57 +0000
committerlloyd <[email protected]>2008-09-28 21:27:57 +0000
commit0e0fb8fd1f0aa2906b7452ae011a2ebe2ad35389 (patch)
tree1f4e5504e3f965158225ae2f4d181aa0ca527701 /src
parent9ebc60c266c37722e83ca7482f1516fc3e8bf6d3 (diff)
Modularize PBEs (password-based encryption schemes)
Diffstat (limited to 'src')
-rw-r--r--src/get_pbe.cpp25
-rw-r--r--src/pbe/pbes1/pbes1.cpp (renamed from src/pbes1.cpp)0
-rw-r--r--src/pbe/pbes1/pbes1.h42
-rw-r--r--src/pbe/pbes2/pbes2.cpp (renamed from src/pbes2.cpp)0
4 files changed, 64 insertions, 3 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/src/pbe/pbes1/pbes1.h b/src/pbe/pbes1/pbes1.h
new file mode 100644
index 000000000..89d611b4e
--- /dev/null
+++ b/src/pbe/pbes1/pbes1.h
@@ -0,0 +1,42 @@
+/*************************************************
+* PKCS #5 v1.5 PBE Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_PBE_PKCS_V15_H__
+#define BOTAN_PBE_PKCS_V15_H__
+
+#include <botan/pbe.h>
+#include <botan/pipe.h>
+#include <botan/enums.h>
+
+namespace Botan {
+
+/*************************************************
+* PKCS#5 v1.5 PBE *
+*************************************************/
+class BOTAN_DLL PBE_PKCS5v15 : public PBE
+ {
+ public:
+ void write(const byte[], u32bit);
+ void start_msg();
+ void end_msg();
+ PBE_PKCS5v15(const std::string&, const std::string&, Cipher_Dir);
+ 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);
+ const Cipher_Dir direction;
+ const std::string digest, cipher;
+ SecureVector<byte> salt, key, iv;
+ u32bit iterations;
+ 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