summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--datatest.cpp8
-rw-r--r--filters.cpp4
2 files changed, 10 insertions, 2 deletions
diff --git a/datatest.cpp b/datatest.cpp
index 0ae50dd..a028244 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 86bd616..9a749f4 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);