diff options
author | weidai <weidai11@users.noreply.github.com> | 2009-03-05 08:53:50 +0000 |
---|---|---|
committer | weidai <weidai11@users.noreply.github.com> | 2009-03-05 08:53:50 +0000 |
commit | da24db2a8b834ba3c3ee5c54041ff3782e9c1984 (patch) | |
tree | 548b001016c5f93e2811ac4067c9b18ca36354e4 | |
parent | e4295fda977bcbddb3d14d344ba45c19c43c6b28 (diff) | |
download | cryptopp-git-da24db2a8b834ba3c3ee5c54041ff3782e9c1984.tar.gz |
fix bug when AuthenticatedDecryptionFilter::MAC_AT_BEGIN is not specified
-rw-r--r-- | datatest.cpp | 8 | ||||
-rw-r--r-- | filters.cpp | 4 |
2 files changed, 10 insertions, 2 deletions
diff --git a/datatest.cpp b/datatest.cpp index 0ae50dd7..a0282447 100644 --- a/datatest.cpp +++ b/datatest.cpp @@ -397,7 +397,8 @@ void TestAuthenticatedSymmetricCipher(TestData &v, const NameValuePairs &overrid std::string encrypted, decrypted; AuthenticatedEncryptionFilter ef(*asc1, new StringSink(encrypted)); - AuthenticatedDecryptionFilter df(*asc2, new StringSink(decrypted), AuthenticatedDecryptionFilter::MAC_AT_BEGIN); + bool macAtBegin = !GlobalRNG().GenerateBit(); // test both ways randomly + AuthenticatedDecryptionFilter df(*asc2, new StringSink(decrypted), macAtBegin ? AuthenticatedDecryptionFilter::MAC_AT_BEGIN : 0); if (asc1->NeedsPrespecifiedDataLengths()) { @@ -407,10 +408,13 @@ void TestAuthenticatedSymmetricCipher(TestData &v, const NameValuePairs &overrid StringStore sh(header), sp(plaintext), sc(ciphertext), sf(footer), sm(mac); - sm.TransferTo(df); + if (macAtBegin) + sm.TransferTo(df); sh.CopyTo(df, LWORD_MAX, "AAD"); sc.TransferTo(df); sf.CopyTo(df, LWORD_MAX, "AAD"); + if (!macAtBegin) + sm.TransferTo(df); df.MessageEnd(); sh.TransferTo(ef, sh.MaxRetrievable()/2+1, "AAD"); diff --git a/filters.cpp b/filters.cpp index 86bd616a..9a749f4e 100644 --- a/filters.cpp +++ b/filters.cpp @@ -885,7 +885,11 @@ byte * AuthenticatedDecryptionFilter::ChannelCreatePutSpace(const std::string &c size_t AuthenticatedDecryptionFilter::ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking) { if (channel.empty()) + { + if (m_lastSize > 0) + m_hashVerifier.ForceNextPut(); return FilterWithBufferedInput::Put2(begin, length, messageEnd, blocking); + } if (channel == "AAD") return m_hashVerifier.Put2(begin, length, 0, blocking); |