aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/mac
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-05-13 12:49:40 -0400
committerJack Lloyd <[email protected]>2018-05-13 12:49:40 -0400
commit1fcf8c6ba3f8912c9c6cba0555597ab0083eaaa2 (patch)
tree07199fd3b677dd02828f73fa1d2dcda272ee7a1f /src/lib/mac
parentbef5303b3ec1a17bc79ccce0eecdca4874639b56 (diff)
Add message to BOTAN_ARG_CHECK and use it more widely
Diffstat (limited to 'src/lib/mac')
-rw-r--r--src/lib/mac/cmac/cmac.cpp1
-rw-r--r--src/lib/mac/gmac/gmac.cpp1
-rw-r--r--src/lib/mac/hmac/hmac.cpp4
-rw-r--r--src/lib/mac/mac.cpp8
-rw-r--r--src/lib/mac/mac.h7
5 files changed, 13 insertions, 8 deletions
diff --git a/src/lib/mac/cmac/cmac.cpp b/src/lib/mac/cmac/cmac.cpp
index bd2a53a72..38752471d 100644
--- a/src/lib/mac/cmac/cmac.cpp
+++ b/src/lib/mac/cmac/cmac.cpp
@@ -6,6 +6,7 @@
*/
#include <botan/cmac.h>
+#include <botan/exceptn.h>
#include <botan/internal/poly_dbl.h>
namespace Botan {
diff --git a/src/lib/mac/gmac/gmac.cpp b/src/lib/mac/gmac/gmac.cpp
index a4e84f57b..27eccdde3 100644
--- a/src/lib/mac/gmac/gmac.cpp
+++ b/src/lib/mac/gmac/gmac.cpp
@@ -8,6 +8,7 @@
#include <botan/gmac.h>
#include <botan/ghash.h>
+#include <botan/exceptn.h>
#include <botan/block_cipher.h>
namespace Botan {
diff --git a/src/lib/mac/hmac/hmac.cpp b/src/lib/mac/hmac/hmac.cpp
index 532c98274..72c617c5b 100644
--- a/src/lib/mac/hmac/hmac.cpp
+++ b/src/lib/mac/hmac/hmac.cpp
@@ -100,8 +100,8 @@ MessageAuthenticationCode* HMAC::clone() const
*/
HMAC::HMAC(HashFunction* hash) : m_hash(hash)
{
- if(m_hash->hash_block_size() == 0)
- throw Invalid_Argument("HMAC cannot be used with " + m_hash->name());
+ BOTAN_ARG_CHECK(m_hash->hash_block_size() > 0,
+ "HMAC is not compatible with this hash function");
}
}
diff --git a/src/lib/mac/mac.cpp b/src/lib/mac/mac.cpp
index 65107470b..4c3fc5230 100644
--- a/src/lib/mac/mac.cpp
+++ b/src/lib/mac/mac.cpp
@@ -6,6 +6,7 @@
*/
#include <botan/mac.h>
+#include <botan/exceptn.h>
#include <botan/scan_name.h>
#include <botan/mem_ops.h>
@@ -147,6 +148,13 @@ MessageAuthenticationCode::create_or_throw(const std::string& algo,
throw Lookup_Error("MAC", algo, provider);
}
+void MessageAuthenticationCode::start_msg(const uint8_t nonce[], size_t nonce_len)
+ {
+ BOTAN_UNUSED(nonce);
+ if(nonce_len > 0)
+ throw Invalid_IV_Length(name(), nonce_len);
+ }
+
/*
* Default (deterministic) MAC verification operation
*/
diff --git a/src/lib/mac/mac.h b/src/lib/mac/mac.h
index 1e358a4c5..de30b7dbb 100644
--- a/src/lib/mac/mac.h
+++ b/src/lib/mac/mac.h
@@ -64,12 +64,7 @@ class BOTAN_PUBLIC_API(2,0) MessageAuthenticationCode : public Buffered_Computat
* Default implementation simply rejects all non-empty nonces
* since most hash/MAC algorithms do not support randomization
*/
- virtual void start_msg(const uint8_t nonce[], size_t nonce_len)
- {
- BOTAN_UNUSED(nonce);
- if(nonce_len > 0)
- throw Invalid_IV_Length(name(), nonce_len);
- }
+ virtual void start_msg(const uint8_t nonce[], size_t nonce_len);
/**
* Begin processing a message with a nonce