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::CheckedSetKey(void *, Empty empty, const byte *key, size_t 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 while (length >= blockSize)
00029 {
00030 xorbuf(m_reg, input, blockSize);
00031 ProcessBuf();
00032 input += blockSize;
00033 length -= blockSize;
00034 }
00035
00036 while (length--)
00037 {
00038 m_reg[m_counter++] ^= *input++;
00039 if (m_counter == blockSize)
00040 ProcessBuf();
00041 }
00042 }
00043
00044 void CBC_MAC_Base::TruncatedFinal(byte *mac, size_t size)
00045 {
00046 ThrowIfInvalidTruncatedSize(size);
00047
00048 if (m_counter)
00049 ProcessBuf();
00050
00051 memcpy(mac, m_reg, size);
00052 memset(m_reg, 0, AccessCipher().BlockSize());
00053 }
00054
00055 void CBC_MAC_Base::ProcessBuf()
00056 {
00057 AccessCipher().ProcessBlock(m_reg);
00058 m_counter = 0;
00059 }
00060
00061 NAMESPACE_END
00062
00063 #endif