From b0f3b8ce1761e7ab9a3ead46fb7403fb38dd3723 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Mon, 4 Sep 2017 20:36:43 -0400 Subject: [PATCH] Aligned buffers in AuthenticatedSymmetricCipherBase --- authenc.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/authenc.cpp b/authenc.cpp index 0ed9cd14..ff877a20 100644 --- a/authenc.cpp +++ b/authenc.cpp @@ -36,7 +36,20 @@ void AuthenticatedSymmetricCipherBase::AuthenticateData(const byte *input, size_ // now process the input data in blocks of blockSize bytes and save the leftovers to m_data if (len >= blockSize) { - size_t leftOver = AuthenticateBlocks(input, len); + // size_t leftOver = AuthenticateBlocks(input, len); + size_t leftOver = 0; + const unsigned int alignment = GetSymmetricCipher().OptimalDataAlignment(); + + if (IsAlignedOn(input, alignment)) + { + leftOver = AuthenticateBlocks(input, len); + } + else + { + AlignedSecByteBlock block(input, len); + leftOver = AuthenticateBlocks(block, len); + } + input += (len - leftOver); len = leftOver; }