diff options
| author | Jeffrey Walton <noloader@gmail.com> | 2017-05-06 09:07:24 -0400 |
|---|---|---|
| committer | Jeffrey Walton <noloader@gmail.com> | 2017-05-06 09:07:24 -0400 |
| commit | 3ea8e0655fb3318d2a58b66fd33bbfb4b5dee445 (patch) | |
| tree | 422208b8a051099170e92e9ccee34c0df1c5059e /validat0.cpp | |
| parent | 6ad999ef2f1970837718c7cc52992f3895615da5 (diff) | |
| download | cryptopp-git-3ea8e0655fb3318d2a58b66fd33bbfb4b5dee445.tar.gz | |
Add constants to default encryptor classes
Diffstat (limited to 'validat0.cpp')
| -rw-r--r-- | validat0.cpp | 93 |
1 files changed, 58 insertions, 35 deletions
diff --git a/validat0.cpp b/validat0.cpp index e1b082a1..a47f979f 100644 --- a/validat0.cpp +++ b/validat0.cpp @@ -116,8 +116,9 @@ bool TestZinflate() // Tamper
try {
StringSource(dest.substr(0, len-2), true, new Inflator(new StringSink(rec)));
- throw Exception(Exception::OTHER_ERROR, "Deflate failed to detect a truncated stream");
- } catch(const Exception&) {}
+ std::cout << "Deflate failed to detect a truncated stream\n";
+ fail = true;
+ } catch(const Exception& ex) { }
}
}
catch(const Exception&)
@@ -136,7 +137,7 @@ bool TestZinflate() try {
StringSource(src, true, new Inflator(new StringSink(dest)));
- } catch(const Exception&) { }
+ } catch(const Exception&) {}
}
// Inflate random data. See if we can induce a crash
@@ -236,26 +237,37 @@ bool TestDefaultEncryptorWithMAC() if (src != rec)
throw Exception(Exception::OTHER_ERROR, "DefaultEncryptorWithMAC failed a self test");
- // Tamper. Data format is [SALT][KEYCHECK][ENCRYPTED DATA].
+ // Tamper with the stream. Data format is [SALT][KEYCHECK][ENCRYPTED DATA].
try {
- StringSource(dest.substr(0, len-2), true, new Inflator(new StringSink(rec)));
- throw Exception(Exception::OTHER_ERROR, "DefaultEncryptorWithMAC failed to detect a truncated stream");
- } catch(const Exception&) {}
+ StringSource(dest.substr(0, len-2), true, new DefaultDecryptorWithMAC(pwd.c_str(), new StringSink(rec)));
+ std::cout << "FAILED: DefaultDecryptorWithMAC failed to detect a truncated stream\n";
+ fail = true;
+ } catch(const Exception& ex) { }
try {
- dest[4] ^= 0x01;
- StringSource(dest, true, new Inflator(new StringSink(rec)));
- throw Exception(Exception::OTHER_ERROR, "DefaultEncryptorWithMAC failed to detect a tampered salt");
- } catch(const Exception&) {}
+ // tamper salt
+ dest[DefaultDecryptorWithMAC::SALTLENGTH/2] ^= 0x01;
+ StringSource(dest, true, new DefaultDecryptorWithMAC(pwd.c_str(), new StringSink(rec)));
+ std::cout << "FAILED: DefaultDecryptorWithMAC failed to detect a tampered salt\n";
+ fail = true;
+ } catch(const Exception& ex) { }
try {
- dest[4] ^= 0x01; dest[20] ^= 0x01; // undo previous tamper
- StringSource(dest, true, new Inflator(new StringSink(rec)));
- throw Exception(Exception::OTHER_ERROR, "DefaultEncryptorWithMAC failed to detect a tampered keycheck");
- } catch(const Exception&) {}
+ // undo previous tamper
+ dest[DefaultDecryptorWithMAC::SALTLENGTH/2] ^= 0x01;
+ // tamper keycheck
+ dest[DefaultDecryptorWithMAC::SALTLENGTH+DefaultDecryptorWithMAC::KEYLENGTH/2] ^= 0x01;
+ StringSource(dest, true, new DefaultDecryptorWithMAC(pwd.c_str(), new StringSink(rec)));
+ std::cout << "FAILED: DefaultDecryptorWithMAC failed to detect a tampered keycheck\n";
+ fail = true;
+ } catch(const Exception& ex) { }
try {
- dest[20] ^= 0x01; dest[dest.length()-2] ^= 0x01; // undo previous tamper
- StringSource(dest, true, new Inflator(new StringSink(rec)));
- throw Exception(Exception::OTHER_ERROR, "DefaultEncryptorWithMAC failed to detect a tampered data");
- } catch(const Exception&) {}
+ // undo previous tamper
+ dest[DefaultDecryptorWithMAC::SALTLENGTH+DefaultDecryptorWithMAC::KEYLENGTH/2] ^= 0x01;
+ // tamper encrypted data
+ dest[dest.length()-2] ^= 0x01;
+ StringSource(dest, true, new DefaultDecryptorWithMAC(pwd.c_str(), new StringSink(rec)));
+ std::cout << "FAILED: DefaultDecryptorWithMAC failed to detect a tampered data\n";
+ fail = true;
+ } catch(const Exception& ex) { }
}
}
catch(const Exception&)
@@ -335,26 +347,37 @@ bool TestLegacyEncryptorWithMAC() if (src != rec)
throw Exception(Exception::OTHER_ERROR, "LegacyEncryptorWithMAC failed a self test");
- // Tamper. Data format is [SALT][KEYCHECK][ENCRYPTED DATA].
+ // Tamper with the stream. Data format is [SALT][KEYCHECK][ENCRYPTED DATA].
try {
- StringSource(dest.substr(0, len-2), true, new Inflator(new StringSink(rec)));
- throw Exception(Exception::OTHER_ERROR, "LegacyEncryptorWithMAC failed to detect a truncated stream");
- } catch(const Exception&) {}
+ StringSource(dest.substr(0, len-2), true, new LegacyDecryptorWithMAC(pwd.c_str(), new StringSink(rec)));
+ std::cout << "FAILED: LegacyEncryptorWithMAC failed to detect a truncated stream\n";
+ fail = true;
+ } catch(const Exception& ex) { }
try {
- dest[4] ^= 0x01;
- StringSource(dest, true, new Inflator(new StringSink(rec)));
- throw Exception(Exception::OTHER_ERROR, "LegacyEncryptorWithMAC failed to detect a tampered salt");
- } catch(const Exception&) {}
+ // tamper salt
+ dest[LegacyEncryptorWithMAC::SALTLENGTH/2] ^= 0x01;
+ StringSource(dest, true, new LegacyDecryptorWithMAC(pwd.c_str(), new StringSink(rec)));
+ std::cout << "FAILED: LegacyEncryptorWithMAC failed to detect a tampered salt\n";
+ fail = true;
+ } catch(const Exception& ex) { }
try {
- dest[4] ^= 0x01; dest[20] ^= 0x01; // undo previous tamper
- StringSource(dest, true, new Inflator(new StringSink(rec)));
- throw Exception(Exception::OTHER_ERROR, "LegacyEncryptorWithMAC failed to detect a tampered keycheck");
- } catch(const Exception&) {}
+ // undo previous tamper
+ dest[LegacyEncryptorWithMAC::SALTLENGTH/2] ^= 0x01;
+ // tamper keycheck
+ dest[LegacyEncryptorWithMAC::SALTLENGTH+LegacyEncryptorWithMAC::KEYLENGTH/2] ^= 0x01;
+ StringSource(dest, true, new LegacyDecryptorWithMAC(pwd.c_str(), new StringSink(rec)));
+ std::cout << "FAILED: LegacyEncryptorWithMAC failed to detect a tampered keycheck\n";
+ fail = true;
+ } catch(const Exception& ex) { }
try {
- dest[20] ^= 0x01; dest[dest.length()-2] ^= 0x01; // undo previous tamper
- StringSource(dest, true, new Inflator(new StringSink(rec)));
- throw Exception(Exception::OTHER_ERROR, "LegacyEncryptorWithMAC failed to detect a tampered data");
- } catch(const Exception&) {}
+ // undo previous tamper
+ dest[LegacyEncryptorWithMAC::SALTLENGTH+LegacyEncryptorWithMAC::KEYLENGTH/2] ^= 0x01;
+ // tamper encrypted data
+ dest[dest.length()-2] ^= 0x01;
+ StringSource(dest, true, new LegacyDecryptorWithMAC(pwd.c_str(), new StringSink(rec)));
+ std::cout << "FAILED: LegacyEncryptorWithMAC failed to detect a tampered data\n";
+ fail = true;
+ } catch(const Exception& ex) { }
}
}
catch(const Exception&)
|
