diff options
author | lloyd <[email protected]> | 2008-09-24 14:44:01 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-24 14:44:01 +0000 |
commit | 5a120e856c78973d1a75bf6b6db9716367038166 (patch) | |
tree | 1137ae6c7560182c05a785dd8412787a35e49d76 | |
parent | 52750a635deee0f526492f905e4f115b13c2d304 (diff) |
Expose CMAC::poly_double as a static function since it looks like I may
want to inline the CMAC computation in EAX mode.
Also optimize CMAC::final_result slightly. Only write to state directly,
instead of also the write buffer (this should help L1 data caching), and
avoid what was basically a no-op where we zeroized part of a buffer and
then xored it against another buffer.
-rw-r--r-- | include/cmac.h | 4 | ||||
-rw-r--r-- | src/cmac.cpp | 21 |
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) |