aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/kdf
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/kdf')
-rw-r--r--src/lib/kdf/hkdf/hkdf.cpp2
-rw-r--r--src/lib/kdf/info.txt4
-rw-r--r--src/lib/kdf/kdf.cpp28
-rw-r--r--src/lib/kdf/kdf.h13
-rw-r--r--src/lib/kdf/kdf1/kdf1.cpp1
-rw-r--r--src/lib/kdf/kdf2/kdf2.cpp1
-rw-r--r--src/lib/kdf/kdf_utils.h28
-rw-r--r--src/lib/kdf/prf_tls/prf_tls.cpp3
-rw-r--r--src/lib/kdf/prf_x942/prf_x942.cpp2
9 files changed, 41 insertions, 41 deletions
diff --git a/src/lib/kdf/hkdf/hkdf.cpp b/src/lib/kdf/hkdf/hkdf.cpp
index df6e49fad..d4c688afc 100644
--- a/src/lib/kdf/hkdf/hkdf.cpp
+++ b/src/lib/kdf/hkdf/hkdf.cpp
@@ -5,8 +5,8 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/kdf_utils.h>
#include <botan/hkdf.h>
+#include <botan/lookup.h>
namespace Botan {
diff --git a/src/lib/kdf/info.txt b/src/lib/kdf/info.txt
index 35032e159..68aa46895 100644
--- a/src/lib/kdf/info.txt
+++ b/src/lib/kdf/info.txt
@@ -7,7 +7,3 @@ base
<header:public>
kdf.h
</header:public>
-
-<header:internal>
-kdf_utils.h
-</header:internal>
diff --git a/src/lib/kdf/kdf.cpp b/src/lib/kdf/kdf.cpp
index 836e9b982..3eba8a5cd 100644
--- a/src/lib/kdf/kdf.cpp
+++ b/src/lib/kdf/kdf.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/kdf.h>
-#include <botan/internal/kdf_utils.h>
+#include <botan/internal/algo_registry.h>
#if defined(BOTAN_HAS_HKDF)
#include <botan/hkdf.h>
@@ -32,10 +32,29 @@
#include <botan/prf_x942.h>
#endif
+#define BOTAN_REGISTER_KDF_NOARGS(type, name) \
+ BOTAN_REGISTER_NAMED_T(KDF, name, type, (make_new_T<type>))
+#define BOTAN_REGISTER_KDF_1HASH(type, name) \
+ BOTAN_REGISTER_NAMED_T(KDF, name, type, (make_new_T_1X<type, HashFunction>))
+
+#define BOTAN_REGISTER_KDF_NAMED_1STR(type, name) \
+ BOTAN_REGISTER_NAMED_T(KDF, name, type, (make_new_T_1str_req<type>))
+
namespace Botan {
KDF::~KDF() {}
+std::unique_ptr<KDF> KDF::create(const std::string& algo_spec,
+ const std::string& provider)
+ {
+ return std::unique_ptr<KDF>(make_a<KDF>(algo_spec, provider));
+ }
+
+std::vector<std::string> KDF::providers(const std::string& algo_spec)
+ {
+ return providers_of<KDF>(KDF::Spec(algo_spec));
+ }
+
KDF* get_kdf(const std::string& algo_spec)
{
SCAN_Name request(algo_spec);
@@ -43,9 +62,10 @@ KDF* get_kdf(const std::string& algo_spec)
if(request.algo_name() == "Raw")
return nullptr; // No KDF
- if(KDF* kdf = make_a<KDF>(algo_spec))
- return kdf;
- throw Algorithm_Not_Found(algo_spec);
+ auto kdf = KDF::create(algo_spec);
+ if(!kdf)
+ throw Algorithm_Not_Found(algo_spec);
+ return kdf.release();
}
#if defined(BOTAN_HAS_HKDF)
diff --git a/src/lib/kdf/kdf.h b/src/lib/kdf/kdf.h
index 936e7c5f1..a8d4650e0 100644
--- a/src/lib/kdf/kdf.h
+++ b/src/lib/kdf/kdf.h
@@ -23,6 +23,19 @@ class BOTAN_DLL KDF
public:
virtual ~KDF();
+ /**
+ * Create an instance based on a name
+ * Will return a null pointer if the algo/provider combination cannot
+ * be found. If providers is empty then best available is chosen.
+ */
+ static std::unique_ptr<KDF> create(const std::string& algo_spec,
+ const std::string& provider = "");
+
+ /**
+ * Returns the list of available providers for this algorithm, empty if not available
+ */
+ static std::vector<std::string> providers(const std::string& algo_spec);
+
virtual std::string name() const = 0;
virtual size_t kdf(byte key[], size_t key_len,
diff --git a/src/lib/kdf/kdf1/kdf1.cpp b/src/lib/kdf/kdf1/kdf1.cpp
index c87bacd27..c7ea3c37e 100644
--- a/src/lib/kdf/kdf1/kdf1.cpp
+++ b/src/lib/kdf/kdf1/kdf1.cpp
@@ -5,7 +5,6 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/kdf_utils.h>
#include <botan/kdf1.h>
namespace Botan {
diff --git a/src/lib/kdf/kdf2/kdf2.cpp b/src/lib/kdf/kdf2/kdf2.cpp
index 1b1c3638a..df2b7a91c 100644
--- a/src/lib/kdf/kdf2/kdf2.cpp
+++ b/src/lib/kdf/kdf2/kdf2.cpp
@@ -5,7 +5,6 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/kdf_utils.h>
#include <botan/kdf2.h>
namespace Botan {
diff --git a/src/lib/kdf/kdf_utils.h b/src/lib/kdf/kdf_utils.h
deleted file mode 100644
index f67892437..000000000
--- a/src/lib/kdf/kdf_utils.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
-* KDF Utility Header
-* (C) 2015 Jack Lloyd
-*
-* Botan is released under the Simplified BSD License (see license.txt)
-*/
-
-#ifndef BOTAN_KDF_UTILS_H__
-#define BOTAN_KDF_UTILS_H__
-
-#include <botan/kdf.h>
-#include <botan/internal/algo_registry.h>
-#include <botan/exceptn.h>
-#include <botan/internal/xor_buf.h>
-
-namespace Botan {
-
-#define BOTAN_REGISTER_KDF_NOARGS(type, name) \
- BOTAN_REGISTER_NAMED_T(KDF, name, type, (make_new_T<type>))
-#define BOTAN_REGISTER_KDF_1HASH(type, name) \
- BOTAN_REGISTER_NAMED_T(KDF, name, type, (make_new_T_1X<type, HashFunction>))
-
-#define BOTAN_REGISTER_KDF_NAMED_1STR(type, name) \
- BOTAN_REGISTER_NAMED_T(KDF, name, type, (make_new_T_1str_req<type>))
-
-}
-
-#endif
diff --git a/src/lib/kdf/prf_tls/prf_tls.cpp b/src/lib/kdf/prf_tls/prf_tls.cpp
index ef130d5ba..08a2a0899 100644
--- a/src/lib/kdf/prf_tls/prf_tls.cpp
+++ b/src/lib/kdf/prf_tls/prf_tls.cpp
@@ -5,9 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/kdf_utils.h>
#include <botan/prf_tls.h>
#include <botan/hmac.h>
+#include <botan/lookup.h>
+#include <botan/internal/xor_buf.h>
namespace Botan {
diff --git a/src/lib/kdf/prf_x942/prf_x942.cpp b/src/lib/kdf/prf_x942/prf_x942.cpp
index e8f234e49..443e207f2 100644
--- a/src/lib/kdf/prf_x942/prf_x942.cpp
+++ b/src/lib/kdf/prf_x942/prf_x942.cpp
@@ -5,12 +5,12 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/kdf_utils.h>
#include <botan/prf_x942.h>
#include <botan/der_enc.h>
#include <botan/oids.h>
#include <botan/hash.h>
#include <botan/loadstor.h>
+#include <botan/lookup.h>
#include <algorithm>
namespace Botan {