00001 #include "pch.h"
00002
00003 #ifndef CRYPTOPP_IMPORTS
00004
00005 #include "cbcmac.h"
00006
00007 NAMESPACE_BEGIN(CryptoPP)
00008
00009 void CBC_MAC_Base::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms)
00010 {
00011 AccessCipher().SetKey(key, length, params);
00012 m_reg.CleanNew(AccessCipher().BlockSize());
00013 m_counter = 0;
00014 }
00015
00016 void CBC_MAC_Base::Update(const byte *input, size_t length)
00017 {
00018 unsigned int blockSize = AccessCipher().BlockSize();
00019
00020 while (m_counter && length)
00021 {
00022 m_reg[m_counter++] ^= *input++;
00023 if (m_counter == blockSize)
00024 ProcessBuf();
00025 length--;
00026 }
00027
00028 if (length >= blockSize)
00029 {
00030 size_t leftOver = AccessCipher().AdvancedProcessBlocks(m_reg, input, m_reg, length, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput);
00031 input += (length - leftOver);
00032 length = leftOver;
00033 }
00034
00035 while (length--)
00036 {
00037 m_reg[m_counter++] ^= *input++;
00038 if (m_counter == blockSize)
00039 ProcessBuf();
00040 }
00041 }
00042
00043 void CBC_MAC_Base::TruncatedFinal(byte *mac, size_t size)
00044 {
00045 ThrowIfInvalidTruncatedSize(size);
00046
00047 if (m_counter)
00048 ProcessBuf();
00049
00050 memcpy(mac, m_reg, size);
00051 memset(m_reg, 0, AccessCipher().BlockSize());
00052 }
00053
00054 void CBC_MAC_Base::ProcessBuf()
00055 {
00056 AccessCipher().ProcessBlock(m_reg);
00057 m_counter = 0;
00058 }
00059
00060 NAMESPACE_END
00061
00062 #endif