aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/mac
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/mac')
-rw-r--r--src/lib/mac/cbc_mac/cbc_mac.cpp5
-rw-r--r--src/lib/mac/cmac/cmac.cpp7
-rw-r--r--src/lib/mac/hmac/hmac.cpp7
-rw-r--r--src/lib/mac/info.txt4
-rw-r--r--src/lib/mac/mac.cpp62
-rw-r--r--src/lib/mac/mac.h19
-rw-r--r--src/lib/mac/mac_utils.h35
-rw-r--r--src/lib/mac/poly1305/poly1305.cpp3
-rw-r--r--src/lib/mac/siphash/siphash.cpp3
-rw-r--r--src/lib/mac/x919_mac/x919_mac.cpp10
10 files changed, 88 insertions, 67 deletions
diff --git a/src/lib/mac/cbc_mac/cbc_mac.cpp b/src/lib/mac/cbc_mac/cbc_mac.cpp
index b58372c78..449865255 100644
--- a/src/lib/mac/cbc_mac/cbc_mac.cpp
+++ b/src/lib/mac/cbc_mac/cbc_mac.cpp
@@ -5,7 +5,6 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/mac_utils.h>
#include <botan/cbc_mac.h>
namespace Botan {
@@ -14,14 +13,12 @@ CBC_MAC* CBC_MAC::make(const Spec& spec)
{
if(spec.arg_count() == 1)
{
- if(auto bc = make_block_cipher(spec.arg(0)))
+ if(auto bc = BlockCipher::create(spec.arg(0)))
return new CBC_MAC(bc.release());
}
return nullptr;
}
-BOTAN_REGISTER_NAMED_T(MessageAuthenticationCode, "CBC-MAC", CBC_MAC, CBC_MAC::make);
-
/*
* Update an CBC-MAC Calculation
*/
diff --git a/src/lib/mac/cmac/cmac.cpp b/src/lib/mac/cmac/cmac.cpp
index 1621079dc..27edda233 100644
--- a/src/lib/mac/cmac/cmac.cpp
+++ b/src/lib/mac/cmac/cmac.cpp
@@ -5,7 +5,6 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/mac_utils.h>
#include <botan/cmac.h>
namespace Botan {
@@ -14,14 +13,12 @@ CMAC* CMAC::make(const Spec& spec)
{
if(spec.arg_count() == 1)
{
- if(BlockCipher* bc = get_block_cipher(spec.arg(0)))
- return new CMAC(bc);
+ if(auto bc = BlockCipher::create(spec.arg(0)))
+ return new CMAC(bc.release());
}
return nullptr;
}
-BOTAN_REGISTER_NAMED_T(MessageAuthenticationCode, "CMAC", CMAC, CMAC::make);
-
/*
* Perform CMAC's multiplication in GF(2^n)
*/
diff --git a/src/lib/mac/hmac/hmac.cpp b/src/lib/mac/hmac/hmac.cpp
index 1c6821a54..f445ab0cf 100644
--- a/src/lib/mac/hmac/hmac.cpp
+++ b/src/lib/mac/hmac/hmac.cpp
@@ -6,7 +6,6 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/mac_utils.h>
#include <botan/hmac.h>
namespace Botan {
@@ -15,14 +14,12 @@ HMAC* HMAC::make(const Spec& spec)
{
if(spec.arg_count() == 1)
{
- if(HashFunction* h = get_hash_function(spec.arg(0)))
- return new HMAC(h);
+ if(auto h = HashFunction::create(spec.arg(0)))
+ return new HMAC(h.release());
}
return nullptr;
}
-BOTAN_REGISTER_NAMED_T(MessageAuthenticationCode, "HMAC", HMAC, HMAC::make);
-
/*
* Update a HMAC Calculation
*/
diff --git a/src/lib/mac/info.txt b/src/lib/mac/info.txt
index 3faa16c11..ab7833857 100644
--- a/src/lib/mac/info.txt
+++ b/src/lib/mac/info.txt
@@ -3,7 +3,3 @@ define MAC 20150626
<header:public>
mac.h
</header:public>
-
-<header:internal>
-mac_utils.h
-</header:internal>
diff --git a/src/lib/mac/mac.cpp b/src/lib/mac/mac.cpp
index 0bb1939c7..8c1185c55 100644
--- a/src/lib/mac/mac.cpp
+++ b/src/lib/mac/mac.cpp
@@ -6,10 +6,48 @@
*/
#include <botan/mac.h>
+#include <botan/internal/algo_registry.h>
#include <botan/mem_ops.h>
+#if defined(BOTAN_HAS_CBC_MAC)
+ #include <botan/cbc_mac.h>
+#endif
+
+#if defined(BOTAN_HAS_CMAC)
+ #include <botan/cmac.h>
+#endif
+
+#if defined(BOTAN_HAS_HMAC)
+ #include <botan/hmac.h>
+#endif
+
+#if defined(BOTAN_HAS_POLY1305)
+ #include <botan/poly1305.h>
+#endif
+
+#if defined(BOTAN_HAS_SIPHASH)
+ #include <botan/siphash.h>
+#endif
+
+#if defined(BOTAN_HAS_ANSI_X919_MAC)
+ #include <botan/x919_mac.h>
+#endif
+
namespace Botan {
+std::unique_ptr<MessageAuthenticationCode> MessageAuthenticationCode::create(const std::string& algo_spec,
+ const std::string& provider)
+ {
+ return std::unique_ptr<MessageAuthenticationCode>(make_a<MessageAuthenticationCode>(algo_spec, provider));
+ }
+
+std::vector<std::string> MessageAuthenticationCode::providers(const std::string& algo_spec)
+ {
+ return providers_of<MessageAuthenticationCode>(MessageAuthenticationCode::Spec(algo_spec));
+ }
+
+MessageAuthenticationCode::~MessageAuthenticationCode() {}
+
/*
* Default (deterministic) MAC verification operation
*/
@@ -23,4 +61,28 @@ bool MessageAuthenticationCode::verify_mac(const byte mac[], size_t length)
return same_mem(our_mac.data(), mac, length);
}
+#if defined(BOTAN_HAS_CBC_MAC)
+BOTAN_REGISTER_NAMED_T(MessageAuthenticationCode, "CBC-MAC", CBC_MAC, CBC_MAC::make);
+#endif
+
+#if defined(BOTAN_HAS_CMAC)
+BOTAN_REGISTER_NAMED_T(MessageAuthenticationCode, "CMAC", CMAC, CMAC::make);
+#endif
+
+#if defined(BOTAN_HAS_HMAC)
+BOTAN_REGISTER_NAMED_T(MessageAuthenticationCode, "HMAC", HMAC, HMAC::make);
+#endif
+
+#if defined(BOTAN_HAS_POLY1305)
+BOTAN_REGISTER_T_NOARGS(MessageAuthenticationCode, Poly1305);
+#endif
+
+#if defined(BOTAN_HAS_SIPHASH)
+BOTAN_REGISTER_NAMED_T_2LEN(MessageAuthenticationCode, SipHash, "SipHash", "base", 2, 4);
+#endif
+
+#if defined(BOTAN_HAS_ANSI_X919_MAC)
+BOTAN_REGISTER_NAMED_T(MessageAuthenticationCode, "X9.19-MAC", ANSI_X919_MAC, make_new_T<ANSI_X919_MAC>);
+#endif
+
}
diff --git a/src/lib/mac/mac.h b/src/lib/mac/mac.h
index 8ad2d1e99..90ef4db15 100644
--- a/src/lib/mac/mac.h
+++ b/src/lib/mac/mac.h
@@ -22,6 +22,23 @@ class BOTAN_DLL MessageAuthenticationCode : public Buffered_Computation,
public SymmetricAlgorithm
{
public:
+ typedef SCAN_Name Spec;
+
+ /**
+ * Create an instance based on a name
+ * Will return a null pointer if the algo/provider combination cannot
+ * be found. If provider is empty then best available is chosen.
+ */
+ static std::unique_ptr<MessageAuthenticationCode> 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 ~MessageAuthenticationCode();
+
/**
* Verify a MAC.
* @param in the MAC to verify as a byte array
@@ -34,8 +51,6 @@ class BOTAN_DLL MessageAuthenticationCode : public Buffered_Computation,
* Get a new object representing the same algorithm as *this
*/
virtual MessageAuthenticationCode* clone() const = 0;
-
- typedef SCAN_Name Spec;
};
}
diff --git a/src/lib/mac/mac_utils.h b/src/lib/mac/mac_utils.h
deleted file mode 100644
index 5b22da4a3..000000000
--- a/src/lib/mac/mac_utils.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
-* Authentication Code Utility Header
-* (C) 2015 Jack Lloyd
-*
-* Botan is released under the Simplified BSD License (see license.txt)
-*/
-
-#ifndef BOTAN_MAC_UTILS_H__
-#define BOTAN_MAC_UTILS_H__
-
-#include <botan/internal/algo_registry.h>
-#include <botan/internal/xor_buf.h>
-#include <botan/loadstor.h>
-#include <botan/rotate.h>
-#include <algorithm>
-
-namespace Botan {
-
-#define BOTAN_REGISTER_MAC(name, maker) BOTAN_REGISTER_T(MessageAuthenticationCode, name, maker)
-#define BOTAN_REGISTER_MAC_NOARGS(name) BOTAN_REGISTER_T_NOARGS(MessageAuthenticationCode, name)
-
-#define BOTAN_REGISTER_MAC_1LEN(name, def) BOTAN_REGISTER_T_1LEN(MessageAuthenticationCode, name, def)
-
-#define BOTAN_REGISTER_MAC_NAMED_NOARGS(type, name) \
- BOTAN_REGISTER_NAMED_T(MessageAuthenticationCode, name, type, make_new_T<type>)
-
-#define BOTAN_REGISTER_MAC_NAMED_1LEN(type, name, def) \
- BOTAN_REGISTER_NAMED_T(MessageAuthenticationCode, name, type, (make_new_T_1len<type,def>))
-#define BOTAN_REGISTER_MAC_NAMED_1STR(type, name, def) \
- BOTAN_REGISTER_NAMED_T(MessageAuthenticationCode, name, type, \
- std::bind(make_new_T_1str<type>, std::placeholders::_1, def));
-
-}
-
-#endif
diff --git a/src/lib/mac/poly1305/poly1305.cpp b/src/lib/mac/poly1305/poly1305.cpp
index 659667baf..0a62808f6 100644
--- a/src/lib/mac/poly1305/poly1305.cpp
+++ b/src/lib/mac/poly1305/poly1305.cpp
@@ -8,7 +8,6 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/mac_utils.h>
#include <botan/poly1305.h>
#include <botan/loadstor.h>
#include <botan/mul128.h>
@@ -16,8 +15,6 @@
namespace Botan {
-BOTAN_REGISTER_MAC_NOARGS(Poly1305);
-
namespace {
void poly1305_init(secure_vector<u64bit>& X, const byte key[32])
diff --git a/src/lib/mac/siphash/siphash.cpp b/src/lib/mac/siphash/siphash.cpp
index f8ed28a84..4a9ffe8ea 100644
--- a/src/lib/mac/siphash/siphash.cpp
+++ b/src/lib/mac/siphash/siphash.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/mac_utils.h>
#include <botan/siphash.h>
namespace Botan {
-BOTAN_REGISTER_NAMED_T_2LEN(MessageAuthenticationCode, SipHash, "SipHash", "base", 2, 4);
-
namespace {
void SipRounds(u64bit M, secure_vector<u64bit>& V, size_t r)
diff --git a/src/lib/mac/x919_mac/x919_mac.cpp b/src/lib/mac/x919_mac/x919_mac.cpp
index 542f9040a..205d812c2 100644
--- a/src/lib/mac/x919_mac/x919_mac.cpp
+++ b/src/lib/mac/x919_mac/x919_mac.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/mac_utils.h>
#include <botan/x919_mac.h>
namespace Botan {
-BOTAN_REGISTER_MAC_NAMED_NOARGS(ANSI_X919_MAC, "X9.19-MAC");
-
/*
* Update an ANSI X9.19 MAC Calculation
*/
@@ -88,10 +85,11 @@ MessageAuthenticationCode* ANSI_X919_MAC::clone() const
/*
* ANSI X9.19 MAC Constructor
*/
-ANSI_X919_MAC::ANSI_X919_MAC() : m_state(8), m_position(0)
+ANSI_X919_MAC::ANSI_X919_MAC() :
+ m_des1(BlockCipher::create("DES")),
+ m_des2(BlockCipher::create("DES")),
+ m_state(8), m_position(0)
{
- m_des1.reset(get_block_cipher("DES"));
- m_des2.reset(m_des1->clone());
}
}