aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pbkdf/pbkdf.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-10-24 12:37:35 -0400
committerJack Lloyd <[email protected]>2016-10-24 12:37:35 -0400
commitc7e76399055c792b84071f22c490906576bd4027 (patch)
tree1e70ece726c42755573b876eae9b060337ef0e80 /src/lib/pbkdf/pbkdf.cpp
parentde54f69aa74d98664fb13b0097f61e17322bca04 (diff)
parent331f7d28de21170e74febae53a7f49732ad40256 (diff)
Merge GH #668: Remove Algo_Registry and associated global locks
Diffstat (limited to 'src/lib/pbkdf/pbkdf.cpp')
-rw-r--r--src/lib/pbkdf/pbkdf.cpp44
1 files changed, 31 insertions, 13 deletions
diff --git a/src/lib/pbkdf/pbkdf.cpp b/src/lib/pbkdf/pbkdf.cpp
index 01f52853a..a3485654b 100644
--- a/src/lib/pbkdf/pbkdf.cpp
+++ b/src/lib/pbkdf/pbkdf.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/pbkdf.h>
-#include <botan/internal/algo_registry.h>
+#include <botan/scan_name.h>
#if defined(BOTAN_HAS_PBKDF1)
#include <botan/pbkdf1.h>
@@ -18,28 +18,46 @@
namespace Botan {
-#define BOTAN_REGISTER_PBKDF_1HASH(type, name) \
- BOTAN_REGISTER_NAMED_T(PBKDF, name, type, (make_new_T_1X<type, HashFunction>))
+PBKDF::~PBKDF() {}
-#if defined(BOTAN_HAS_PBKDF1)
-BOTAN_REGISTER_PBKDF_1HASH(PKCS5_PBKDF1, "PBKDF1");
-#endif
+std::unique_ptr<PBKDF> PBKDF::create(const std::string& algo_spec,
+ const std::string& provider)
+ {
+ const SCAN_Name req(algo_spec);
#if defined(BOTAN_HAS_PBKDF2)
-BOTAN_REGISTER_NAMED_T(PBKDF, "PBKDF2", PKCS5_PBKDF2, PKCS5_PBKDF2::make);
+ if(req.algo_name() == "PBKDF2")
+ {
+ // TODO OpenSSL
+
+ if(provider.empty() || provider == "base")
+ {
+ if(auto mac = MessageAuthenticationCode::create(req.arg(0)))
+ return std::unique_ptr<PBKDF>(new PKCS5_PBKDF2(mac.release()));
+
+ if(auto mac = MessageAuthenticationCode::create("HMAC(" + req.arg(0) + ")"))
+ return std::unique_ptr<PBKDF>(new PKCS5_PBKDF2(mac.release()));
+ }
+
+ return nullptr;
+ }
#endif
-PBKDF::~PBKDF() {}
+#if defined(BOTAN_HAS_PBKDF1)
+ if(req.algo_name() == "PBKDF1" && req.arg_count() == 1)
+ {
+ if(auto hash = HashFunction::create(req.arg(0)))
+ return std::unique_ptr<PBKDF>(new PKCS5_PBKDF1(hash.release()));
-std::unique_ptr<PBKDF> PBKDF::create(const std::string& algo_spec,
- const std::string& provider)
- {
- return std::unique_ptr<PBKDF>(make_a<PBKDF>(Botan::PBKDF::Spec(algo_spec), provider));
+ }
+#endif
+
+ return nullptr;
}
std::vector<std::string> PBKDF::providers(const std::string& algo_spec)
{
- return providers_of<PBKDF>(PBKDF::Spec(algo_spec));
+ return probe_providers_of<PBKDF>(algo_spec, { "base", "openssl" });
}
void PBKDF::pbkdf_timed(byte out[], size_t out_len,