aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_mac.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-10-26 20:31:30 -0400
committerJack Lloyd <[email protected]>2017-10-26 22:26:15 -0400
commite6d45052efedfe49e99adb6318aaf56e0a9e8d7b (patch)
treec6c3ccd3cff3d04285940bf1d518c809e0653947 /src/tests/test_mac.cpp
parent315b002ecf00f6b6bb0f0d5200d1f39a83527e8f (diff)
Add checks that keyed algorithms are actually keyed before use
Previously calling update or encrypt without calling set_key first would result in invalid outputs or else crashing.
Diffstat (limited to 'src/tests/test_mac.cpp')
-rw-r--r--src/tests/test_mac.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/tests/test_mac.cpp b/src/tests/test_mac.cpp
index f4e3e4268..18ba82b30 100644
--- a/src/tests/test_mac.cpp
+++ b/src/tests/test_mac.cpp
@@ -59,6 +59,17 @@ class Message_Auth_Tests final : public Text_Based_Test
result.test_is_nonempty("provider", provider);
result.test_eq(provider, mac->name(), algo);
+ try
+ {
+ std::vector<uint8_t> buf(128);
+ mac->update(buf.data(), buf.size());
+ result.test_failure("Was able to MAC without a key being set");
+ }
+ catch(Botan::Invalid_State&)
+ {
+ result.test_success("Trying to MAC with no key set fails");
+ }
+
mac->set_key(key);
mac->start(iv);
@@ -108,6 +119,30 @@ class Message_Auth_Tests final : public Text_Based_Test
result.test_eq(provider + " split mac", mac->verify_mac(expected.data(), expected.size()), true);
}
+
+ mac->clear();
+
+ try
+ {
+ std::vector<uint8_t> buf(128);
+ mac->update(buf.data(), buf.size());
+ result.test_failure("Was able to MAC without a key being set");
+ }
+ catch(Botan::Invalid_State&)
+ {
+ result.test_success("Trying to MAC with no key set (after clear) fails");
+ }
+
+ try
+ {
+ std::vector<uint8_t> buf(mac->output_length());
+ mac->final(buf.data());
+ result.test_failure("Was able to MAC without a key being set");
+ }
+ catch(Botan::Invalid_State&)
+ {
+ result.test_success("Trying to MAC with no key set (after clear) fails");
+ }
}
return result;