summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bench1.cpp99
-rw-r--r--validat3.cpp132
-rw-r--r--validat5.cpp48
-rw-r--r--validat6.cpp26
-rw-r--r--validate.h27
5 files changed, 158 insertions, 174 deletions
diff --git a/bench1.cpp b/bench1.cpp
index 11dee0be..714a8637 100644
--- a/bench1.cpp
+++ b/bench1.cpp
@@ -13,6 +13,10 @@
#include "smartptr.h"
#include "stdcpp.h"
+#include <iostream>
+#include <iomanip>
+#include <sstream>
+
#if CRYPTOPP_MSC_VERSION
# pragma warning(disable: 4355)
#endif
@@ -32,7 +36,7 @@ const double CLOCK_TICKS_PER_SECOND = (double)CLK_TCK;
const double CLOCK_TICKS_PER_SECOND = 1000000.0;
#endif
-const byte defaultKey[] = "0123456789" // 168 + NULL
+extern const byte defaultKey[] = "0123456789" // 168 + NULL
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
"00000000000000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000";
@@ -43,67 +47,70 @@ time_t g_testBegin, g_testEnd;
void OutputResultBytes(const char *name, const char *provider, double length, double timeTaken)
{
- // Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
- StreamState ss(std::cout);
+ std::ostringstream oss;
// Coverity finding
if (length < 0.000001f) length = 0.000001f;
if (timeTaken < 0.000001f) timeTaken = 0.000001f;
double mbs = length / timeTaken / (1024*1024);
- std::cout << "\n<TR><TD>" << name << "<TD>" << provider;
- std::cout << std::setiosflags(std::ios::fixed);
- std::cout << "<TD>" << std::setprecision(0) << std::setiosflags(std::ios::fixed) << mbs;
+ oss << "\n<TR><TD>" << name << "<TD>" << provider;
+ oss << std::setiosflags(std::ios::fixed);
+ oss << "<TD>" << std::setprecision(0) << std::setiosflags(std::ios::fixed) << mbs;
if (g_hertz > 1.0f)
{
const double cpb = timeTaken * g_hertz / length;
if (cpb < 24.0f)
- std::cout << "<TD>" << std::setprecision(2) << std::setiosflags(std::ios::fixed) << cpb;
+ oss << "<TD>" << std::setprecision(2) << std::setiosflags(std::ios::fixed) << cpb;
else
- std::cout << "<TD>" << std::setprecision(1) << std::setiosflags(std::ios::fixed) << cpb;
+ oss << "<TD>" << std::setprecision(1) << std::setiosflags(std::ios::fixed) << cpb;
}
g_logTotal += log(mbs);
g_logCount++;
+
+ std::cout << oss.str();
}
void OutputResultKeying(double iterations, double timeTaken)
{
- // Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
- StreamState ss(std::cout);
+ std::ostringstream oss;
// Coverity finding
if (iterations < 0.000001f) iterations = 0.000001f;
if (timeTaken < 0.000001f) timeTaken = 0.000001f;
- std::cout << "<TD>" << std::setprecision(3) << std::setiosflags(std::ios::fixed) << (1000*1000*timeTaken/iterations);
+ oss << "<TD>" << std::setprecision(3) << std::setiosflags(std::ios::fixed) << (1000*1000*timeTaken/iterations);
// Coverity finding
if (g_hertz > 1.0f)
- std::cout << "<TD>" << std::setprecision(0) << std::setiosflags(std::ios::fixed) << timeTaken * g_hertz / iterations;
+ oss << "<TD>" << std::setprecision(0) << std::setiosflags(std::ios::fixed) << timeTaken * g_hertz / iterations;
+
+ std::cout << oss.str();
}
void OutputResultOperations(const char *name, const char *provider, const char *operation, bool pc, unsigned long iterations, double timeTaken)
{
- // Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
- StreamState ss(std::cout);
+ std::ostringstream oss;
// Coverity finding
if (!iterations) iterations++;
if (timeTaken < 0.000001f) timeTaken = 0.000001f;
- std::cout << "\n<TR><TD>" << name << " " << operation << (pc ? " with precomputation" : "");
- std::cout << "<TD>" << provider;
- std::cout << "<TD>" << std::setprecision(2) << std::setiosflags(std::ios::fixed) << (1000*timeTaken/iterations);
+ oss << "\n<TR><TD>" << name << " " << operation << (pc ? " with precomputation" : "");
+ oss << "<TD>" << provider;
+ oss << "<TD>" << std::setprecision(2) << std::setiosflags(std::ios::fixed) << (1000*timeTaken/iterations);
// Coverity finding
if (g_hertz > 1.0f)
{
const double t = timeTaken * g_hertz / iterations / 1000000;
- std::cout << "<TD>" << std::setprecision(2) << std::setiosflags(std::ios::fixed) << t;
+ oss << "<TD>" << std::setprecision(2) << std::setiosflags(std::ios::fixed) << t;
}
g_logTotal += log(iterations/timeTaken);
g_logCount++;
+
+ std::cout << oss.str();
}
/*
@@ -276,34 +283,40 @@ void BenchMarkByNameKeyLess(const char *factoryName, const char *displayName = N
void AddHtmlHeader()
{
+ std::ostringstream oss;
+
// HTML5
- std::cout << "<!DOCTYPE HTML>";
- std::cout << "\n<HTML lang=\"en\">";
+ oss << "<!DOCTYPE HTML>";
+ oss << "\n<HTML lang=\"en\">";
- std::cout << "\n<HEAD>";
- std::cout << "\n<META charset=\"UTF-8\">";
- std::cout << "\n<TITLE>Speed Comparison of Popular Crypto Algorithms</TITLE>";
- std::cout << "\n<STYLE>\n table {border-collapse: collapse;}";
- std::cout << "\n table, th, td, tr {border: 1px solid black;}\n</STYLE>";
- std::cout << "\n</HEAD>";
+ oss << "\n<HEAD>";
+ oss << "\n<META charset=\"UTF-8\">";
+ oss << "\n<TITLE>Speed Comparison of Popular Crypto Algorithms</TITLE>";
+ oss << "\n<STYLE>\n table {border-collapse: collapse;}";
+ oss << "\n table, th, td, tr {border: 1px solid black;}\n</STYLE>";
+ oss << "\n</HEAD>";
- std::cout << "\n<BODY>";
+ oss << "\n<BODY>";
- std::cout << "\n<H1><A href=\"http://www.cryptopp.com\">Crypto++</A> " << CRYPTOPP_VERSION / 100;
- std::cout << '.' << (CRYPTOPP_VERSION % 100) / 10 << '.' << CRYPTOPP_VERSION % 10 << " Benchmarks</H1>";
+ oss << "\n<H1><A href=\"http://www.cryptopp.com\">Crypto++</A> " << CRYPTOPP_VERSION / 100;
+ oss << '.' << (CRYPTOPP_VERSION % 100) / 10 << '.' << CRYPTOPP_VERSION % 10 << " Benchmarks</H1>";
- std::cout << "\n<P>Here are speed benchmarks for some commonly used cryptographic algorithms.</P>";
+ oss << "\n<P>Here are speed benchmarks for some commonly used cryptographic algorithms.</P>";
if (g_hertz > 1.0f)
- std::cout << "\n<P>CPU frequency of the test platform is " << g_hertz << " Hz.</P>";
+ oss << "\n<P>CPU frequency of the test platform is " << g_hertz << " Hz.</P>";
else
- std::cout << "\n<P>CPU frequency of the test platform was not provided.</P>" << std::endl;
+ oss << "\n<P>CPU frequency of the test platform was not provided.</P>" << std::endl;
+
+ std::cout << oss.str();
}
void AddHtmlFooter()
{
+ std::ostringstream oss;
std::cout << "\n</BODY>";
std::cout << "\n</HTML>" << std::endl;
+ std::cout << oss.str();
}
void BenchmarkWithCommand(int argc, const char* const argv[])
@@ -327,6 +340,7 @@ void Benchmark(Test::TestClass suites, double t, double hertz)
{
g_allocatedTime = t;
g_hertz = hertz;
+ std::ostringstream oss;
AddHtmlHeader();
@@ -338,37 +352,36 @@ void Benchmark(Test::TestClass suites, double t, double hertz)
// Unkeyed algorithms
if (suites & Test::Unkeyed)
{
- std::cout << "\n<BR>";
+ oss << "\n<BR>";
Benchmark1(t, hertz);
}
// Shared key algorithms
if (suites & Test::SharedKey)
{
- std::cout << "\n<BR>";
+ oss << "\n<BR>";
Benchmark2(t, hertz);
}
// Public key algorithms
if (suites & Test::PublicKey)
{
- std::cout << "\n<BR>";
+ oss << "\n<BR>";
Benchmark3(t, hertz);
}
g_testEnd = ::time(NULLPTR);
- {
- StreamState state(std::cout);
- std::cout << "\n<P>Throughput Geometric Average: " << std::setiosflags(std::ios::fixed);
- std::cout << std::exp(g_logTotal/(g_logCount > 0.0f ? g_logCount : 1.0f)) << std::endl;
- }
+ oss << "\n<P>Throughput Geometric Average: " << std::setiosflags(std::ios::fixed);
+ oss << std::exp(g_logTotal/(g_logCount > 0.0f ? g_logCount : 1.0f)) << std::endl;
- std::cout << "\n<P>Test started at " << TimeToString(g_testBegin);
- std::cout << "\n<BR>Test ended at " << TimeToString(g_testEnd);
- std::cout << std::endl;
+ oss << "\n<P>Test started at " << TimeToString(g_testBegin);
+ oss << "\n<BR>Test ended at " << TimeToString(g_testEnd);
+ oss << std::endl;
AddHtmlFooter();
+
+ std::cout << oss.str();
}
void Benchmark1(double t, double hertz)
diff --git a/validat3.cpp b/validat3.cpp
index e393715d..218b08c1 100644
--- a/validat3.cpp
+++ b/validat3.cpp
@@ -1061,6 +1061,9 @@ bool TestMersenne()
bool pass = true, fail = false;
member_ptr<RandomNumberGenerator> rng;
+ std::ostringstream oss;
+ oss << std::setiosflags(std::ios::fixed) << std::setprecision(6);
+
try {rng.reset(new PadlockRNG);}
catch (const PadlockRNG_Err &) {}
if (rng.get())
@@ -1081,37 +1084,37 @@ bool TestMersenne()
fail = !(msr & (1 << 6U));
pass &= !fail;
if (fail)
- std::cout << "FAILED:";
+ oss << "FAILED:";
else
- std::cout << "passed:";
- std::cout << " VIA RNG is activated\n";
+ oss << "passed:";
+ oss << " VIA RNG is activated\n";
// Bit 13 should be unset
fail = !!(msr & (1 << 13U));
pass &= !fail;
if (fail)
- std::cout << "FAILED:";
+ oss << "FAILED:";
else
- std::cout << "passed:";
- std::cout << " von Neumann corrector is activated\n";
+ oss << "passed:";
+ oss << " von Neumann corrector is activated\n";
// Bit 14 should be unset
fail = !!(msr & (1 << 14U));
pass &= !fail;
if (fail)
- std::cout << "FAILED:";
+ oss << "FAILED:";
else
- std::cout << "passed:";
- std::cout << " String filter is deactivated\n";
+ oss << "passed:";
+ oss << " String filter is deactivated\n";
// Bit 12:10 should be unset
fail = !!(msr & (0x7 << 10U));
pass &= !fail;
if (fail)
- std::cout << "FAILED:";
+ oss << "FAILED:";
else
- std::cout << "passed:";
- std::cout << " Bias voltage is unmodified\n";
+ oss << "passed:";
+ oss << " Bias voltage is unmodified\n";
fail = false;
if (t == zero || t == one)
@@ -1119,10 +1122,10 @@ bool TestMersenne()
pass &= !fail;
if (fail)
- std::cout << "FAILED:";
+ oss << "FAILED:";
else
- std::cout << "passed:";
- std::cout << " All 0's or all 1's test\n";
+ oss << "passed:";
+ oss << " All 0's or all 1's test\n";
MeterFilter meter(new Redirector(TheBitBucket()));
Deflator deflator(new Redirector(meter));
@@ -1141,16 +1144,12 @@ bool TestMersenne()
if (mv < 0.98f)
fail = true;
- // Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
- StreamState ss(std::cout);
- std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(6);
-
pass &= !fail;
if (fail)
- std::cout << "FAILED:";
+ oss << "FAILED:";
else
- std::cout << "passed:";
- std::cout << " Maurer Randomness Test returned value " << mv << "\n";
+ oss << "passed:";
+ oss << " Maurer Randomness Test returned value " << mv << "\n";
fail = false;
if (meter.GetTotalBytes() < SIZE)
@@ -1158,10 +1157,10 @@ bool TestMersenne()
pass &= !fail;
if (fail)
- std::cout << "FAILED:";
+ oss << "FAILED:";
else
- std::cout << "passed:";
- std::cout << " " << SIZE << " generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE\n";
+ oss << "passed:";
+ oss << " " << SIZE << " generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE\n";
try
{
@@ -1175,10 +1174,10 @@ bool TestMersenne()
pass &= !fail;
if (fail)
- std::cout << "FAILED:";
+ oss << "FAILED:";
else
- std::cout << "passed:";
- std::cout << " discarded " << SIZE << " bytes\n";
+ oss << "passed:";
+ oss << " discarded " << SIZE << " bytes\n";
try
{
@@ -1202,14 +1201,15 @@ bool TestMersenne()
pass &= !fail;
if (fail)
- std::cout << "FAILED:";
+ oss << "FAILED:";
else
- std::cout << "passed:";
- std::cout << " GenerateWord32 and Crop\n";
+ oss << "passed:";
+ oss << " GenerateWord32 and Crop\n";
}
else
- std::cout << "Padlock RNG generator not available, skipping test.\n";
+ oss << "Padlock RNG generator not available, skipping test.\n";
+ std::cout << oss.str();
return pass;
}
@@ -1220,6 +1220,9 @@ bool TestRDRAND()
bool pass = true, fail = false;
member_ptr<RandomNumberGenerator> rng;
+ std::ostringstream oss;
+ oss << std::setiosflags(std::ios::fixed) << std::setprecision(6);
+
try {rng.reset(new RDRAND);}
catch (const RDRAND_Err &) {}
if (rng.get())
@@ -1243,16 +1246,12 @@ bool TestRDRAND()
if (mv < 0.98f)
fail = true;
- // Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
- StreamState ss(std::cout);
- std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(6);
-
pass &= !fail;
if (fail)
- std::cout << "FAILED:";
+ oss << "FAILED:";
else
- std::cout << "passed:";
- std::cout << " Maurer Randomness Test returned value " << mv << "\n";
+ oss << "passed:";
+ oss << " Maurer Randomness Test returned value " << mv << "\n";
fail = false;
if (meter.GetTotalBytes() < SIZE)
@@ -1260,10 +1259,10 @@ bool TestRDRAND()
pass &= !fail;
if (fail)
- std::cout << "FAILED:";
+ oss << "FAILED:";
else
- std::cout << "passed:";
- std::cout << " " << SIZE << " generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE\n";
+ oss << "passed:";
+ oss << " " << SIZE << " generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE\n";
try
{
@@ -1277,10 +1276,10 @@ bool TestRDRAND()
pass &= !fail;
if (fail)
- std::cout << "FAILED:";
+ oss << "FAILED:";
else
- std::cout << "passed:";
- std::cout << " discarded " << SIZE << " bytes\n";
+ oss << "passed:";
+ oss << " discarded " << SIZE << " bytes\n";
try
{
@@ -1304,14 +1303,15 @@ bool TestRDRAND()
pass &= !fail;
if (fail)
- std::cout << "FAILED:";
+ oss << "FAILED:";
else
- std::cout << "passed:";
- std::cout << " GenerateWord32 and Crop\n";
+ oss << "passed:";
+ oss << " GenerateWord32 and Crop\n";
}
else
- std::cout << "RDRAND generator not available, skipping test.\n";
+ oss << "RDRAND generator not available, skipping test.\n";
+ std::cout << oss.str();
return pass;
}
@@ -1322,6 +1322,9 @@ bool TestRDSEED()
bool pass = true, fail = false;
member_ptr<RandomNumberGenerator> rng;
+ std::ostringstream oss;
+ oss << std::setiosflags(std::ios::fixed) << std::setprecision(6);
+
try {rng.reset(new RDSEED);}
catch (const RDSEED_Err &) {}
if (rng.get())
@@ -1345,16 +1348,12 @@ bool TestRDSEED()
if (mv < 0.98f)
fail = true;
- // Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
- StreamState ss(std::cout);
- std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(6);
-
pass &= !fail;
if (fail)
- std::cout << "FAILED:";
+ oss << "FAILED:";
else
- std::cout << "passed:";
- std::cout << " Maurer Randomness Test returned value " << mv << "\n";
+ oss << "passed:";
+ oss << " Maurer Randomness Test returned value " << mv << "\n";
fail = false;
if (meter.GetTotalBytes() < SIZE)
@@ -1362,10 +1361,10 @@ bool TestRDSEED()
pass &= !fail;
if (fail)
- std::cout << "FAILED:";
+ oss << "FAILED:";
else
- std::cout << "passed:";
- std::cout << " " << SIZE << " generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE\n";
+ oss << "passed:";
+ oss << " " << SIZE << " generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE\n";
try
{
@@ -1379,10 +1378,10 @@ bool TestRDSEED()
pass &= !fail;
if (fail)
- std::cout << "FAILED:";
+ oss << "FAILED:";
else
- std::cout << "passed:";
- std::cout << " discarded " << SIZE << " bytes\n";
+ oss << "passed:";
+ oss << " discarded " << SIZE << " bytes\n";
try
{
@@ -1406,14 +1405,15 @@ bool TestRDSEED()
pass &= !fail;
if (fail)
- std::cout << "FAILED:";
+ oss << "FAILED:";
else
- std::cout << "passed:";
- std::cout << " GenerateWord32 and Crop\n";
+ oss << "passed:";
+ oss << " GenerateWord32 and Crop\n";
}
else
- std::cout << "RDSEED generator not available, skipping test.\n";
+ oss << "RDSEED generator not available, skipping test.\n";
+ std::cout << oss.str();
return pass;
}
#endif
diff --git a/validat5.cpp b/validat5.cpp
index 44c004a9..b0b27849 100644
--- a/validat5.cpp
+++ b/validat5.cpp
@@ -69,10 +69,9 @@ struct HashTestTuple
bool HashModuleTest(HashTransformation &md, const HashTestTuple *testSet, unsigned int testSetSize)
{
bool pass=true, fail;
- SecByteBlock digest(md.DigestSize());
+ std::ostringstream oss;
- // Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
- StreamState ss(std::cout);
+ SecByteBlock digest(md.DigestSize());
for (unsigned int i=0; i<testSetSize; i++)
{
unsigned j;
@@ -83,15 +82,16 @@ bool HashModuleTest(HashTransformation &md, const HashTestTuple *testSet, unsign
fail = !!memcmp(digest, testSet[i].output, md.DigestSize()) != 0;
pass = pass && !fail;
- std::cout << (fail ? "FAILED " : "passed ");
+ oss << (fail ? "FAILED " : "passed ");
for (j=0; j<md.DigestSize(); j++)
- std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)digest[j];
- std::cout << " \"" << (char *)testSet[i].input << '\"';
+ oss << std::setw(2) << std::setfill('0') << std::hex << (int)digest[j];
+ oss << " \"" << (char *)testSet[i].input << '\"';
if (testSet[i].repeatTimes != 1)
- std::cout << " repeated " << std::dec << testSet[i].repeatTimes << " times";
- std::cout << std::endl;
+ oss << " repeated " << std::dec << testSet[i].repeatTimes << " times";
+ oss << std::endl;
}
+ std::cout << oss.str();
return pass;
}
@@ -407,21 +407,19 @@ bool ValidateMD5MAC()
{0x18,0xe3,0x49,0xa5,0x24,0x44,0xb3,0x0e,0x5e,0xba,0x5a,0xdd,0xdc,0xd9,0xf1,0x8d},
{0xf2,0xb9,0x06,0xa5,0xb8,0x4b,0x9b,0x4b,0xbe,0x95,0xed,0x32,0x56,0x4e,0xe7,0xeb}}};
- // Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
- StreamState ss(std::cout);
-
byte digest[MD5MAC::DIGESTSIZE];
bool pass=true, fail;
+ std::ostringstream oss;
- std::cout << "\nMD5MAC validation suite running...\n";
+ oss << "\nMD5MAC validation suite running...\n";
for (int k=0; k<2; k++)
{
MD5MAC mac(keys[k]);
- std::cout << "\nKEY: ";
+ oss << "\nKEY: ";
for (int j=0;j<MD5MAC::KEYLENGTH;j++)
- std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)keys[k][j];
- std::cout << std::endl << std::endl;
+ oss << std::setw(2) << std::setfill('0') << std::hex << (int)keys[k][j];
+ oss << std::endl << std::endl;
for (int i=0;i<7;i++)
{
mac.Update((byte *)TestVals[i], strlen(TestVals[i]));
@@ -429,13 +427,14 @@ bool ValidateMD5MAC()
fail = !!memcmp(digest, output[k][i], MD5MAC::DIGESTSIZE)
|| !mac.VerifyDigest(output[k][i], (byte *)TestVals[i], strlen(TestVals[i]));
pass = pass && !fail;
- std::cout << (fail ? "FAILED " : "passed ");
+ oss << (fail ? "FAILED " : "passed ");
for (int j=0;j<MD5MAC::DIGESTSIZE;j++)
- std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)digest[j];
- std::cout << " \"" << TestVals[i] << '\"' << std::endl;
+ oss << std::setw(2) << std::setfill('0') << std::hex << (int)digest[j];
+ oss << " \"" << TestVals[i] << '\"' << std::endl;
}
}
+ std::cout << oss.str();
return pass;
}
#endif
@@ -540,13 +539,11 @@ bool ValidateTTMAC()
{0x54,0xba,0xc3,0x92,0xa8,0x86,0x80,0x6d,0x16,0x95,0x56,0xfc,0xbb,0x67,0x89,0xb5,0x4f,0xb3,0x64,0xfb},
{0x0c,0xed,0x2c,0x9f,0x8f,0x0d,0x9d,0x03,0x98,0x1a,0xb5,0xc8,0x18,0x4b,0xac,0x43,0xdd,0x54,0xc4,0x84}};
- // Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
- StreamState ss(std::cout);
-
byte digest[TTMAC::DIGESTSIZE];
bool pass=true, fail;
+ std::ostringstream oss;
- std::cout << "\nTwo-Track-MAC validation suite running...\n";
+ oss << "\nTwo-Track-MAC validation suite running...\n";
TTMAC mac(key, sizeof(key));
for (unsigned int k = 0; k<COUNTOF(TestVals); k++)
@@ -556,12 +553,13 @@ bool ValidateTTMAC()
fail = !!memcmp(digest, output[k], TTMAC::DIGESTSIZE)
|| !mac.VerifyDigest(output[k], (byte *)TestVals[k], strlen(TestVals[k]));
pass = pass && !fail;
- std::cout << (fail ? "FAILED " : "passed ");
+ oss << (fail ? "FAILED " : "passed ");
for (int j=0;j<TTMAC::DIGESTSIZE;j++)
- std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)digest[j];
- std::cout << " \"" << TestVals[k] << '\"' << std::endl;
+ oss << std::setw(2) << std::setfill('0') << std::hex << (int)digest[j];
+ oss << " \"" << TestVals[k] << '\"' << std::endl;
}
+ std::cout << oss.str();
return true;
}
diff --git a/validat6.cpp b/validat6.cpp
index 669372ec..6494bf19 100644
--- a/validat6.cpp
+++ b/validat6.cpp
@@ -195,46 +195,46 @@ bool ValidateBBS()
bool pass = true, fail;
int j;
- static const byte output1[] = {
+ const byte output1[] = {
0x49,0xEA,0x2C,0xFD,0xB0,0x10,0x64,0xA0,0xBB,0xB9,
0x2A,0xF1,0x01,0xDA,0xC1,0x8A,0x94,0xF7,0xB7,0xCE};
- static const byte output2[] = {
+ const byte output2[] = {
0x74,0x45,0x48,0xAE,0xAC,0xB7,0x0E,0xDF,0xAF,0xD7,
0xD5,0x0E,0x8E,0x29,0x83,0x75,0x6B,0x27,0x46,0xA1};
- // Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
- StreamState ss(std::cout);
byte buf[20];
+ std::ostringstream oss;
bbs.GenerateBlock(buf, 20);
fail = memcmp(output1, buf, 20) != 0;
pass = pass && !fail;
- std::cout << (fail ? "FAILED " : "passed ");
+ oss << (fail ? "FAILED " : "passed ");
for (j=0;j<20;j++)
- std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)buf[j];
- std::cout << std::endl;
+ oss << std::setw(2) << std::setfill('0') << std::hex << (int)buf[j];
+ oss << std::endl;
bbs.Seek(10);
bbs.GenerateBlock(buf, 10);
fail = memcmp(output1+10, buf, 10) != 0;
pass = pass && !fail;
- std::cout << (fail ? "FAILED " : "passed ");
+ oss << (fail ? "FAILED " : "passed ");
for (j=0;j<10;j++)
- std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)buf[j];
- std::cout << std::endl;
+ oss << std::setw(2) << std::setfill('0') << std::hex << (int)buf[j];
+ oss << std::endl;
bbs.Seek(1234567);
bbs.GenerateBlock(buf, 20);
fail = memcmp(output2, buf, 20) != 0;
pass = pass && !fail;
- std::cout << (fail ? "FAILED " : "passed ");
+ oss << (fail ? "FAILED " : "passed ");
for (j=0;j<20;j++)
- std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)buf[j];
- std::cout << std::endl;
+ oss << std::setw(2) << std::setfill('0') << std::hex << (int)buf[j];
+ oss << std::endl;
+ std::cout << oss.str();
return pass;
}
diff --git a/validate.h b/validate.h
index a312fb6d..d4ca8a4b 100644
--- a/validate.h
+++ b/validate.h
@@ -170,33 +170,6 @@ private:
BufferedTransformation &m_source;
};
-#if 1
-// Coverity findings in benchmark and validation routines
-class StreamState
-{
-public:
- StreamState(std::ostream& out)
- : m_out(out), m_prec(out.precision()), m_width(out.width()), m_fmt(out.flags()), m_fill(out.fill())
- {
- }
-
- ~StreamState()
- {
- m_out.fill(m_fill);
- m_out.flags(m_fmt);
- m_out.width(m_width);
- m_out.precision(m_prec);
- }
-
-private:
- std::ostream& m_out;
- std::streamsize m_prec;
- std::streamsize m_width;
- std::ios_base::fmtflags m_fmt;
- std::ostream::char_type m_fill;
-};
-#endif
-
// Safer functions on Windows for C&A, http://github.com/weidai11/cryptopp/issues/55
inline std::string TimeToString(const time_t& t)
{