Use aligned buffer for CMAC
parent
d0eefdf32a
commit
a2223356b0
18
cmac.cpp
18
cmac.cpp
|
|
@ -77,7 +77,8 @@ void CMAC_Base::Update(const byte *input, size_t length)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BlockCipher &cipher = AccessCipher();
|
BlockCipher &cipher = AccessCipher();
|
||||||
unsigned int blockSize = cipher.BlockSize();
|
const unsigned int blockSize = cipher.BlockSize();
|
||||||
|
const unsigned int alignment = cipher.OptimalDataAlignment();
|
||||||
|
|
||||||
if (m_counter > 0)
|
if (m_counter > 0)
|
||||||
{
|
{
|
||||||
|
|
@ -100,7 +101,20 @@ void CMAC_Base::Update(const byte *input, size_t length)
|
||||||
if (length > blockSize)
|
if (length > blockSize)
|
||||||
{
|
{
|
||||||
CRYPTOPP_ASSERT(m_counter == 0);
|
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);
|
input += (length - leftOver);
|
||||||
length = leftOver;
|
length = leftOver;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue