summaryrefslogtreecommitdiffstats
path: root/botan/src/mac/x919_mac/x919_mac.cpp
diff options
context:
space:
mode:
authorKeith Isdale <keith.isdale@nokia.com>2010-07-26 14:56:53 +1000
committerKeith Isdale <keith.isdale@nokia.com>2010-07-26 14:56:53 +1000
commit9f034793bcfc51c2b7c1dd14db806f7258f9a9eb (patch)
tree63bd0f50ce5b77828ad8205eafd7b9412810499e /botan/src/mac/x919_mac/x919_mac.cpp
parent619d92cfef29e653bfdf852e83888e50cfc4348f (diff)
parent65271649dbc90f3af1184ad1b23bdb64c0c07d07 (diff)
Merge branch 'master' of git://git-nokia.trolltech.com.au/qtsoftware/research/qtuitest
Diffstat (limited to 'botan/src/mac/x919_mac/x919_mac.cpp')
-rw-r--r--botan/src/mac/x919_mac/x919_mac.cpp107
1 files changed, 107 insertions, 0 deletions
diff --git a/botan/src/mac/x919_mac/x919_mac.cpp b/botan/src/mac/x919_mac/x919_mac.cpp
new file mode 100644
index 0000000..ef89cac
--- /dev/null
+++ b/botan/src/mac/x919_mac/x919_mac.cpp
@@ -0,0 +1,107 @@
+/*
+* ANSI X9.19 MAC
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/x919_mac.h>
+#include <botan/xor_buf.h>
+#include <algorithm>
+
+namespace Botan {
+
+/*
+* Update an ANSI X9.19 MAC Calculation
+*/
+void ANSI_X919_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 ANSI X9.19 MAC Calculation
+*/
+void ANSI_X919_MAC::final_result(byte mac[])
+ {
+ if(position)
+ e->encrypt(state);
+ d->decrypt(state, mac);
+ e->encrypt(mac);
+ state.clear();
+ position = 0;
+ }
+
+/*
+* ANSI X9.19 MAC Key Schedule
+*/
+void ANSI_X919_MAC::key_schedule(const byte key[], u32bit length)
+ {
+ e->set_key(key, 8);
+ if(length == 8) d->set_key(key, 8);
+ else d->set_key(key + 8, 8);
+ }
+
+/*
+* Clear memory of sensitive data
+*/
+void ANSI_X919_MAC::clear() throw()
+ {
+ e->clear();
+ d->clear();
+ state.clear();
+ position = 0;
+ }
+
+std::string ANSI_X919_MAC::name() const
+ {
+ return "X9.19-MAC";
+ }
+
+MessageAuthenticationCode* ANSI_X919_MAC::clone() const
+ {
+ return new ANSI_X919_MAC(e->clone());
+ }
+
+/*
+* ANSI X9.19 MAC Constructor
+*/
+ANSI_X919_MAC::ANSI_X919_MAC(BlockCipher* e_in) :
+ MessageAuthenticationCode(e_in->BLOCK_SIZE,
+ e_in->MINIMUM_KEYLENGTH,
+ 2*e_in->MAXIMUM_KEYLENGTH,
+ 2*e_in->KEYLENGTH_MULTIPLE),
+ e(e_in), d(e->clone()), position(0)
+ {
+ if(e->name() != "DES")
+ throw Invalid_Argument("ANSI X9.19 MAC only supports DES");
+ }
+
+/*
+* ANSI X9.19 MAC Destructor
+le*/
+ANSI_X919_MAC::~ANSI_X919_MAC()
+ {
+ delete e;
+ delete d;
+ }
+
+}