summaryrefslogtreecommitdiff
path: root/validat8.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2021-03-19 16:29:10 -0400
committerJeffrey Walton <noloader@gmail.com>2021-03-19 16:29:10 -0400
commit744026b75c48acbb2d8ddd1d0bb8e3aa9a9b7bc1 (patch)
treeade52377fa85b892dece3bfc9753dbfad7faec80 /validat8.cpp
parentdff71eb8ee7aeaa4f4f92c8effe3658a57d07722 (diff)
downloadcryptopp-git-744026b75c48acbb2d8ddd1d0bb8e3aa9a9b7bc1.tar.gz
Add additional RSA and Rabin self tests
Diffstat (limited to 'validat8.cpp')
-rw-r--r--validat8.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/validat8.cpp b/validat8.cpp
index c08a6bbd..cc1d7e6a 100644
--- a/validat8.cpp
+++ b/validat8.cpp
@@ -59,6 +59,15 @@ inline bool operator!=(const RSA::PrivateKey& lhs, const RSA::PrivateKey& rhs) {
return !operator==(lhs, rhs);
}
+inline bool operator==(const RSA::PublicKey& lhs, const RSA::PublicKey& rhs) {
+ return lhs.GetModulus() == rhs.GetModulus() &&
+ lhs.GetPublicExponent() == rhs.GetPublicExponent();
+}
+
+inline bool operator!=(const RSA::PublicKey& lhs, const RSA::PublicKey& rhs) {
+ return !operator==(lhs, rhs);
+}
+
inline bool operator==(const LUC::PrivateKey& lhs, const LUC::PrivateKey& rhs) {
return lhs.GetModulus() == rhs.GetModulus() &&
lhs.GetPublicExponent() == rhs.GetPublicExponent() &&
@@ -71,6 +80,15 @@ inline bool operator!=(const LUC::PrivateKey& lhs, const LUC::PrivateKey& rhs) {
return !operator==(lhs, rhs);
}
+inline bool operator==(const LUC::PublicKey& lhs, const LUC::PublicKey& rhs) {
+ return lhs.GetModulus() == rhs.GetModulus() &&
+ lhs.GetPublicExponent() == rhs.GetPublicExponent();
+}
+
+inline bool operator!=(const LUC::PublicKey& lhs, const LUC::PublicKey& rhs) {
+ return !operator==(lhs, rhs);
+}
+
inline bool operator==(const Rabin::PrivateKey& lhs, const Rabin::PrivateKey& rhs) {
return lhs.GetModulus() == rhs.GetModulus() &&
lhs.GetQuadraticResidueModPrime1() == rhs.GetQuadraticResidueModPrime1() &&
@@ -118,6 +136,15 @@ bool ValidateRSA_Encrypt()
std::cout << (fail ? "FAILED " : "passed ");
std::cout << "RSA::PrivateKey initialization\n";
+
+ RSA::PublicKey rsaPub2;
+ rsaPub2.Initialize(n, e);
+
+ fail = (rsaPub != rsaPub2);
+ pass = pass && !fail;
+
+ std::cout << (fail ? "FAILED " : "passed ");
+ std::cout << "RSA::PublicKey initialization\n";
}
{
FileSource keys(DataDir("TestData/rsa1024.dat").c_str(), true, new HexDecoder);
@@ -209,6 +236,15 @@ bool ValidateLUC_Encrypt()
std::cout << (fail ? "FAILED " : "passed ");
std::cout << "LUC::PrivateKey initialization\n";
+
+ LUC::PublicKey lucPub2;
+ lucPub2.Initialize(n, e);
+
+ fail = (lucPub != lucPub2);
+ pass = pass && !fail;
+
+ std::cout << (fail ? "FAILED " : "passed ");
+ std::cout << "LUC::PublicKey initialization\n";
}
{
FileSource keys(DataDir("TestData/luc1024.dat").c_str(), true, new HexDecoder);
@@ -226,6 +262,23 @@ bool ValidateLUC_Encrypt()
std::cout << (fail ? "FAILED " : "passed ");
std::cout << "LUC::PrivateKey encoding and decoding\n";
}
+ {
+ FileSource keys(DataDir("TestData/rabi1024.dat").c_str(), true, new HexDecoder);
+ LUC::PrivateKey lucPriv; lucPriv.BERDecode(keys);
+ LUC::PublicKey lucPub(lucPriv);
+
+ ByteQueue q;
+ lucPub.DEREncode(q);
+
+ LUC::PublicKey lucPub2;
+ lucPub2.BERDecode(q);
+
+ fail = (lucPub != lucPub2);
+ pass = pass && !fail;
+
+ std::cout << (fail ? "FAILED " : "passed ");
+ std::cout << "LUC::PublicKey encoding and decoding\n";
+ }
#endif
LUCES_OAEP_SHA_Decryptor priv(GlobalRNG(), 512);