summaryrefslogtreecommitdiff
path: root/validat0.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2018-09-10 21:55:08 -0400
committerJeffrey Walton <noloader@gmail.com>2018-09-10 21:55:08 -0400
commit590f8573c4ed9bd586410baa8082b4c502051c78 (patch)
tree72448ecdabee514a07343c2cdc6bac3b7c22f5d7 /validat0.cpp
parentd0946abb0b10dd76ab2d307148f74fda664844bc (diff)
downloadcryptopp-git-590f8573c4ed9bd586410baa8082b4c502051c78.tar.gz
Fix LegacyDecryptor and LegacyDecryptorWithMAC (GH #714)
The classes used the wrong hash with the MAC. The legacy gear should have used SHA1, not SHA256.
Diffstat (limited to 'validat0.cpp')
-rw-r--r--validat0.cpp48
1 files changed, 30 insertions, 18 deletions
diff --git a/validat0.cpp b/validat0.cpp
index 62e5ec30..d9c445f1 100644
--- a/validat0.cpp
+++ b/validat0.cpp
@@ -434,10 +434,22 @@ bool TestEncryptors()
try
{
+ // Common password and message.
std::string password = "super secret password";
std::string recovered, message = "Now is the time for all good men to come to the aide of their country.";
- //StringSource(message, true, new DefaultEncryptorWithMAC(password.c_str(), new FileSink("TestData/defdmac.bin")));
- FileSource("TestData/defdmac.bin", true, new DefaultDecryptorWithMAC(password.c_str(), new StringSink(recovered)));
+
+ // This data was generated with Crypto++ 5.6.2
+ //StringSource(message, true, new LegacyEncryptorWithMAC(password.c_str(), new FileSink("TestData/defdmac1.bin")));
+ FileSource("TestData/defdmac1.bin", true, new LegacyDecryptorWithMAC(password.c_str(), new StringSink(recovered)));
+ if (message != recovered)
+ throw Exception(Exception::OTHER_ERROR, "LegacyDecryptorWithMAC failed a self test");
+
+ // Reset sink
+ recovered.clear();
+
+ // This data was generated with Crypto++ 6.0
+ //StringSource(message, true, new DefaultEncryptorWithMAC(password.c_str(), new FileSink("TestData/defdmac2.bin")));
+ FileSource("TestData/defdmac2.bin", true, new DefaultDecryptorWithMAC(password.c_str(), new StringSink(recovered)));
if (message != recovered)
throw Exception(Exception::OTHER_ERROR, "DefaultDecryptorWithMAC failed a self test");
}
@@ -1491,22 +1503,22 @@ bool TestASN1Parse()
#if defined(CRYPTOPP_EXTENDED_VALIDATION)
bool TestStringSink()
{
- try
- {
- std::string in = "The quick brown fox jumps over the lazy dog";
-
- std::string str;
- StringSource s1(in, true, new StringSink(str));
-
- std::vector<byte> vec;
- StringSource s2(in, true, new VectorSink(vec));
-
- return str.size() == vec.size() && std::equal(str.begin(), str.end(), vec.begin());
- }
- catch(const std::exception&)
- {
- }
- return false;
+ try
+ {
+ std::string in = "The quick brown fox jumps over the lazy dog";
+
+ std::string str;
+ StringSource s1(in, true, new StringSink(str));
+
+ std::vector<byte> vec;
+ StringSource s2(in, true, new VectorSink(vec));
+
+ return str.size() == vec.size() && std::equal(str.begin(), str.end(), vec.begin());
+ }
+ catch(const std::exception&)
+ {
+ }
+ return false;
}
#endif