aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cbc_mac.cpp108
-rw-r--r--src/def_alg.cpp2
2 files changed, 110 insertions, 0 deletions
diff --git a/src/cbc_mac.cpp b/src/cbc_mac.cpp
new file mode 100644
index 000000000..e805c2aa7
--- /dev/null
+++ b/src/cbc_mac.cpp
@@ -0,0 +1,108 @@
+/*************************************************
+* CBC-MAC Source File *
+* (C) 1999-2007 The Botan Project *
+*************************************************/
+
+#include <botan/cbc_mac.h>
+#include <botan/lookup.h>
+#include <botan/bit_ops.h>
+#include <algorithm>
+
+namespace Botan {
+
+/*************************************************
+* Update an CBC-MAC Calculation *
+*************************************************/
+void CBC_MAC::add_data(const byte input[], u32bit length)
+ {
+ u32bit xored = std::min(8 - position, length);
+ xor_buf(state + position, input, xored);
+ position += xored;
+
+ if(position < 8) return;
+
+ e->encrypt(state);
+ input += xored;
+ length -= xored;
+ while(length >= 8)
+ {
+ xor_buf(state, input, 8);
+ e->encrypt(state);
+ input += 8;
+ length -= 8;
+ }
+
+ xor_buf(state, input, length);
+ position = length;
+ }
+
+/*************************************************
+* Finalize an CBC-MAC Calculation *
+*************************************************/
+void CBC_MAC::final_result(byte mac[])
+ {
+ if(position)
+ e->encrypt(state);
+
+ copy_mem(mac, state.begin(), state.size());
+ state.clear();
+ position = 0;
+ }
+
+/*************************************************
+* CBC-MAC Key Schedule *
+*************************************************/
+void CBC_MAC::key(const byte key[], u32bit length)
+ {
+ e->set_key(key, length);
+ }
+
+/*************************************************
+* Clear memory of sensitive data *
+*************************************************/
+void CBC_MAC::clear() throw()
+ {
+ e->clear();
+ state.clear();
+ position = 0;
+ }
+
+/*************************************************
+* Return the name of this type *
+*************************************************/
+std::string CBC_MAC::name() const
+ {
+ return "CBC-MAC(" + e->name() + ")";
+ }
+
+/*************************************************
+* Return a clone of this object *
+*************************************************/
+MessageAuthenticationCode* CBC_MAC::clone() const
+ {
+ return new CBC_MAC(e->name());
+ }
+
+/*************************************************
+* CBC-MAC Constructor *
+*************************************************/
+CBC_MAC::CBC_MAC(const std::string& cipher) :
+ MessageAuthenticationCode(block_size_of(cipher),
+ min_keylength_of(cipher),
+ max_keylength_of(cipher),
+ keylength_multiple_of(cipher)),
+ state(block_size_of(cipher))
+ {
+ e = get_block_cipher(cipher);
+ position = 0;
+ }
+
+/*************************************************
+* CBC-MAC Destructor *
+*************************************************/
+CBC_MAC::~CBC_MAC()
+ {
+ delete e;
+ }
+
+}
diff --git a/src/def_alg.cpp b/src/def_alg.cpp
index 09ae5c978..2dbd30621 100644
--- a/src/def_alg.cpp
+++ b/src/def_alg.cpp
@@ -52,6 +52,7 @@
#include <botan/whrlpool.h>
#include <botan/par_hash.h>
+#include <botan/cbc_mac.h>
#include <botan/cmac.h>
#include <botan/hmac.h>
#include <botan/x919_mac.h>
@@ -219,6 +220,7 @@ Default_Engine::find_mac(const std::string& algo_spec) const
return 0;
const std::string algo_name = deref_alias(name[0]);
+ HANDLE_TYPE_ONE_STRING("CBC-MAC", CBC_MAC);
HANDLE_TYPE_ONE_STRING("CMAC", CMAC);
HANDLE_TYPE_ONE_STRING("HMAC", HMAC);
HANDLE_TYPE_NO_ARGS("X9.19-MAC", ANSI_X919_MAC);