summaryrefslogtreecommitdiff
path: root/datatest.cpp
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2003-03-26 21:50:44 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2003-03-26 21:50:44 +0000
commit0a0244dacface689335de6e0edf978b29ddb66e1 (patch)
treeef84fa621368e7bce53a7708b5188ae8df1d9ed3 /datatest.cpp
parent79694912becd37f5f0077464350f3db55dd2ca7c (diff)
downloadcryptopp-0a0244dacface689335de6e0edf978b29ddb66e1.tar.gz
fix bugs in SEAL and Panama
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@54 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'datatest.cpp')
-rw-r--r--datatest.cpp41
1 files changed, 39 insertions, 2 deletions
diff --git a/datatest.cpp b/datatest.cpp
index 50b26fe..1307760 100644
--- a/datatest.cpp
+++ b/datatest.cpp
@@ -197,7 +197,7 @@ privateKeyTests:
}
}
-void TestEncryptionScheme(TestData &v)
+void TestAsymmetricCipher(TestData &v)
{
std::string name = GetRequiredDatum(v, "Name");
std::string test = GetRequiredDatum(v, "Test");
@@ -237,6 +237,41 @@ void TestEncryptionScheme(TestData &v)
}
}
+void TestSymmetricCipher(TestData &v)
+{
+ std::string name = GetRequiredDatum(v, "Name");
+ std::string test = GetRequiredDatum(v, "Test");
+
+ std::string key = GetDecodedDatum(v, "Key");
+ std::string iv = GetDecodedDatum(v, "IV");
+ std::string ciphertext = GetDecodedDatum(v, "Ciphertext");
+ std::string plaintext = GetDecodedDatum(v, "Plaintext");
+
+ if (test == "Encrypt")
+ {
+ std::auto_ptr<SymmetricCipher> encryptor(ObjectFactoryRegistry<SymmetricCipher, ENCRYPTION>::Registry().CreateObject(name.c_str()));
+ encryptor->SetKeyWithIV((const byte *)key.data(), key.size(), (const byte *)iv.data());
+ std::string encrypted;
+ StringSource ss(plaintext, true, new StreamTransformationFilter(*encryptor, new StringSink(encrypted), StreamTransformationFilter::NO_PADDING));
+ if (encrypted != ciphertext)
+ SignalTestFailure();
+ }
+ else if (test == "Decrypt")
+ {
+ std::auto_ptr<SymmetricCipher> decryptor(ObjectFactoryRegistry<SymmetricCipher, DECRYPTION>::Registry().CreateObject(name.c_str()));
+ decryptor->SetKeyWithIV((const byte *)key.data(), key.size(), (const byte *)iv.data());
+ std::string decrypted;
+ StringSource ss(ciphertext, true, new StreamTransformationFilter(*decryptor, new StringSink(decrypted), StreamTransformationFilter::NO_PADDING));
+ if (decrypted != plaintext)
+ SignalTestFailure();
+ }
+ else
+ {
+ SignalTestError();
+ assert(false);
+ }
+}
+
void TestDigestOrMAC(TestData &v, bool testDigest)
{
std::string name = GetRequiredDatum(v, "Name");
@@ -391,8 +426,10 @@ void TestDataFile(const std::string &filename, unsigned int &totalTests, unsigne
{
if (algType == "Signature")
TestSignatureScheme(v);
+ else if (algType == "SymmetricCipher")
+ TestSymmetricCipher(v);
else if (algType == "AsymmetricCipher")
- TestEncryptionScheme(v);
+ TestAsymmetricCipher(v);
else if (algType == "MessageDigest")
TestDigestOrMAC(v, true);
else if (algType == "MAC")