aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/cmac.h4
-rw-r--r--src/cmac.cpp21
2 files changed, 14 insertions, 11 deletions
diff --git a/include/cmac.h b/include/cmac.h
index de3f8b87a..c7f107258 100644
--- a/include/cmac.h
+++ b/include/cmac.h
@@ -19,6 +19,10 @@ class BOTAN_DLL CMAC : public MessageAuthenticationCode
void clear() throw();
std::string name() const;
MessageAuthenticationCode* clone() const;
+
+ static SecureVector<byte> poly_double(const MemoryRegion<byte>& in,
+ byte polynomial);
+
CMAC(const std::string&);
~CMAC() { delete e; }
private:
diff --git a/src/cmac.cpp b/src/cmac.cpp
index 210fa6768..5a99f93b1 100644
--- a/src/cmac.cpp
+++ b/src/cmac.cpp
@@ -9,12 +9,11 @@
namespace Botan {
-namespace {
-
/*************************************************
* Perform CMAC's multiplication in GF(2^n) *
*************************************************/
-SecureVector<byte> poly_double(const MemoryRegion<byte>& in, byte polynomial)
+SecureVector<byte> CMAC::poly_double(const MemoryRegion<byte>& in,
+ byte polynomial)
{
const bool do_xor = (in[0] & 0x80) ? true : false;
@@ -34,8 +33,6 @@ SecureVector<byte> poly_double(const MemoryRegion<byte>& in, byte polynomial)
return out;
}
-}
-
/*************************************************
* Update an CMAC Calculation *
*************************************************/
@@ -66,16 +63,18 @@ void CMAC::add_data(const byte input[], u32bit length)
*************************************************/
void CMAC::final_result(byte mac[])
{
+ xor_buf(state, buffer, position);
+
if(position == OUTPUT_LENGTH)
- xor_buf(buffer, B, OUTPUT_LENGTH);
+ {
+ xor_buf(state, B, OUTPUT_LENGTH);
+ }
else
{
- buffer[position] = 0x80;
- for(u32bit j = position+1; j != OUTPUT_LENGTH; ++j)
- buffer[j] = 0;
- xor_buf(buffer, P, OUTPUT_LENGTH);
+ state[position] ^= 0x80;
+ xor_buf(state, P, OUTPUT_LENGTH);
}
- xor_buf(state, buffer, OUTPUT_LENGTH);
+
e->encrypt(state);
for(u32bit j = 0; j != OUTPUT_LENGTH; ++j)