Use aligned buffer for CMAC

This commit is contained in:
Jeffrey Walton 2017-09-04 19:49:45 -04:00
parent d0eefdf32a
commit a2223356b0
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
2 changed files with 17 additions and 3 deletions

View File

@ -77,7 +77,8 @@ void CMAC_Base::Update(const byte *input, size_t length)
return;
BlockCipher &cipher = AccessCipher();
unsigned int blockSize = cipher.BlockSize();
const unsigned int blockSize = cipher.BlockSize();
const unsigned int alignment = cipher.OptimalDataAlignment();
if (m_counter > 0)
{
@ -100,7 +101,20 @@ void CMAC_Base::Update(const byte *input, size_t length)
if (length > blockSize)
{
CRYPTOPP_ASSERT(m_counter == 0);
size_t leftOver = 1 + cipher.AdvancedProcessBlocks(m_reg, input, m_reg, length-1, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput);
const byte* is = input; // m_reg is always aligned
AlignedSecByteBlock i;
if (!IsAlignedOn(input, alignment))
{
i.Assign(input, length);
is = i.begin();
}
// size_t leftOver = 1 + cipher.AdvancedProcessBlocks(m_reg, input, m_reg, length-1,
// BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput);
const int flags = BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput;
size_t leftOver = 1 + cipher.AdvancedProcessBlocks(m_reg, is, m_reg, length-1, flags);
input += (length - leftOver);
length = leftOver;
}

2
cmac.h
View File

@ -34,7 +34,7 @@ protected:
virtual BlockCipher & AccessCipher() =0;
void ProcessBuf();
SecByteBlock m_reg;
AlignedSecByteBlock m_reg;
unsigned int m_counter;
};