diff options
author | Jeffrey Walton <noloader@gmail.com> | 2019-01-28 20:56:10 -0500 |
---|---|---|
committer | Jeffrey Walton <noloader@gmail.com> | 2019-01-28 20:56:10 -0500 |
commit | 281831c08a4af049f1de649d6561f4213b050c0a (patch) | |
tree | 40bd26aa2bb68d3294a35d66e0d77d4131a26088 /chachapoly.cpp | |
parent | cb674918b3cb1ec7f07634a3d1cbb8b722a127fd (diff) | |
download | cryptopp-git-281831c08a4af049f1de649d6561f4213b050c0a.tar.gz |
Fix ChaCha20Poly1305 padding
Diffstat (limited to 'chachapoly.cpp')
-rw-r--r-- | chachapoly.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/chachapoly.cpp b/chachapoly.cpp index 02a1f6b1..ee49b4e6 100644 --- a/chachapoly.cpp +++ b/chachapoly.cpp @@ -50,15 +50,19 @@ size_t ChaCha20Poly1305_Base::AuthenticateBlocks(const byte *data, size_t len) void ChaCha20Poly1305_Base::AuthenticateLastHeaderBlock()
{
+ // Pad to a multiple of 16 or 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);
}
void ChaCha20Poly1305_Base::AuthenticateLastConfidentialBlock()
{
+ // Pad to a multiple of 16 or 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);
}
|