aboutsummaryrefslogtreecommitdiffstats
path: root/src/algo_factory
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-11-04 02:13:29 +0000
committerlloyd <[email protected]>2010-11-04 02:13:29 +0000
commit20191a0e123d0098375be099fcce22f6a6415402 (patch)
treefc17c42295acee6bf168c3f61ca2470f7d1aa0a0 /src/algo_factory
parent51e9d52e4fcfcf486ee53af1a42c98e841bcfde0 (diff)
Move PBKDF lookups to engine
Diffstat (limited to 'src/algo_factory')
-rw-r--r--src/algo_factory/algo_factory.cpp47
-rw-r--r--src/algo_factory/algo_factory.h24
2 files changed, 71 insertions, 0 deletions
diff --git a/src/algo_factory/algo_factory.cpp b/src/algo_factory/algo_factory.cpp
index ba4a435d7..3d640ab8a 100644
--- a/src/algo_factory/algo_factory.cpp
+++ b/src/algo_factory/algo_factory.cpp
@@ -15,6 +15,7 @@
#include <botan/stream_cipher.h>
#include <botan/hash.h>
#include <botan/mac.h>
+#include <botan/pbkdf.h>
#include <algorithm>
@@ -55,6 +56,12 @@ MessageAuthenticationCode* engine_get_algo(Engine* engine,
Algorithm_Factory& af)
{ return engine->find_mac(request, af); }
+template<>
+PBKDF* engine_get_algo(Engine* engine,
+ const SCAN_Name& request,
+ Algorithm_Factory& af)
+ { return engine->find_pbkdf(request, af); }
+
template<typename T>
const T* factory_prototype(const std::string& algo_spec,
const std::string& provider,
@@ -93,6 +100,7 @@ Algorithm_Factory::Algorithm_Factory(Mutex_Factory& mf)
stream_cipher_cache = new Algorithm_Cache<StreamCipher>(mf.make());
hash_cache = new Algorithm_Cache<HashFunction>(mf.make());
mac_cache = new Algorithm_Cache<MessageAuthenticationCode>(mf.make());
+ pbkdf_cache = new Algorithm_Cache<PBKDF>(mf.make());
}
/*
@@ -104,6 +112,7 @@ Algorithm_Factory::~Algorithm_Factory()
delete stream_cipher_cache;
delete hash_cache;
delete mac_cache;
+ delete pbkdf_cache;
std::for_each(engines.begin(), engines.end(), del_fun<Engine>());
}
@@ -114,6 +123,7 @@ void Algorithm_Factory::clear_caches()
stream_cipher_cache->clear_cache();
hash_cache->clear_cache();
mac_cache->clear_cache();
+ pbkdf_cache->clear_cache();
}
void Algorithm_Factory::add_engine(Engine* engine)
@@ -136,6 +146,8 @@ void Algorithm_Factory::set_preferred_provider(const std::string& algo_spec,
hash_cache->set_preferred_provider(algo_spec, provider);
else if(prototype_mac(algo_spec))
mac_cache->set_preferred_provider(algo_spec, provider);
+ else if(prototype_pbkdf(algo_spec))
+ pbkdf_cache->set_preferred_provider(algo_spec, provider);
}
/*
@@ -168,6 +180,8 @@ Algorithm_Factory::providers_of(const std::string& algo_spec)
return hash_cache->providers_of(algo_spec);
else if(prototype_mac(algo_spec))
return mac_cache->providers_of(algo_spec);
+ else if(prototype_pbkdf(algo_spec))
+ return pbkdf_cache->providers_of(algo_spec);
else
return std::vector<std::string>();
}
@@ -218,6 +232,18 @@ Algorithm_Factory::prototype_mac(const std::string& algo_spec,
}
/*
+* Return the prototypical object corresponding to this request
+*/
+const PBKDF*
+Algorithm_Factory::prototype_pbkdf(const std::string& algo_spec,
+ const std::string& provider)
+ {
+ return factory_prototype<PBKDF>(algo_spec, provider,
+ engines,
+ *this, pbkdf_cache);
+ }
+
+/*
* Return a new block cipher corresponding to this request
*/
BlockCipher*
@@ -266,6 +292,18 @@ Algorithm_Factory::make_mac(const std::string& algo_spec,
}
/*
+* Return a new object corresponding to this request
+*/
+PBKDF*
+Algorithm_Factory::make_pbkdf(const std::string& algo_spec,
+ const std::string& provider)
+ {
+ if(const PBKDF* proto = prototype_pbkdf(algo_spec, provider))
+ return proto->clone();
+ throw Algorithm_Not_Found(algo_spec);
+ }
+
+/*
* Add a new block cipher
*/
void Algorithm_Factory::add_block_cipher(BlockCipher* block_cipher,
@@ -301,4 +339,13 @@ void Algorithm_Factory::add_mac(MessageAuthenticationCode* mac,
mac_cache->add(mac, mac->name(), provider);
}
+/*
+* Add a new PBKDF
+*/
+void Algorithm_Factory::add_pbkdf(PBKDF* pbkdf,
+ const std::string& provider)
+ {
+ pbkdf_cache->add(pbkdf, pbkdf->name(), provider);
+ }
+
}
diff --git a/src/algo_factory/algo_factory.h b/src/algo_factory/algo_factory.h
index 10549d5d3..b9f15757d 100644
--- a/src/algo_factory/algo_factory.h
+++ b/src/algo_factory/algo_factory.h
@@ -21,6 +21,7 @@ class BlockCipher;
class StreamCipher;
class HashFunction;
class MessageAuthenticationCode;
+class PBKDF;
template<typename T> class Algorithm_Cache;
@@ -161,6 +162,28 @@ class BOTAN_DLL Algorithm_Factory
const std::string& provider);
/**
+ * @param algo_spec the algorithm we want
+ * @param provider the provider we would like to use
+ * @returns pointer to const prototype object, ready to clone(), or NULL
+ */
+ const PBKDF* prototype_pbkdf(const std::string& algo_spec,
+ const std::string& provider = "");
+
+ /**
+ * @param algo_spec the algorithm we want
+ * @param provider the provider we would like to use
+ * @returns pointer to freshly created instance of the request algorithm
+ */
+ PBKDF* make_pbkdf(const std::string& algo_spec,
+ const std::string& provider = "");
+
+ /**
+ * @param algo the algorithm to add
+ * @param provider the provider of this algorithm
+ */
+ void add_pbkdf(PBKDF* algo, const std::string& provider);
+
+ /**
* An iterator for the engines in this factory
* @deprecated Avoid in new code
*/
@@ -196,6 +219,7 @@ class BOTAN_DLL Algorithm_Factory
Algorithm_Cache<StreamCipher>* stream_cipher_cache;
Algorithm_Cache<HashFunction>* hash_cache;
Algorithm_Cache<MessageAuthenticationCode>* mac_cache;
+ Algorithm_Cache<PBKDF>* pbkdf_cache;
};
}