Fix ChaCha20Poly1305 padding

pull/795/head
Jeffrey Walton 2019-01-28 20:56:10 -05:00
parent cb674918b3
commit 281831c08a
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 6 additions and 2 deletions

View File

@ -50,15 +50,19 @@ size_t ChaCha20Poly1305_Base::AuthenticateBlocks(const byte *data, size_t len)
void ChaCha20Poly1305_Base::AuthenticateLastHeaderBlock() void ChaCha20Poly1305_Base::AuthenticateLastHeaderBlock()
{ {
// Pad to a multiple of 16 or 0
const byte zero[16] = {0}; const byte zero[16] = {0};
size_t pad = 16 - (m_totalHeaderLength % 16); size_t rem = m_totalHeaderLength % 16;
size_t pad = rem ? 16 - rem : 0;
AccessMAC().Update(zero, pad); AccessMAC().Update(zero, pad);
} }
void ChaCha20Poly1305_Base::AuthenticateLastConfidentialBlock() void ChaCha20Poly1305_Base::AuthenticateLastConfidentialBlock()
{ {
// Pad to a multiple of 16 or 0
const byte zero[16] = {0}; const byte zero[16] = {0};
size_t pad = 16 - (m_totalMessageLength % 16); size_t rem = m_totalMessageLength % 16;
size_t pad = rem ? 16 - rem : 0;
AccessMAC().Update(zero, pad); AccessMAC().Update(zero, pad);
} }