summaryrefslogtreecommitdiff
path: root/datatest.cpp
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2013-01-19 02:20:00 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2013-01-19 02:20:00 +0000
commit6282aab71c9f925b533065e4dbfce632b83ee4ac (patch)
tree0489fdbd8b1c5c6f87537d4136dcf1afeecb0bd8 /datatest.cpp
parent34c4e67c9abc9402c95a6b9533fbbae6b486be63 (diff)
downloadcryptopp-6282aab71c9f925b533065e4dbfce632b83ee4ac.tar.gz
add SHA-3
update DSA to FIPS 186-3 update version numbers git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@535 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'datatest.cpp')
-rw-r--r--datatest.cpp89
1 files changed, 47 insertions, 42 deletions
diff --git a/datatest.cpp b/datatest.cpp
index 9396816..7a1a9cf 100644
--- a/datatest.cpp
+++ b/datatest.cpp
@@ -14,6 +14,7 @@ USING_NAMESPACE(CryptoPP)
USING_NAMESPACE(std)
typedef std::map<std::string, std::string> TestData;
+static bool s_thorough;
class TestFailure : public Exception
{
@@ -186,18 +187,17 @@ private:
void TestKeyPairValidAndConsistent(CryptoMaterial &pub, const CryptoMaterial &priv)
{
- if (!pub.Validate(GlobalRNG(), 3))
+ if (!pub.Validate(GlobalRNG(), 2+s_thorough))
SignalTestFailure();
- if (!priv.Validate(GlobalRNG(), 3))
+ if (!priv.Validate(GlobalRNG(), 2+s_thorough))
SignalTestFailure();
-/* EqualityComparisonFilter comparison;
- pub.Save(ChannelSwitch(comparison, "0"));
+ ByteQueue bq1, bq2;
+ pub.Save(bq1);
pub.AssignFrom(priv);
- pub.Save(ChannelSwitch(comparison, "1"));
- comparison.ChannelMessageSeriesEnd("0");
- comparison.ChannelMessageSeriesEnd("1");
-*/
+ pub.Save(bq2);
+ if (bq1 != bq2)
+ SignalTestFailure();
}
void TestSignatureScheme(TestData &v)
@@ -209,41 +209,50 @@ void TestSignatureScheme(TestData &v)
std::auto_ptr<PK_Verifier> verifier(ObjectFactoryRegistry<PK_Verifier>::Registry().CreateObject(name.c_str()));
TestDataNameValuePairs pairs(v);
- std::string keyFormat = GetRequiredDatum(v, "KeyFormat");
-
- if (keyFormat == "DER")
- verifier->AccessMaterial().Load(StringStore(GetDecodedDatum(v, "PublicKey")).Ref());
- else if (keyFormat == "Component")
- verifier->AccessMaterial().AssignFrom(pairs);
- if (test == "Verify" || test == "NotVerify")
+ if (test == "GenerateKey")
{
- VerifierFilter verifierFilter(*verifier, NULL, VerifierFilter::SIGNATURE_AT_BEGIN);
- PutDecodedDatumInto(v, "Signature", verifierFilter);
- PutDecodedDatumInto(v, "Message", verifierFilter);
- verifierFilter.MessageEnd();
- if (verifierFilter.GetLastResult() == (test == "NotVerify"))
- SignalTestFailure();
- }
- else if (test == "PublicKeyValid")
- {
- if (!verifier->GetMaterial().Validate(GlobalRNG(), 3))
- SignalTestFailure();
+ signer->AccessPrivateKey().GenerateRandom(GlobalRNG(), pairs);
+ verifier->AccessPublicKey().AssignFrom(signer->AccessPrivateKey());
}
else
- goto privateKeyTests;
+ {
+ std::string keyFormat = GetRequiredDatum(v, "KeyFormat");
- return;
+ if (keyFormat == "DER")
+ verifier->AccessMaterial().Load(StringStore(GetDecodedDatum(v, "PublicKey")).Ref());
+ else if (keyFormat == "Component")
+ verifier->AccessMaterial().AssignFrom(pairs);
-privateKeyTests:
- if (keyFormat == "DER")
- signer->AccessMaterial().Load(StringStore(GetDecodedDatum(v, "PrivateKey")).Ref());
- else if (keyFormat == "Component")
- signer->AccessMaterial().AssignFrom(pairs);
-
- if (test == "KeyPairValidAndConsistent")
+ if (test == "Verify" || test == "NotVerify")
+ {
+ VerifierFilter verifierFilter(*verifier, NULL, VerifierFilter::SIGNATURE_AT_BEGIN);
+ PutDecodedDatumInto(v, "Signature", verifierFilter);
+ PutDecodedDatumInto(v, "Message", verifierFilter);
+ verifierFilter.MessageEnd();
+ if (verifierFilter.GetLastResult() == (test == "NotVerify"))
+ SignalTestFailure();
+ return;
+ }
+ else if (test == "PublicKeyValid")
+ {
+ if (!verifier->GetMaterial().Validate(GlobalRNG(), 3))
+ SignalTestFailure();
+ return;
+ }
+
+ if (keyFormat == "DER")
+ signer->AccessMaterial().Load(StringStore(GetDecodedDatum(v, "PrivateKey")).Ref());
+ else if (keyFormat == "Component")
+ signer->AccessMaterial().AssignFrom(pairs);
+ }
+
+ if (test == "GenerateKey" || test == "KeyPairValidAndConsistent")
{
TestKeyPairValidAndConsistent(verifier->AccessMaterial(), signer->GetMaterial());
+ VerifierFilter verifierFilter(*verifier, NULL, VerifierFilter::THROW_EXCEPTION);
+ verifierFilter.Put((const byte *)"abc", 3);
+ StringSource ss("abc", true, new SignerFilter(GlobalRNG(), *signer, new Redirector(verifierFilter)));
}
else if (test == "Sign")
{
@@ -261,11 +270,6 @@ privateKeyTests:
SignalTestError();
assert(false); // TODO: implement
}
- else if (test == "GenerateKey")
- {
- SignalTestError();
- assert(false);
- }
else
{
SignalTestError();
@@ -684,7 +688,7 @@ void TestDataFile(const std::string &filename, const NameValuePairs &overridePar
break;
v[name] = value;
- if (name == "Test")
+ if (name == "Test" && (s_thorough || v["SlowTest"] != "1"))
{
bool failed = true;
std::string algType = GetRequiredDatum(v, "AlgorithmType");
@@ -741,8 +745,9 @@ void TestDataFile(const std::string &filename, const NameValuePairs &overridePar
}
}
-bool RunTestDataFile(const char *filename, const NameValuePairs &overrideParameters)
+bool RunTestDataFile(const char *filename, const NameValuePairs &overrideParameters, bool thorough)
{
+ s_thorough = thorough;
unsigned int totalTests = 0, failedTests = 0;
TestDataFile(filename, overrideParameters, totalTests, failedTests);
cout << dec << "\nTests complete. Total tests = " << totalTests << ". Failed tests = " << failedTests << ".\n";