summaryrefslogtreecommitdiff
path: root/validat8.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2019-07-03 01:41:23 -0400
committerJeffrey Walton <noloader@gmail.com>2019-07-03 01:41:23 -0400
commitce6d3c1306cfa3f78c938a66cccc8acc5d0ec2af (patch)
tree042e28c2814a63755b44501c899380376c733ebb /validat8.cpp
parent5d0ceb3b04323a484059809d238d56e16ebcbe3e (diff)
downloadcryptopp-git-ce6d3c1306cfa3f78c938a66cccc8acc5d0ec2af.tar.gz
Add legacy ECIES ECP cryptosystem and kat (GH #856)
Diffstat (limited to 'validat8.cpp')
-rw-r--r--validat8.cpp52
1 files changed, 51 insertions, 1 deletions
diff --git a/validat8.cpp b/validat8.cpp
index 16d2daba..a1d032c0 100644
--- a/validat8.cpp
+++ b/validat8.cpp
@@ -38,6 +38,14 @@
NAMESPACE_BEGIN(CryptoPP)
NAMESPACE_BEGIN(Test)
+inline byte* C2B(char* ptr) {
+ return reinterpret_cast<byte*>(ptr);
+}
+
+inline const byte* C2B(const char* ptr) {
+ return reinterpret_cast<const byte*>(ptr);
+}
+
bool ValidateRSA_Encrypt()
{
// Must be large enough for RSA-3072 to test SHA3_256
@@ -139,6 +147,7 @@ bool ValidateECP_Encrypt()
return pass;
}
+// https://github.com/weidai11/cryptopp/issues/856
class NULLHash : public CryptoPP::IteratedHashWithStaticTransform
<CryptoPP::word32, CryptoPP::BigEndian, 32, 0, NULLHash, 0>
{
@@ -148,6 +157,7 @@ public:
static const char *StaticAlgorithmName() {return "NULL HASH";}
};
+// https://github.com/weidai11/cryptopp/issues/856
template <class EC, class HASH = SHA1, class COFACTOR_OPTION = NoCofactorMultiplication, bool DHAES_MODE = true, bool LABEL_OCTETS = false>
struct ECIES_NULLDigest
: public DL_ES<
@@ -158,7 +168,7 @@ struct ECIES_NULLDigest
ECIES<EC> >
{
// TODO: fix this after name is standardized
- CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "ECIES NULLDigest";}
+ CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "ECIES-NULLDigest";}
};
bool ValidateECP_NULLDigest_Encrypt()
@@ -182,6 +192,46 @@ bool ValidateECP_NULLDigest_Encrypt()
return pass;
}
+// Ensure interop with Crypto++ 5.6.4 and earlier
+bool ValidateECP_Legacy_Encrypt()
+{
+ std::cout << "\nLegacy ECIES ECP validation suite running...\n\n";
+ bool pass = true;
+ {
+ FileSource fc(DataDir("TestData/ecies_p160.dat").c_str(), true, new HexDecoder);
+ ECIES<ECP,SHA1,NoCofactorMultiplication,false,true>::Decryptor privC(fc);
+ ECIES<ECP,SHA1,NoCofactorMultiplication,false,true>::Encryptor pubC(privC);
+
+ pass = CryptoSystemValidate(privC, pubC) && pass;
+
+ // Test data generated by Crypto++ 5.6.2.
+ // Also see https://github.com/weidai11/cryptopp/pull/857.
+ const std::string plain = "Yoda said, Do or do not. There is no try.";
+ const std::string cipher =
+ "\x04\xF6\xC1\xB1\xFA\xAC\x8A\xD5\xD3\x96\xE7\x13\xAE\xBD\x0C\xCE"
+ "\x15\xCF\x44\x54\x08\x63\xCC\xBF\x89\x4D\xD0\xB8\x38\xA1\x3A\xB2"
+ "\x90\x75\x86\x82\x7F\x9D\x95\x26\xA5\x74\x13\x3A\x74\x63\x11\x71"
+ "\x70\x4C\x01\xA4\x08\x04\x95\x69\x6A\x91\xF0\xC0\xA4\xBD\x1E\xAA"
+ "\x59\x57\xB8\xA9\xD2\xF7\x7C\x98\xE3\xC5\xE3\xF4\x4F\xA7\x6E\x73"
+ "\x83\xF3\x1E\x05\x73\xA4\xEE\x63\x55\xFD\x6D\x31\xBB\x9E\x36\x4C"
+ "\x79\xD0\x76\xC0\x0D\xE9";
+
+ std::string recover;
+ recover.resize(privC.MaxPlaintextLength(cipher.size()));
+
+ DecodingResult result = privC.Decrypt(GlobalRNG(), C2B(&cipher[0]), cipher.size(), C2B(&recover[0]));
+ if (result.isValidCoding)
+ recover.resize(result.messageLength);
+ else
+ recover.resize(0);
+
+ pass = (plain == recover) && pass;
+ std::cout << (pass ? "passed " : "FAILED ");
+ std::cout << "decryption known answer\n";
+ }
+ return pass;
+}
+
bool ValidateEC2N_Encrypt()
{
// DEREncode() changed to Save() at Issue 569.