aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/kdf/prf_tls
diff options
context:
space:
mode:
authorlloyd <[email protected]>2015-01-31 16:18:09 +0000
committerlloyd <[email protected]>2015-01-31 16:18:09 +0000
commitfd3016d10124d2b7ccd7bc885235f2e407d73800 (patch)
treee237b54c3a8d465c893a012157d9d52014eaccc9 /src/lib/kdf/prf_tls
parent00c9b3f4834603946065c15b9b2e9fa5e973b979 (diff)
Use registry also for KDF, EMSA, and EME
Diffstat (limited to 'src/lib/kdf/prf_tls')
-rw-r--r--src/lib/kdf/prf_tls/prf_tls.cpp24
-rw-r--r--src/lib/kdf/prf_tls/prf_tls.h10
2 files changed, 23 insertions, 11 deletions
diff --git a/src/lib/kdf/prf_tls/prf_tls.cpp b/src/lib/kdf/prf_tls/prf_tls.cpp
index 79292922c..f1061fd10 100644
--- a/src/lib/kdf/prf_tls/prf_tls.cpp
+++ b/src/lib/kdf/prf_tls/prf_tls.cpp
@@ -5,14 +5,24 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
+#include <botan/internal/kdf_utils.h>
#include <botan/prf_tls.h>
-#include <botan/internal/xor_buf.h>
#include <botan/hmac.h>
-#include <botan/md5.h>
-#include <botan/sha160.h>
namespace Botan {
+TLS_12_PRF* TLS_12_PRF::make(const Spec& spec)
+ {
+ if(auto mac = make_a<MessageAuthenticationCode>(spec.arg(0)))
+ return new TLS_12_PRF(mac);
+ if(auto hash = make_a<HashFunction>(spec.arg(0)))
+ return new TLS_12_PRF(new HMAC(hash));
+ return nullptr;
+ }
+
+BOTAN_REGISTER_NAMED_T(KDF, "TLS-12-PRF", TLS_12_PRF, TLS_12_PRF::make);
+BOTAN_REGISTER_KDF_NOARGS(TLS_PRF, "TLS-PRF");
+
namespace {
/*
@@ -61,8 +71,8 @@ void P_hash(secure_vector<byte>& output,
*/
TLS_PRF::TLS_PRF()
{
- hmac_md5.reset(new HMAC(new MD5));
- hmac_sha1.reset(new HMAC(new SHA_160));
+ hmac_md5.reset(make_a<MessageAuthenticationCode>("HMAC(MD5)"));
+ hmac_sha1.reset(make_a<MessageAuthenticationCode>("HMAC(SHA-1)"));
}
/*
@@ -88,7 +98,7 @@ secure_vector<byte> TLS_PRF::derive(size_t key_len,
/*
* TLS v1.2 PRF Constructor and Destructor
*/
-TLS_12_PRF::TLS_12_PRF(MessageAuthenticationCode* mac) : hmac(mac)
+TLS_12_PRF::TLS_12_PRF(MessageAuthenticationCode* mac) : m_mac(mac)
{
}
@@ -98,7 +108,7 @@ secure_vector<byte> TLS_12_PRF::derive(size_t key_len,
{
secure_vector<byte> output(key_len);
- P_hash(output, *hmac, secret, secret_len, seed, seed_len);
+ P_hash(output, *m_mac, secret, secret_len, seed, seed_len);
return output;
}
diff --git a/src/lib/kdf/prf_tls/prf_tls.h b/src/lib/kdf/prf_tls/prf_tls.h
index 71b4d55e9..c3adc6caf 100644
--- a/src/lib/kdf/prf_tls/prf_tls.h
+++ b/src/lib/kdf/prf_tls/prf_tls.h
@@ -42,12 +42,14 @@ class BOTAN_DLL TLS_12_PRF : public KDF
const byte secret[], size_t secret_len,
const byte seed[], size_t seed_len) const;
- std::string name() const { return "TLSv12-PRF(" + hmac->name() + ")"; }
- KDF* clone() const { return new TLS_12_PRF(hmac->clone()); }
+ std::string name() const { return "TLS-12-PRF(" + m_mac->name() + ")"; }
+ KDF* clone() const { return new TLS_12_PRF(m_mac->clone()); }
- TLS_12_PRF(MessageAuthenticationCode* hmac);
+ TLS_12_PRF(MessageAuthenticationCode* mac);
+
+ static TLS_12_PRF* make(const Spec& spec);
private:
- std::unique_ptr<MessageAuthenticationCode> hmac;
+ std::unique_ptr<MessageAuthenticationCode> m_mac;
};
}