Cut-in determinsitic signature verification during signing
parent
79c231edcb
commit
9cc0c47f7b
40
datatest.cpp
40
datatest.cpp
|
|
@ -290,9 +290,12 @@ void TestSignatureScheme(TestData &v)
|
||||||
// for DSA and ECDSA, and access to the seed or secret is not needed. If
|
// for DSA and ECDSA, and access to the seed or secret is not needed. If
|
||||||
// additional determinsitic signatures are added, then the test harness will
|
// additional determinsitic signatures are added, then the test harness will
|
||||||
// likely need to be extended.
|
// likely need to be extended.
|
||||||
SignerFilter f(GlobalRNG(), *signer, new HexEncoder(new FileSink(cout)));
|
string signature;
|
||||||
|
SignerFilter f(GlobalRNG(), *signer, new HexEncoder(new StringSink(signature)));
|
||||||
StringSource ss(GetDecodedDatum(v, "Message"), true, new Redirector(f));
|
StringSource ss(GetDecodedDatum(v, "Message"), true, new Redirector(f));
|
||||||
SignalTestFailure();
|
if (GetDecodedDatum(v, "Signature") != signature)
|
||||||
|
SignalTestFailure();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else if (test == "RandomSign")
|
else if (test == "RandomSign")
|
||||||
{
|
{
|
||||||
|
|
@ -610,7 +613,7 @@ void TestDigestOrMAC(TestData &v, bool testDigest)
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestKeyDerivationFunction(TestData &v)
|
void TestKeyDerivationFunction(TestData &v)
|
||||||
{
|
{
|
||||||
std::string name = GetRequiredDatum(v, "Name");
|
std::string name = GetRequiredDatum(v, "Name");
|
||||||
std::string test = GetRequiredDatum(v, "Test");
|
std::string test = GetRequiredDatum(v, "Test");
|
||||||
|
|
||||||
|
|
@ -622,13 +625,13 @@ void TestKeyDerivationFunction(TestData &v)
|
||||||
std::string info = GetDecodedDatum(v, "Info");
|
std::string info = GetDecodedDatum(v, "Info");
|
||||||
std::string derived = GetDecodedDatum(v, "DerivedKey");
|
std::string derived = GetDecodedDatum(v, "DerivedKey");
|
||||||
std::string t = GetDecodedDatum(v, "DerivedKeyLength");
|
std::string t = GetDecodedDatum(v, "DerivedKeyLength");
|
||||||
|
|
||||||
TestDataNameValuePairs pairs(v);
|
TestDataNameValuePairs pairs(v);
|
||||||
unsigned int length = pairs.GetIntValueWithDefault(Name::DerivedKeyLength(), (int)derived.size());
|
unsigned int length = pairs.GetIntValueWithDefault(Name::DerivedKeyLength(), (int)derived.size());
|
||||||
|
|
||||||
member_ptr<KeyDerivationFunction> kdf;
|
member_ptr<KeyDerivationFunction> kdf;
|
||||||
kdf.reset(ObjectFactoryRegistry<KeyDerivationFunction>::Registry().CreateObject(name.c_str()));
|
kdf.reset(ObjectFactoryRegistry<KeyDerivationFunction>::Registry().CreateObject(name.c_str()));
|
||||||
|
|
||||||
std::string calc; calc.resize(length);
|
std::string calc; calc.resize(length);
|
||||||
unsigned int ret = kdf->DeriveKey(reinterpret_cast<byte*>(&calc[0]), calc.size(),
|
unsigned int ret = kdf->DeriveKey(reinterpret_cast<byte*>(&calc[0]), calc.size(),
|
||||||
reinterpret_cast<const byte*>(key.data()), key.size(),
|
reinterpret_cast<const byte*>(key.data()), key.size(),
|
||||||
|
|
@ -644,11 +647,6 @@ bool GetField(std::istream &is, std::string &name, std::string &value)
|
||||||
name.resize(0); // GCC workaround: 2.95.3 doesn't have clear()
|
name.resize(0); // GCC workaround: 2.95.3 doesn't have clear()
|
||||||
is >> name;
|
is >> name;
|
||||||
|
|
||||||
#if defined(__COVERITY__)
|
|
||||||
// The datafile being read is in /usr/share, and it protected by filesystem ACLs
|
|
||||||
// __coverity_tainted_data_sanitize__(reinterpret_cast<void*>(&name));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (name.empty())
|
if (name.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
@ -668,7 +666,7 @@ bool GetField(std::istream &is, std::string &name, std::string &value)
|
||||||
// VC60 workaround: getline bug
|
// VC60 workaround: getline bug
|
||||||
char buffer[128];
|
char buffer[128];
|
||||||
value.resize(0); // GCC workaround: 2.95.3 doesn't have clear()
|
value.resize(0); // GCC workaround: 2.95.3 doesn't have clear()
|
||||||
bool continueLine;
|
bool continueLine, space = false;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|
@ -676,6 +674,8 @@ bool GetField(std::istream &is, std::string &name, std::string &value)
|
||||||
{
|
{
|
||||||
is.get(buffer, sizeof(buffer));
|
is.get(buffer, sizeof(buffer));
|
||||||
value += buffer;
|
value += buffer;
|
||||||
|
if (buffer[0] == ' ')
|
||||||
|
space = true;
|
||||||
}
|
}
|
||||||
while (buffer[0] != 0);
|
while (buffer[0] != 0);
|
||||||
is.clear();
|
is.clear();
|
||||||
|
|
@ -698,6 +698,23 @@ bool GetField(std::istream &is, std::string &name, std::string &value)
|
||||||
}
|
}
|
||||||
while (continueLine);
|
while (continueLine);
|
||||||
|
|
||||||
|
// Strip intermediate spaces for some values.
|
||||||
|
if (space && (name == "Modulus" || name == "SubgroupOrder" || name == "SubgroupGenerator" ||
|
||||||
|
name == "PublicElement" || name == "PrivateExponent" || name == "Signature"))
|
||||||
|
{
|
||||||
|
string temp;
|
||||||
|
temp.reserve(value.size());
|
||||||
|
|
||||||
|
std::string::const_iterator it;
|
||||||
|
for(it = value.begin(); it != value.end(); it++)
|
||||||
|
{
|
||||||
|
if(*it != ' ')
|
||||||
|
temp.push_back(*it);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::swap(temp, value);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -829,3 +846,4 @@ bool RunTestDataFile(const char *filename, const NameValuePairs &overrideParamet
|
||||||
cout << "SOME TESTS FAILED!\n";
|
cout << "SOME TESTS FAILED!\n";
|
||||||
return failedTests == 0;
|
return failedTests == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue