aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pbkdf
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/pbkdf')
-rw-r--r--src/lib/pbkdf/pbkdf.cpp44
-rw-r--r--src/lib/pbkdf/pbkdf.h4
-rw-r--r--src/lib/pbkdf/pbkdf2/pbkdf2.cpp11
-rw-r--r--src/lib/pbkdf/pbkdf2/pbkdf2.h2
4 files changed, 31 insertions, 30 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,
diff --git a/src/lib/pbkdf/pbkdf.h b/src/lib/pbkdf/pbkdf.h
index 63a8a82f0..3abac0896 100644
--- a/src/lib/pbkdf/pbkdf.h
+++ b/src/lib/pbkdf/pbkdf.h
@@ -9,8 +9,6 @@
#define BOTAN_PBKDF_H__
#include <botan/symkey.h>
-#include <botan/scan_name.h>
-#include <botan/scan_name.h>
#include <botan/exceptn.h>
#include <chrono>
@@ -39,8 +37,6 @@ class BOTAN_DLL PBKDF
*/
static std::vector<std::string> providers(const std::string& algo_spec);
- typedef SCAN_Name Spec;
-
/**
* @return new instance of this same algorithm
*/
diff --git a/src/lib/pbkdf/pbkdf2/pbkdf2.cpp b/src/lib/pbkdf/pbkdf2/pbkdf2.cpp
index 5a8f529c6..0041fd537 100644
--- a/src/lib/pbkdf/pbkdf2/pbkdf2.cpp
+++ b/src/lib/pbkdf/pbkdf2/pbkdf2.cpp
@@ -11,17 +11,6 @@
namespace Botan {
-PKCS5_PBKDF2* PKCS5_PBKDF2::make(const Spec& spec)
- {
- if(auto mac = MessageAuthenticationCode::create(spec.arg(0)))
- return new PKCS5_PBKDF2(mac.release());
-
- if(auto mac = MessageAuthenticationCode::create("HMAC(" + spec.arg(0) + ")"))
- return new PKCS5_PBKDF2(mac.release());
-
- return nullptr;
- }
-
size_t
pbkdf2(MessageAuthenticationCode& prf,
byte out[],
diff --git a/src/lib/pbkdf/pbkdf2/pbkdf2.h b/src/lib/pbkdf/pbkdf2/pbkdf2.h
index 4f77f338b..36a3c640a 100644
--- a/src/lib/pbkdf/pbkdf2/pbkdf2.h
+++ b/src/lib/pbkdf/pbkdf2/pbkdf2.h
@@ -49,8 +49,6 @@ class BOTAN_DLL PKCS5_PBKDF2 final : public PBKDF
* @param mac_fn the MAC object to use as PRF
*/
explicit PKCS5_PBKDF2(MessageAuthenticationCode* mac_fn) : m_mac(mac_fn) {}
-
- static PKCS5_PBKDF2* make(const Spec& spec);
private:
std::unique_ptr<MessageAuthenticationCode> m_mac;
};