mirror of
https://github.com/shadps4-emu/ext-cryptopp.git
synced 2024-11-23 09:59:42 +00:00
Add Test namespace within CryptoPP namespace (Issue 379)
This commit is contained in:
parent
11f0186fd0
commit
73836e58a5
2
asn.cpp
2
asn.cpp
@ -1,4 +1,5 @@
|
||||
// asn.cpp - originally written and placed in the public domain by Wei Dai
|
||||
// CryptoPP::Test namespace added by JW in February 2017
|
||||
|
||||
#include "pch.h"
|
||||
#include "config.h"
|
||||
@ -11,7 +12,6 @@
|
||||
#include <time.h>
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
USING_NAMESPACE(std)
|
||||
|
||||
/// DER Length
|
||||
size_t DERLengthEncode(BufferedTransformation &bt, lword length)
|
||||
|
22
bench.h
22
bench.h
@ -1,13 +1,33 @@
|
||||
// bench.h - originally written and placed in the public domain by Wei Dai
|
||||
// CryptoPP::Test namespace added by JW in February 2017
|
||||
|
||||
#ifndef CRYPTOPP_BENCH_H
|
||||
#define CRYPTOPP_BENCH_H
|
||||
|
||||
#include "cryptlib.h"
|
||||
|
||||
extern const double CLOCK_TICKS_PER_SECOND;
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
NAMESPACE_BEGIN(Test)
|
||||
|
||||
ANONYMOUS_NAMESPACE_BEGIN
|
||||
#ifdef CLOCKS_PER_SEC
|
||||
const double CLOCK_TICKS_PER_SECOND = (double)CLOCKS_PER_SEC;
|
||||
#elif defined(CLK_TCK)
|
||||
const double CLOCK_TICKS_PER_SECOND = (double)CLK_TCK;
|
||||
#else
|
||||
const double CLOCK_TICKS_PER_SECOND = 1000000.0;
|
||||
#endif
|
||||
|
||||
static const byte defaultKey[] = "0123456789" // 168 + NULL
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"00000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000000000000";
|
||||
NAMESPACE_END
|
||||
|
||||
void BenchmarkAll(double t, double hertz);
|
||||
void BenchmarkAll2(double t, double hertz);
|
||||
|
||||
NAMESPACE_END // Test
|
||||
NAMESPACE_END // CryptoPP
|
||||
|
||||
#endif
|
||||
|
100
bench1.cpp
100
bench1.cpp
@ -1,4 +1,5 @@
|
||||
// bench1.cpp - originally written and placed in the public domain by Wei Dai
|
||||
// CryptoPP::Test namespace added by JW in February 2017
|
||||
|
||||
#include "cryptlib.h"
|
||||
#include "bench.h"
|
||||
@ -20,79 +21,63 @@
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
// These are noisy enoguh due to test.cpp. Turn them off here.
|
||||
#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
|
||||
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
NAMESPACE_BEGIN(Test)
|
||||
|
||||
USING_NAMESPACE(CryptoPP)
|
||||
USING_NAMESPACE(std)
|
||||
|
||||
#ifdef CLOCKS_PER_SEC
|
||||
const double CLOCK_TICKS_PER_SECOND = (double)CLOCKS_PER_SEC;
|
||||
#elif defined(CLK_TCK)
|
||||
const double CLOCK_TICKS_PER_SECOND = (double)CLK_TCK;
|
||||
#else
|
||||
const double CLOCK_TICKS_PER_SECOND = 1000000.0;
|
||||
#endif
|
||||
|
||||
double logtotal = 0.0, g_allocatedTime = 0, g_hertz = 0;
|
||||
unsigned int logcount = 0;
|
||||
|
||||
static const byte defaultKey[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
|
||||
double logTotal = 0.0, g_allocatedTime = 0, g_hertz = 0;
|
||||
unsigned int logCount = 0;
|
||||
|
||||
void OutputResultBytes(const char *name, double length, double timeTaken)
|
||||
{
|
||||
// Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
|
||||
StreamState ss(cout);
|
||||
StreamState ss(std::cout);
|
||||
|
||||
// Coverity finding
|
||||
if (length < 0.0000000001f) length = 0.000001f;
|
||||
if (timeTaken < 0.0000000001f) timeTaken = 0.000001f;
|
||||
|
||||
double mbs = length / timeTaken / (1024*1024);
|
||||
cout << "\n<TR><TH>" << name;
|
||||
// cout << "<TD>" << setprecision(3) << length / (1024*1024);
|
||||
cout << setiosflags(ios::fixed);
|
||||
// cout << "<TD>" << setprecision(3) << timeTaken;
|
||||
cout << "<TD>" << setprecision(0) << setiosflags(ios::fixed) << mbs;
|
||||
std::cout << "\n<TR><TH>" << name;
|
||||
// std::cout << "<TD>" << std::setprecision(3) << length / (1024*1024);
|
||||
std::cout << std::setiosflags(std::ios::fixed);
|
||||
// std::cout << "<TD>" << std::setprecision(3) << timeTaken;
|
||||
std::cout << "<TD>" << std::setprecision(0) << std::setiosflags(std::ios::fixed) << mbs;
|
||||
if (g_hertz)
|
||||
cout << "<TD>" << setprecision(1) << setiosflags(ios::fixed) << timeTaken * g_hertz / length;
|
||||
logtotal += log(mbs);
|
||||
logcount++;
|
||||
std::cout << "<TD>" << std::setprecision(1) << std::setiosflags(std::ios::fixed) << timeTaken * g_hertz / length;
|
||||
logTotal += log(mbs);
|
||||
logCount++;
|
||||
}
|
||||
|
||||
void OutputResultKeying(double iterations, double timeTaken)
|
||||
{
|
||||
// Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
|
||||
StreamState ss(cout);
|
||||
StreamState ss(std::cout);
|
||||
|
||||
// Coverity finding
|
||||
if (iterations < 0.0000000001f) iterations = 0.000001f;
|
||||
if (timeTaken < 0.0000000001f) timeTaken = 0.000001f;
|
||||
|
||||
cout << "<TD>" << setprecision(3) << setiosflags(ios::fixed) << (1000*1000*timeTaken/iterations);
|
||||
std::cout << "<TD>" << std::setprecision(3) << std::setiosflags(std::ios::fixed) << (1000*1000*timeTaken/iterations);
|
||||
if (g_hertz)
|
||||
cout << "<TD>" << setprecision(0) << setiosflags(ios::fixed) << timeTaken * g_hertz / iterations;
|
||||
std::cout << "<TD>" << std::setprecision(0) << std::setiosflags(std::ios::fixed) << timeTaken * g_hertz / iterations;
|
||||
}
|
||||
|
||||
void OutputResultOperations(const char *name, const char *operation, bool pc, unsigned long iterations, double timeTaken)
|
||||
{
|
||||
// Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
|
||||
StreamState ss(cout);
|
||||
StreamState ss(std::cout);
|
||||
|
||||
// Coverity finding
|
||||
if (!iterations) iterations++;
|
||||
if (timeTaken < 0.0000000001f) timeTaken = 0.000001f;
|
||||
|
||||
cout << "\n<TR><TH>" << name << " " << operation << (pc ? " with precomputation" : "");
|
||||
cout << "<TD>" << setprecision(2) << setiosflags(ios::fixed) << (1000*timeTaken/iterations);
|
||||
std::cout << "\n<TR><TH>" << name << " " << operation << (pc ? " with precomputation" : "");
|
||||
std::cout << "<TD>" << std::setprecision(2) << std::setiosflags(std::ios::fixed) << (1000*timeTaken/iterations);
|
||||
if (g_hertz)
|
||||
cout << "<TD>" << setprecision(2) << setiosflags(ios::fixed) << timeTaken * g_hertz / iterations / 1000000;
|
||||
std::cout << "<TD>" << std::setprecision(2) << std::setiosflags(std::ios::fixed) << timeTaken * g_hertz / iterations / 1000000;
|
||||
|
||||
logtotal += log(iterations/timeTaken);
|
||||
logcount++;
|
||||
logTotal += log(iterations/timeTaken);
|
||||
logCount++;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -122,7 +107,7 @@ void BenchMark(const char *name, StreamTransformation &cipher, double timeTotal)
|
||||
{
|
||||
const int BUF_SIZE=RoundUpToMultipleOf(2048U, cipher.OptimalBlockSize());
|
||||
AlignedSecByteBlock buf(BUF_SIZE);
|
||||
GlobalRNG().GenerateBlock(buf, BUF_SIZE);
|
||||
Test::GlobalRNG().GenerateBlock(buf, BUF_SIZE);
|
||||
clock_t start = clock();
|
||||
|
||||
unsigned long i=0, blocks=1;
|
||||
@ -151,7 +136,7 @@ void BenchMark(const char *name, HashTransformation &ht, double timeTotal)
|
||||
{
|
||||
const int BUF_SIZE=2048U;
|
||||
AlignedSecByteBlock buf(BUF_SIZE);
|
||||
GlobalRNG().GenerateBlock(buf, BUF_SIZE);
|
||||
Test::GlobalRNG().GenerateBlock(buf, BUF_SIZE);
|
||||
clock_t start = clock();
|
||||
|
||||
unsigned long i=0, blocks=1;
|
||||
@ -172,7 +157,7 @@ void BenchMark(const char *name, BufferedTransformation &bt, double timeTotal)
|
||||
{
|
||||
const int BUF_SIZE=2048U;
|
||||
AlignedSecByteBlock buf(BUF_SIZE);
|
||||
GlobalRNG().GenerateBlock(buf, BUF_SIZE);
|
||||
Test::GlobalRNG().GenerateBlock(buf, BUF_SIZE);
|
||||
clock_t start = clock();
|
||||
|
||||
unsigned long i=0, blocks=1;
|
||||
@ -248,8 +233,8 @@ void BenchMarkByNameKeyLess(const char *factoryName, const char *displayName=NUL
|
||||
void BenchmarkAll(double t, double hertz)
|
||||
{
|
||||
#if 1
|
||||
logtotal = 0;
|
||||
logcount = 0;
|
||||
logTotal = 0;
|
||||
logCount = 0;
|
||||
g_allocatedTime = t;
|
||||
g_hertz = hertz;
|
||||
|
||||
@ -258,18 +243,18 @@ void BenchmarkAll(double t, double hertz)
|
||||
{
|
||||
cpb = "<TH>Cycles Per Byte";
|
||||
cpk = "<TH>Cycles to<br>Setup Key and IV";
|
||||
cout << "CPU frequency of the test platform is " << g_hertz << " Hz.\n";
|
||||
std::cout << "CPU frequency of the test platform is " << g_hertz << " Hz.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
cpb = cpk = "";
|
||||
cout << "CPU frequency of the test platform was not provided.\n";
|
||||
std::cout << "CPU frequency of the test platform was not provided.\n";
|
||||
}
|
||||
|
||||
cout << "<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right><COL align=right><COL align=right>" << endl;
|
||||
cout << "<THEAD><TR><TH>Algorithm<TH>MiB/Second" << cpb << "<TH>Microseconds to<br>Setup Key and IV" << cpk << endl;
|
||||
std::cout << "<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right><COL align=right><COL align=right>" << std::endl;
|
||||
std::cout << "<THEAD><TR><TH>Algorithm<TH>MiB/Second" << cpb << "<TH>Microseconds to<br>Setup Key and IV" << cpk << std::endl;
|
||||
|
||||
cout << "\n<TBODY style=\"background: yellow\">";
|
||||
std::cout << "\n<TBODY style=\"background: yellow\">";
|
||||
#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE
|
||||
if (HasCLMUL())
|
||||
BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>("AES/GCM", 0, "AES/GCM");
|
||||
@ -286,7 +271,7 @@ void BenchmarkAll(double t, double hertz)
|
||||
BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>("AES/CCM");
|
||||
BenchMarkByName2<AuthenticatedSymmetricCipher, AuthenticatedSymmetricCipher>("AES/EAX");
|
||||
|
||||
cout << "\n<TBODY style=\"background: white\">";
|
||||
std::cout << "\n<TBODY style=\"background: white\">";
|
||||
#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE
|
||||
if (HasCLMUL())
|
||||
BenchMarkByName2<AuthenticatedSymmetricCipher, MessageAuthenticationCode>("AES/GCM", 0, "GMAC(AES)");
|
||||
@ -308,7 +293,7 @@ void BenchmarkAll(double t, double hertz)
|
||||
BenchMarkByName<MessageAuthenticationCode>("SipHash-2-4");
|
||||
BenchMarkByName<MessageAuthenticationCode>("SipHash-4-8");
|
||||
|
||||
cout << "\n<TBODY style=\"background: yellow\">";
|
||||
std::cout << "\n<TBODY style=\"background: yellow\">";
|
||||
BenchMarkByNameKeyLess<HashTransformation>("CRC32");
|
||||
BenchMarkByNameKeyLess<HashTransformation>("CRC32C");
|
||||
BenchMarkByNameKeyLess<HashTransformation>("Adler32");
|
||||
@ -333,7 +318,7 @@ void BenchmarkAll(double t, double hertz)
|
||||
BenchMarkByNameKeyLess<HashTransformation>("BLAKE2s");
|
||||
BenchMarkByNameKeyLess<HashTransformation>("BLAKE2b");
|
||||
|
||||
cout << "\n<TBODY style=\"background: white\">";
|
||||
std::cout << "\n<TBODY style=\"background: white\">";
|
||||
BenchMarkByName<SymmetricCipher>("Panama-LE");
|
||||
BenchMarkByName<SymmetricCipher>("Panama-BE");
|
||||
BenchMarkByName<SymmetricCipher>("Salsa20");
|
||||
@ -347,7 +332,7 @@ void BenchmarkAll(double t, double hertz)
|
||||
BenchMarkByName<SymmetricCipher>("SEAL-3.0-LE");
|
||||
BenchMarkByName<SymmetricCipher>("WAKE-OFB-LE");
|
||||
|
||||
cout << "\n<TBODY style=\"background: yellow\">";
|
||||
std::cout << "\n<TBODY style=\"background: yellow\">";
|
||||
BenchMarkByName<SymmetricCipher>("AES/CTR", 16);
|
||||
BenchMarkByName<SymmetricCipher>("AES/CTR", 24);
|
||||
BenchMarkByName<SymmetricCipher>("AES/CTR", 32);
|
||||
@ -377,10 +362,10 @@ void BenchmarkAll(double t, double hertz)
|
||||
BenchMarkByName<SymmetricCipher>("CAST-128/CTR");
|
||||
BenchMarkByName<SymmetricCipher>("SKIPJACK/CTR");
|
||||
BenchMarkByName<SymmetricCipher>("SEED/CTR", 0, "SEED/CTR (1/2 K table)");
|
||||
cout << "</TABLE>" << endl;
|
||||
std::cout << "</TABLE>" << std::endl;
|
||||
|
||||
BenchmarkAll2(t, hertz);
|
||||
cout << "Throughput Geometric Average: " << setiosflags(ios::fixed) << exp(logtotal/(logcount ? logcount : 1)) << endl;
|
||||
std::cout << "Throughput Geometric Average: " << std::setiosflags(std::ios::fixed) << exp(logTotal/(logCount ? logCount : 1)) << std::endl;
|
||||
|
||||
// Safer functions on Windows for C&A, https://github.com/weidai11/cryptopp/issues/55
|
||||
#if (CRYPTOPP_MSC_VERSION >= 1400)
|
||||
@ -394,10 +379,13 @@ void BenchmarkAll(double t, double hertz)
|
||||
err = asctime_s(timeBuf, sizeof(timeBuf), &localTime);
|
||||
CRYPTOPP_ASSERT(err == 0);
|
||||
|
||||
cout << "\nTest ended at " << timeBuf;
|
||||
std::cout << "\nTest ended at " << timeBuf;
|
||||
#else
|
||||
const time_t endTime = time(NULL);
|
||||
cout << "\nTest ended at " << asctime(localtime(&endTime));
|
||||
std::cout << "\nTest ended at " << asctime(localtime(&endTime));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
NAMESPACE_END // Test
|
||||
NAMESPACE_END // CryptoPP
|
||||
|
83
bench2.cpp
83
bench2.cpp
@ -1,4 +1,5 @@
|
||||
// bench2.cpp - originally written and placed in the public domain by Wei Dai
|
||||
// CryptoPP::Test namespace added by JW in February 2017
|
||||
|
||||
#include "cryptlib.h"
|
||||
#include "bench.h"
|
||||
@ -34,13 +35,8 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
// These are noisy enoguh due to test.cpp. Turn them off here.
|
||||
#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
|
||||
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
USING_NAMESPACE(CryptoPP)
|
||||
USING_NAMESPACE(std)
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
NAMESPACE_BEGIN(Test)
|
||||
|
||||
void OutputResultOperations(const char *name, const char *operation, bool pc, unsigned long iterations, double timeTaken);
|
||||
|
||||
@ -48,13 +44,13 @@ void BenchMarkEncryption(const char *name, PK_Encryptor &key, double timeTotal,
|
||||
{
|
||||
unsigned int len = 16;
|
||||
SecByteBlock plaintext(len), ciphertext(key.CiphertextLength(len));
|
||||
GlobalRNG().GenerateBlock(plaintext, len);
|
||||
Test::GlobalRNG().GenerateBlock(plaintext, len);
|
||||
|
||||
const clock_t start = clock();
|
||||
unsigned int i;
|
||||
double timeTaken;
|
||||
for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
|
||||
key.Encrypt(GlobalRNG(), plaintext, len, ciphertext);
|
||||
key.Encrypt(Test::GlobalRNG(), plaintext, len, ciphertext);
|
||||
|
||||
OutputResultOperations(name, "Encryption", pc, i, timeTaken);
|
||||
|
||||
@ -70,14 +66,14 @@ void BenchMarkDecryption(const char *name, PK_Decryptor &priv, PK_Encryptor &pub
|
||||
unsigned int len = 16;
|
||||
SecByteBlock ciphertext(pub.CiphertextLength(len));
|
||||
SecByteBlock plaintext(pub.MaxPlaintextLength(ciphertext.size()));
|
||||
GlobalRNG().GenerateBlock(plaintext, len);
|
||||
pub.Encrypt(GlobalRNG(), plaintext, len, ciphertext);
|
||||
Test::GlobalRNG().GenerateBlock(plaintext, len);
|
||||
pub.Encrypt(Test::GlobalRNG(), plaintext, len, ciphertext);
|
||||
|
||||
const clock_t start = clock();
|
||||
unsigned int i;
|
||||
double timeTaken;
|
||||
for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
|
||||
priv.Decrypt(GlobalRNG(), ciphertext, ciphertext.size(), plaintext);
|
||||
priv.Decrypt(Test::GlobalRNG(), ciphertext, ciphertext.size(), plaintext);
|
||||
|
||||
OutputResultOperations(name, "Decryption", false, i, timeTaken);
|
||||
}
|
||||
@ -86,13 +82,13 @@ void BenchMarkSigning(const char *name, PK_Signer &key, double timeTotal, bool p
|
||||
{
|
||||
unsigned int len = 16;
|
||||
AlignedSecByteBlock message(len), signature(key.SignatureLength());
|
||||
GlobalRNG().GenerateBlock(message, len);
|
||||
Test::GlobalRNG().GenerateBlock(message, len);
|
||||
|
||||
const clock_t start = clock();
|
||||
unsigned int i;
|
||||
double timeTaken;
|
||||
for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
|
||||
key.SignMessage(GlobalRNG(), message, len, signature);
|
||||
key.SignMessage(Test::GlobalRNG(), message, len, signature);
|
||||
|
||||
OutputResultOperations(name, "Signature", pc, i, timeTaken);
|
||||
|
||||
@ -107,8 +103,8 @@ void BenchMarkVerification(const char *name, const PK_Signer &priv, PK_Verifier
|
||||
{
|
||||
unsigned int len = 16;
|
||||
AlignedSecByteBlock message(len), signature(pub.SignatureLength());
|
||||
GlobalRNG().GenerateBlock(message, len);
|
||||
priv.SignMessage(GlobalRNG(), message, len, signature);
|
||||
Test::GlobalRNG().GenerateBlock(message, len);
|
||||
priv.SignMessage(Test::GlobalRNG(), message, len, signature);
|
||||
|
||||
const clock_t start = clock();
|
||||
unsigned int i;
|
||||
@ -137,7 +133,7 @@ void BenchMarkKeyGen(const char *name, SimpleKeyAgreementDomain &d, double timeT
|
||||
unsigned int i;
|
||||
double timeTaken;
|
||||
for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
|
||||
d.GenerateKeyPair(GlobalRNG(), priv, pub);
|
||||
d.GenerateKeyPair(Test::GlobalRNG(), priv, pub);
|
||||
|
||||
OutputResultOperations(name, "Key-Pair Generation", pc, i, timeTaken);
|
||||
|
||||
@ -156,7 +152,7 @@ void BenchMarkKeyGen(const char *name, AuthenticatedKeyAgreementDomain &d, doubl
|
||||
unsigned int i;
|
||||
double timeTaken;
|
||||
for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++)
|
||||
d.GenerateEphemeralKeyPair(GlobalRNG(), priv, pub);
|
||||
d.GenerateEphemeralKeyPair(Test::GlobalRNG(), priv, pub);
|
||||
|
||||
OutputResultOperations(name, "Key-Pair Generation", pc, i, timeTaken);
|
||||
|
||||
@ -171,8 +167,8 @@ void BenchMarkAgreement(const char *name, SimpleKeyAgreementDomain &d, double ti
|
||||
{
|
||||
SecByteBlock priv1(d.PrivateKeyLength()), priv2(d.PrivateKeyLength());
|
||||
SecByteBlock pub1(d.PublicKeyLength()), pub2(d.PublicKeyLength());
|
||||
d.GenerateKeyPair(GlobalRNG(), priv1, pub1);
|
||||
d.GenerateKeyPair(GlobalRNG(), priv2, pub2);
|
||||
d.GenerateKeyPair(Test::GlobalRNG(), priv1, pub1);
|
||||
d.GenerateKeyPair(Test::GlobalRNG(), priv2, pub2);
|
||||
SecByteBlock val(d.AgreedValueLength());
|
||||
|
||||
const clock_t start = clock();
|
||||
@ -193,10 +189,10 @@ void BenchMarkAgreement(const char *name, AuthenticatedKeyAgreementDomain &d, do
|
||||
SecByteBlock epriv1(d.EphemeralPrivateKeyLength()), epriv2(d.EphemeralPrivateKeyLength());
|
||||
SecByteBlock spub1(d.StaticPublicKeyLength()), spub2(d.StaticPublicKeyLength());
|
||||
SecByteBlock epub1(d.EphemeralPublicKeyLength()), epub2(d.EphemeralPublicKeyLength());
|
||||
d.GenerateStaticKeyPair(GlobalRNG(), spriv1, spub1);
|
||||
d.GenerateStaticKeyPair(GlobalRNG(), spriv2, spub2);
|
||||
d.GenerateEphemeralKeyPair(GlobalRNG(), epriv1, epub1);
|
||||
d.GenerateEphemeralKeyPair(GlobalRNG(), epriv2, epub2);
|
||||
d.GenerateStaticKeyPair(Test::GlobalRNG(), spriv1, spub1);
|
||||
d.GenerateStaticKeyPair(Test::GlobalRNG(), spriv2, spub2);
|
||||
d.GenerateEphemeralKeyPair(Test::GlobalRNG(), epriv1, epub1);
|
||||
d.GenerateEphemeralKeyPair(Test::GlobalRNG(), epriv2, epub2);
|
||||
SecByteBlock val(d.AgreedValueLength());
|
||||
|
||||
const clock_t start = clock();
|
||||
@ -218,10 +214,10 @@ void BenchMarkAgreement(const char *name, AuthenticatedKeyAgreementDomainWithRol
|
||||
SecByteBlock epriv1(d.EphemeralPrivateKeyLength()), epriv2(d.EphemeralPrivateKeyLength());
|
||||
SecByteBlock spub1(d.StaticPublicKeyLength()), spub2(d.StaticPublicKeyLength());
|
||||
SecByteBlock epub1(d.EphemeralPublicKeyLength()), epub2(d.EphemeralPublicKeyLength());
|
||||
d.GenerateStaticKeyPair(GlobalRNG(), spriv1, spub1);
|
||||
d.GenerateStaticKeyPair(GlobalRNG(), spriv2, spub2);
|
||||
d.GenerateEphemeralKeyPair(GlobalRNG(), epriv1, epub1);
|
||||
d.GenerateEphemeralKeyPair(GlobalRNG(), epriv2, epub2);
|
||||
d.GenerateStaticKeyPair(Test::GlobalRNG(), spriv1, spub1);
|
||||
d.GenerateStaticKeyPair(Test::GlobalRNG(), spriv2, spub2);
|
||||
d.GenerateEphemeralKeyPair(Test::GlobalRNG(), epriv1, epub1);
|
||||
d.GenerateEphemeralKeyPair(Test::GlobalRNG(), epriv2, epub2);
|
||||
SecByteBlock val(d.AgreedValueLength());
|
||||
|
||||
const clock_t start = clock();
|
||||
@ -272,22 +268,22 @@ void BenchmarkAll2(double t, double hertz)
|
||||
{
|
||||
g_hertz = hertz;
|
||||
|
||||
cout << "<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right>" << endl;
|
||||
cout << "<THEAD><TR><TH>Operation<TH>Milliseconds/Operation" << (g_hertz ? "<TH>Megacycles/Operation" : "") << endl;
|
||||
std::cout << "<TABLE border=1><COLGROUP><COL align=left><COL align=right><COL align=right>" << std::endl;
|
||||
std::cout << "<THEAD><TR><TH>Operation<TH>Milliseconds/Operation" << (g_hertz ? "<TH>Megacycles/Operation" : "") << std::endl;
|
||||
|
||||
cout << "\n<TBODY style=\"background: yellow\">";
|
||||
std::cout << "\n<TBODY style=\"background: yellow\">";
|
||||
BenchMarkCrypto<RSAES<OAEP<SHA> > >(CRYPTOPP_DATA_DIR "TestData/rsa1024.dat", "RSA 1024", t);
|
||||
BenchMarkCrypto<LUCES<OAEP<SHA> > >(CRYPTOPP_DATA_DIR "TestData/luc1024.dat", "LUC 1024", t);
|
||||
BenchMarkCrypto<DLIES<> >(CRYPTOPP_DATA_DIR "TestData/dlie1024.dat", "DLIES 1024", t);
|
||||
BenchMarkCrypto<LUC_IES<> >(CRYPTOPP_DATA_DIR "TestData/lucc512.dat", "LUCELG 512", t);
|
||||
|
||||
cout << "\n<TBODY style=\"background: white\">";
|
||||
std::cout << "\n<TBODY style=\"background: white\">";
|
||||
BenchMarkCrypto<RSAES<OAEP<SHA> > >(CRYPTOPP_DATA_DIR "TestData/rsa2048.dat", "RSA 2048", t);
|
||||
BenchMarkCrypto<LUCES<OAEP<SHA> > >(CRYPTOPP_DATA_DIR "TestData/luc2048.dat", "LUC 2048", t);
|
||||
BenchMarkCrypto<DLIES<> >(CRYPTOPP_DATA_DIR "TestData/dlie2048.dat", "DLIES 2048", t);
|
||||
BenchMarkCrypto<LUC_IES<> >(CRYPTOPP_DATA_DIR "TestData/lucc1024.dat", "LUCELG 1024", t);
|
||||
|
||||
cout << "\n<TBODY style=\"background: yellow\">";
|
||||
std::cout << "\n<TBODY style=\"background: yellow\">";
|
||||
BenchMarkSignature<RSASS<PSSR, SHA> >(CRYPTOPP_DATA_DIR "TestData/rsa1024.dat", "RSA 1024", t);
|
||||
BenchMarkSignature<RWSS<PSSR, SHA> >(CRYPTOPP_DATA_DIR "TestData/rw1024.dat", "RW 1024", t);
|
||||
BenchMarkSignature<LUCSS<PSSR, SHA> >(CRYPTOPP_DATA_DIR "TestData/luc1024.dat", "LUC 1024", t);
|
||||
@ -297,7 +293,7 @@ void BenchmarkAll2(double t, double hertz)
|
||||
BenchMarkSignature<ESIGN<SHA> >(CRYPTOPP_DATA_DIR "TestData/esig1023.dat", "ESIGN 1023", t);
|
||||
BenchMarkSignature<ESIGN<SHA> >(CRYPTOPP_DATA_DIR "TestData/esig1536.dat", "ESIGN 1536", t);
|
||||
|
||||
cout << "\n<TBODY style=\"background: white\">";
|
||||
std::cout << "\n<TBODY style=\"background: white\">";
|
||||
BenchMarkSignature<RSASS<PSSR, SHA> >(CRYPTOPP_DATA_DIR "TestData/rsa2048.dat", "RSA 2048", t);
|
||||
BenchMarkSignature<RWSS<PSSR, SHA> >(CRYPTOPP_DATA_DIR "TestData/rw2048.dat", "RW 2048", t);
|
||||
BenchMarkSignature<LUCSS<PSSR, SHA> >(CRYPTOPP_DATA_DIR "TestData/luc2048.dat", "LUC 2048", t);
|
||||
@ -305,7 +301,7 @@ void BenchmarkAll2(double t, double hertz)
|
||||
BenchMarkSignature<LUC_HMP<SHA> >(CRYPTOPP_DATA_DIR "TestData/lucs1024.dat", "LUC-HMP 1024", t);
|
||||
BenchMarkSignature<ESIGN<SHA> >(CRYPTOPP_DATA_DIR "TestData/esig2046.dat", "ESIGN 2046", t);
|
||||
|
||||
cout << "\n<TBODY style=\"background: yellow\">";
|
||||
std::cout << "\n<TBODY style=\"background: yellow\">";
|
||||
BenchMarkKeyAgreement<XTR_DH>(CRYPTOPP_DATA_DIR "TestData/xtrdh171.dat", "XTR-DH 171", t);
|
||||
BenchMarkKeyAgreement<XTR_DH>(CRYPTOPP_DATA_DIR "TestData/xtrdh342.dat", "XTR-DH 342", t);
|
||||
BenchMarkKeyAgreement<DH>(CRYPTOPP_DATA_DIR "TestData/dh1024.dat", "DH 1024", t);
|
||||
@ -327,15 +323,15 @@ void BenchmarkAll2(double t, double hertz)
|
||||
BenchMarkKeyAgreement<ECFHMQV512>(CRYPTOPP_DATA_DIR "TestData/fhmqv512.dat", "FHMQV P-512", t);
|
||||
#endif
|
||||
|
||||
cout << "\n<TBODY style=\"background: white\">";
|
||||
std::cout << "\n<TBODY style=\"background: white\">";
|
||||
{
|
||||
ECIES<ECP>::Decryptor cpriv(GlobalRNG(), ASN1::secp256k1());
|
||||
ECIES<ECP>::Decryptor cpriv(Test::GlobalRNG(), ASN1::secp256k1());
|
||||
ECIES<ECP>::Encryptor cpub(cpriv);
|
||||
ECDSA<ECP, SHA>::Signer spriv(cpriv);
|
||||
ECDSA<ECP, SHA>::Verifier spub(spriv);
|
||||
ECDSA_RFC6979<ECP, SHA>::Signer spriv2(cpriv);
|
||||
ECDSA_RFC6979<ECP, SHA>::Verifier spub2(spriv);
|
||||
ECGDSA<ECP, SHA>::Signer spriv3(GlobalRNG(), ASN1::secp256k1());
|
||||
ECGDSA<ECP, SHA>::Signer spriv3(Test::GlobalRNG(), ASN1::secp256k1());
|
||||
ECGDSA<ECP, SHA>::Verifier spub3(spriv3);
|
||||
ECDH<ECP>::Domain ecdhc(ASN1::secp256k1());
|
||||
ECMQV<ECP>::Domain ecmqvc(ASN1::secp256k1());
|
||||
@ -354,15 +350,15 @@ void BenchmarkAll2(double t, double hertz)
|
||||
BenchMarkAgreement("ECMQVC over GF(p) 256", ecmqvc, t);
|
||||
}
|
||||
|
||||
cout << "<TBODY style=\"background: yellow\">" << endl;
|
||||
std::cout << "<TBODY style=\"background: yellow\">" << std::endl;
|
||||
{
|
||||
ECIES<EC2N>::Decryptor cpriv(GlobalRNG(), ASN1::sect233r1());
|
||||
ECIES<EC2N>::Decryptor cpriv(Test::GlobalRNG(), ASN1::sect233r1());
|
||||
ECIES<EC2N>::Encryptor cpub(cpriv);
|
||||
ECDSA<EC2N, SHA>::Signer spriv(cpriv);
|
||||
ECDSA<EC2N, SHA>::Verifier spub(spriv);
|
||||
ECDSA_RFC6979<EC2N, SHA>::Signer spriv2(cpriv);
|
||||
ECDSA_RFC6979<EC2N, SHA>::Verifier spub2(spriv);
|
||||
ECGDSA<EC2N, SHA>::Signer spriv3(GlobalRNG(), ASN1::sect233r1());
|
||||
ECGDSA<EC2N, SHA>::Signer spriv3(Test::GlobalRNG(), ASN1::sect233r1());
|
||||
ECGDSA<EC2N, SHA>::Verifier spub3(spriv3);
|
||||
ECDH<EC2N>::Domain ecdhc(ASN1::sect233r1());
|
||||
ECMQV<EC2N>::Domain ecmqvc(ASN1::sect233r1());
|
||||
@ -380,5 +376,8 @@ void BenchmarkAll2(double t, double hertz)
|
||||
BenchMarkKeyGen("ECMQVC over GF(2^n) 233", ecmqvc, t);
|
||||
BenchMarkAgreement("ECMQVC over GF(2^n) 233", ecmqvc, t);
|
||||
}
|
||||
cout << "</TABLE>" << endl;
|
||||
std::cout << "</TABLE>" << std::endl;
|
||||
}
|
||||
|
||||
NAMESPACE_END // Test
|
||||
NAMESPACE_END // CryptoPP
|
@ -1,4 +1,5 @@
|
||||
// channels.cpp - originally written and placed in the public domain by Wei Dai
|
||||
// CryptoPP::Test namespace added by JW in February 2017
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
@ -8,7 +9,6 @@
|
||||
#include "channels.h"
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
USING_NAMESPACE(std)
|
||||
|
||||
#if 0
|
||||
void MessageSwitch::AddDefaultRoute(BufferedTransformation &destination, const std::string &channel)
|
||||
@ -37,7 +37,7 @@ public:
|
||||
MessageRouteIterator(MessageSwitch &ms, const std::string &channel)
|
||||
: m_channel(channel)
|
||||
{
|
||||
pair<MapIterator, MapIterator> range = cs.m_routeMap.equal_range(channel);
|
||||
std::pair<MapIterator, MapIterator> range = cs.m_routeMap.equal_range(channel);
|
||||
if (range.first == range.second)
|
||||
{
|
||||
m_useDefault = true;
|
||||
@ -97,7 +97,7 @@ void MessageSwitch::MessageSeriesEnd(int propagation=-1);
|
||||
void ChannelRouteIterator::Reset(const std::string &channel)
|
||||
{
|
||||
m_channel = channel;
|
||||
pair<MapIterator, MapIterator> range = m_cs.m_routeMap.equal_range(channel);
|
||||
std::pair<MapIterator, MapIterator> range = m_cs.m_routeMap.equal_range(channel);
|
||||
if (range.first == range.second)
|
||||
{
|
||||
m_useDefault = true;
|
||||
@ -297,7 +297,7 @@ void ChannelSwitch::AddRoute(const std::string &inChannel, BufferedTransformatio
|
||||
void ChannelSwitch::RemoveRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel)
|
||||
{
|
||||
typedef ChannelSwitch::RouteMap::iterator MapIterator;
|
||||
pair<MapIterator, MapIterator> range = m_routeMap.equal_range(inChannel);
|
||||
std::pair<MapIterator, MapIterator> range = m_routeMap.equal_range(inChannel);
|
||||
|
||||
for (MapIterator it = range.first; it != range.second; ++it)
|
||||
if (it->second.first == &destination && it->second.second == outChannel)
|
||||
|
75
datatest.cpp
75
datatest.cpp
@ -1,4 +1,5 @@
|
||||
// datatest.cpp - originally written and placed in the public domain by Wei Dai
|
||||
// CryptoPP::Test namespace added by JW in February 2017
|
||||
|
||||
#define CRYPTOPP_DEFAULT_NO_DLL
|
||||
#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
|
||||
@ -27,8 +28,8 @@
|
||||
extern "C" void __coverity_tainted_data_sanitize__(void *);
|
||||
#endif
|
||||
|
||||
USING_NAMESPACE(CryptoPP)
|
||||
USING_NAMESPACE(std)
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
NAMESPACE_BEGIN(Test)
|
||||
|
||||
typedef std::map<std::string, std::string> TestData;
|
||||
static bool s_thorough = false;
|
||||
@ -45,7 +46,7 @@ static void OutputTestData(const TestData &v)
|
||||
{
|
||||
for (TestData::const_iterator i = v.begin(); i != v.end(); ++i)
|
||||
{
|
||||
cerr << i->first << ": " << i->second << endl;
|
||||
std::cerr << i->first << ": " << i->second << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,8 +87,8 @@ void RandomizedTransfer(BufferedTransformation &source, BufferedTransformation &
|
||||
while (source.MaxRetrievable() > (finish ? 0 : 4096))
|
||||
{
|
||||
byte buf[4096+64];
|
||||
size_t start = GlobalRNG().GenerateWord32(0, 63);
|
||||
size_t len = GlobalRNG().GenerateWord32(1, UnsignedMin(4096U, 3*source.MaxRetrievable()/2));
|
||||
size_t start = Test::GlobalRNG().GenerateWord32(0, 63);
|
||||
size_t len = Test::GlobalRNG().GenerateWord32(1, UnsignedMin(4096U, 3*source.MaxRetrievable()/2));
|
||||
len = source.Get(buf+start, len);
|
||||
target.ChannelPut(channel, buf+start, len);
|
||||
}
|
||||
@ -176,7 +177,7 @@ public:
|
||||
if (i == m_data.end())
|
||||
return false;
|
||||
|
||||
m_temp.resize(0);
|
||||
m_temp.clear();
|
||||
PutDecodedDatumInto(m_data, i->first.c_str(), StringSink(m_temp).Ref());
|
||||
*reinterpret_cast<int *>(pValue) = (int)m_temp.size();
|
||||
return true;
|
||||
@ -193,7 +194,7 @@ public:
|
||||
*reinterpret_cast<Integer *>(pValue) = Integer((std::string(value) + "h").c_str());
|
||||
else if (valueType == typeid(ConstByteArrayParameter))
|
||||
{
|
||||
m_temp.resize(0);
|
||||
m_temp.clear();
|
||||
PutDecodedDatumInto(m_data, name, StringSink(m_temp).Ref());
|
||||
reinterpret_cast<ConstByteArrayParameter *>(pValue)->Assign((const byte *)m_temp.data(), m_temp.size(), false);
|
||||
}
|
||||
@ -211,9 +212,9 @@ private:
|
||||
void TestKeyPairValidAndConsistent(CryptoMaterial &pub, const CryptoMaterial &priv)
|
||||
{
|
||||
// "!!" converts between bool <-> integral.
|
||||
if (!pub.Validate(GlobalRNG(), 2U+!!s_thorough))
|
||||
if (!pub.Validate(Test::GlobalRNG(), 2U+!!s_thorough))
|
||||
SignalTestFailure();
|
||||
if (!priv.Validate(GlobalRNG(), 2U+!!s_thorough))
|
||||
if (!priv.Validate(Test::GlobalRNG(), 2U+!!s_thorough))
|
||||
SignalTestFailure();
|
||||
|
||||
ByteQueue bq1, bq2;
|
||||
@ -236,7 +237,7 @@ void TestSignatureScheme(TestData &v)
|
||||
|
||||
if (test == "GenerateKey")
|
||||
{
|
||||
signer->AccessPrivateKey().GenerateRandom(GlobalRNG(), pairs);
|
||||
signer->AccessPrivateKey().GenerateRandom(Test::GlobalRNG(), pairs);
|
||||
verifier->AccessPublicKey().AssignFrom(signer->AccessPrivateKey());
|
||||
}
|
||||
else
|
||||
@ -260,7 +261,7 @@ void TestSignatureScheme(TestData &v)
|
||||
}
|
||||
else if (test == "PublicKeyValid")
|
||||
{
|
||||
if (!verifier->GetMaterial().Validate(GlobalRNG(), 3))
|
||||
if (!verifier->GetMaterial().Validate(Test::GlobalRNG(), 3))
|
||||
SignalTestFailure();
|
||||
return;
|
||||
}
|
||||
@ -276,11 +277,11 @@ void TestSignatureScheme(TestData &v)
|
||||
TestKeyPairValidAndConsistent(verifier->AccessMaterial(), signer->GetMaterial());
|
||||
SignatureVerificationFilter verifierFilter(*verifier, NULL, SignatureVerificationFilter::THROW_EXCEPTION);
|
||||
verifierFilter.Put((const byte *)"abc", 3);
|
||||
StringSource ss("abc", true, new SignerFilter(GlobalRNG(), *signer, new Redirector(verifierFilter)));
|
||||
StringSource ss("abc", true, new SignerFilter(Test::GlobalRNG(), *signer, new Redirector(verifierFilter)));
|
||||
}
|
||||
else if (test == "Sign")
|
||||
{
|
||||
SignerFilter f(GlobalRNG(), *signer, new HexEncoder(new FileSink(cout)));
|
||||
SignerFilter f(Test::GlobalRNG(), *signer, new HexEncoder(new FileSink(std::cout)));
|
||||
StringSource ss(GetDecodedDatum(v, "Message"), true, new Redirector(f));
|
||||
SignalTestFailure();
|
||||
}
|
||||
@ -290,8 +291,8 @@ void TestSignatureScheme(TestData &v)
|
||||
// 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
|
||||
// likely need to be extended.
|
||||
string signature;
|
||||
SignerFilter f(GlobalRNG(), *signer, new StringSink(signature));
|
||||
std::string signature;
|
||||
SignerFilter f(Test::GlobalRNG(), *signer, new StringSink(signature));
|
||||
StringSource ss(GetDecodedDatum(v, "Message"), true, new Redirector(f));
|
||||
|
||||
if (GetDecodedDatum(v, "Signature") != signature)
|
||||
@ -336,7 +337,7 @@ void TestAsymmetricCipher(TestData &v)
|
||||
if (test == "DecryptMatch")
|
||||
{
|
||||
std::string decrypted, expected = GetDecodedDatum(v, "Plaintext");
|
||||
StringSource ss(GetDecodedDatum(v, "Ciphertext"), true, new PK_DecryptorFilter(GlobalRNG(), *decryptor, new StringSink(decrypted)));
|
||||
StringSource ss(GetDecodedDatum(v, "Ciphertext"), true, new PK_DecryptorFilter(Test::GlobalRNG(), *decryptor, new StringSink(decrypted)));
|
||||
if (decrypted != expected)
|
||||
SignalTestFailure();
|
||||
}
|
||||
@ -510,7 +511,7 @@ void TestAuthenticatedSymmetricCipher(TestData &v, const NameValuePairs &overrid
|
||||
|
||||
std::string encrypted, decrypted;
|
||||
AuthenticatedEncryptionFilter ef(*asc1, new StringSink(encrypted));
|
||||
bool macAtBegin = !mac.empty() && !GlobalRNG().GenerateBit(); // test both ways randomly
|
||||
bool macAtBegin = !mac.empty() && !Test::GlobalRNG().GenerateBit(); // test both ways randomly
|
||||
AuthenticatedDecryptionFilter df(*asc2, new StringSink(decrypted), macAtBegin ? AuthenticatedDecryptionFilter::MAC_AT_BEGIN : 0);
|
||||
|
||||
if (asc1->NeedsPrespecifiedDataLengths())
|
||||
@ -646,7 +647,7 @@ void TestKeyDerivationFunction(TestData &v)
|
||||
|
||||
bool GetField(std::istream &is, std::string &name, std::string &value)
|
||||
{
|
||||
name.resize(0); // GCC workaround: 2.95.3 doesn't have clear()
|
||||
name.clear();
|
||||
is >> name;
|
||||
|
||||
if (name.empty())
|
||||
@ -655,7 +656,7 @@ bool GetField(std::istream &is, std::string &name, std::string &value)
|
||||
if (name[name.size()-1] != ':')
|
||||
{
|
||||
char c;
|
||||
is >> skipws >> c;
|
||||
is >> std::skipws >> c;
|
||||
if (c != ':')
|
||||
SignalTestError();
|
||||
}
|
||||
@ -667,7 +668,7 @@ bool GetField(std::istream &is, std::string &name, std::string &value)
|
||||
|
||||
// VC60 workaround: getline bug
|
||||
char buffer[128];
|
||||
value.resize(0); // GCC workaround: 2.95.3 doesn't have clear()
|
||||
value.clear();
|
||||
bool continueLine, space = false;
|
||||
|
||||
do
|
||||
@ -704,7 +705,7 @@ bool GetField(std::istream &is, std::string &name, std::string &value)
|
||||
if (space && (name == "Modulus" || name == "SubgroupOrder" || name == "SubgroupGenerator" ||
|
||||
name == "PublicElement" || name == "PrivateExponent" || name == "Signature"))
|
||||
{
|
||||
string temp;
|
||||
std::string temp;
|
||||
temp.reserve(value.size());
|
||||
|
||||
std::string::const_iterator it;
|
||||
@ -725,25 +726,25 @@ void OutputPair(const NameValuePairs &v, const char *name)
|
||||
Integer x;
|
||||
bool b = v.GetValue(name, x);
|
||||
CRYPTOPP_UNUSED(b); CRYPTOPP_ASSERT(b);
|
||||
cout << name << ": \\\n ";
|
||||
x.Encode(HexEncoder(new FileSink(cout), false, 64, "\\\n ").Ref(), x.MinEncodedSize());
|
||||
cout << endl;
|
||||
std::cout << name << ": \\\n ";
|
||||
x.Encode(HexEncoder(new FileSink(std::cout), false, 64, "\\\n ").Ref(), x.MinEncodedSize());
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void OutputNameValuePairs(const NameValuePairs &v)
|
||||
{
|
||||
std::string names = v.GetValueNames();
|
||||
string::size_type i = 0;
|
||||
std::string::size_type i = 0;
|
||||
while (i < names.size())
|
||||
{
|
||||
string::size_type j = names.find_first_of (';', i);
|
||||
std::string::size_type j = names.find_first_of (';', i);
|
||||
|
||||
if (j == string::npos)
|
||||
if (j == std::string::npos)
|
||||
return;
|
||||
else
|
||||
{
|
||||
std::string name = names.substr(i, j-i);
|
||||
if (name.find(':') == string::npos)
|
||||
if (name.find(':') == std::string::npos)
|
||||
OutputPair(v, name.c_str());
|
||||
}
|
||||
|
||||
@ -787,7 +788,7 @@ void TestDataFile(std::string filename, const NameValuePairs &overrideParameters
|
||||
if (lastAlgName != GetRequiredDatum(v, "Name"))
|
||||
{
|
||||
lastAlgName = GetRequiredDatum(v, "Name");
|
||||
cout << "\nTesting " << algType.c_str() << " algorithm " << lastAlgName.c_str() << ".\n";
|
||||
std::cout << "\nTesting " << algType.c_str() << " algorithm " << lastAlgName.c_str() << ".\n";
|
||||
}
|
||||
|
||||
try
|
||||
@ -814,24 +815,24 @@ void TestDataFile(std::string filename, const NameValuePairs &overrideParameters
|
||||
}
|
||||
catch (const TestFailure &)
|
||||
{
|
||||
cout << "\nTest failed.\n";
|
||||
std::cout << "\nTest failed.\n";
|
||||
}
|
||||
catch (const CryptoPP::Exception &e)
|
||||
{
|
||||
cout << "\nCryptoPP::Exception caught: " << e.what() << endl;
|
||||
std::cout << "\nCryptoPP::Exception caught: " << e.what() << std::endl;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
cout << "\nstd::exception caught: " << e.what() << endl;
|
||||
std::cout << "\nstd::exception caught: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
if (failed)
|
||||
{
|
||||
cout << "Skipping to next test.\n";
|
||||
std::cout << "Skipping to next test.\n";
|
||||
failedTests++;
|
||||
}
|
||||
else
|
||||
cout << "." << flush;
|
||||
std::cout << "." << std::flush;
|
||||
|
||||
totalTests++;
|
||||
}
|
||||
@ -843,9 +844,11 @@ bool RunTestDataFile(const char *filename, const NameValuePairs &overrideParamet
|
||||
s_thorough = thorough;
|
||||
unsigned int totalTests = 0, failedTests = 0;
|
||||
TestDataFile((filename ? filename : ""), overrideParameters, totalTests, failedTests);
|
||||
cout << dec << "\nTests complete. Total tests = " << totalTests << ". Failed tests = " << failedTests << "." << endl;
|
||||
std::cout << std::dec << "\nTests complete. Total tests = " << totalTests << ". Failed tests = " << failedTests << "." << std::endl;
|
||||
if (failedTests != 0)
|
||||
cout << "SOME TESTS FAILED!\n";
|
||||
std::cout << "SOME TESTS FAILED!\n";
|
||||
return failedTests == 0;
|
||||
}
|
||||
|
||||
NAMESPACE_END // Test
|
||||
NAMESPACE_END // CryptoPP
|
||||
|
388
test.cpp
388
test.cpp
@ -1,4 +1,5 @@
|
||||
// test.cpp - originally written and placed in the public domain by Wei Dai
|
||||
// CryptoPP::Test namespace added by JW in February 2017
|
||||
|
||||
#define CRYPTOPP_DEFAULT_NO_DLL
|
||||
#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
|
||||
@ -66,12 +67,7 @@
|
||||
# pragma strict_gs_check (on)
|
||||
#endif
|
||||
|
||||
#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
|
||||
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
USING_NAMESPACE(CryptoPP)
|
||||
USING_NAMESPACE(std)
|
||||
|
||||
const int MAX_PHRASE_LENGTH=250;
|
||||
|
||||
@ -79,8 +75,8 @@ void RegisterFactories();
|
||||
void PrintSeedAndThreads(const std::string& seed);
|
||||
|
||||
void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed);
|
||||
string RSAEncryptString(const char *pubFilename, const char *seed, const char *message);
|
||||
string RSADecryptString(const char *privFilename, const char *ciphertext);
|
||||
std::string RSAEncryptString(const char *pubFilename, const char *seed, const char *message);
|
||||
std::string RSADecryptString(const char *privFilename, const char *ciphertext);
|
||||
void RSASignFile(const char *privFilename, const char *messageFilename, const char *signatureFilename);
|
||||
bool RSAVerifyFile(const char *pubFilename, const char *messageFilename, const char *signatureFilename);
|
||||
|
||||
@ -89,8 +85,8 @@ void HmacFile(const char *hexKey, const char *file);
|
||||
|
||||
void AES_CTR_Encrypt(const char *hexKey, const char *hexIV, const char *infile, const char *outfile);
|
||||
|
||||
string EncryptString(const char *plaintext, const char *passPhrase);
|
||||
string DecryptString(const char *ciphertext, const char *passPhrase);
|
||||
std::string EncryptString(const char *plaintext, const char *passPhrase);
|
||||
std::string DecryptString(const char *ciphertext, const char *passPhrase);
|
||||
|
||||
void EncryptFile(const char *in, const char *out, const char *passPhrase);
|
||||
void DecryptFile(const char *in, const char *out, const char *passPhrase);
|
||||
@ -119,11 +115,19 @@ void PrintSeedAndThreads(const std::string& seed);
|
||||
|
||||
int (*AdhocTest)(int argc, char *argv[]) = NULL;
|
||||
|
||||
namespace { OFB_Mode<AES>::Encryption s_globalRNG; }
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
NAMESPACE_BEGIN(Test)
|
||||
|
||||
ANONYMOUS_NAMESPACE_BEGIN
|
||||
OFB_Mode<AES>::Encryption s_globalRNG;
|
||||
NAMESPACE_END
|
||||
|
||||
RandomNumberGenerator & GlobalRNG()
|
||||
{
|
||||
return dynamic_cast<RandomNumberGenerator&>(s_globalRNG);
|
||||
}
|
||||
NAMESPACE_END // Test
|
||||
NAMESPACE_END // CryptoPP
|
||||
|
||||
// See misc.h and trap.h for comments and usage
|
||||
#if defined(CRYPTOPP_DEBUG) && defined(UNIX_SIGNALS_AVAILABLE)
|
||||
@ -153,7 +157,7 @@ int CRYPTOPP_API main(int argc, char *argv[])
|
||||
seed.resize(16, ' ');
|
||||
|
||||
// Fetch the SymmetricCipher interface, not the RandomNumberGenerator interface, to key the underlying cipher
|
||||
OFB_Mode<AES>::Encryption& aesg = dynamic_cast<OFB_Mode<AES>::Encryption&>(GlobalRNG());
|
||||
OFB_Mode<AES>::Encryption& aesg = dynamic_cast<OFB_Mode<AES>::Encryption&>(Test::GlobalRNG());
|
||||
aesg.SetKeyWithIV((byte *)seed.data(), 16, (byte *)seed.data());
|
||||
|
||||
std::string command, executableName, macFilename;
|
||||
@ -168,18 +172,18 @@ int CRYPTOPP_API main(int argc, char *argv[])
|
||||
char thisSeed[1024], privFilename[128], pubFilename[128];
|
||||
unsigned int keyLength;
|
||||
|
||||
cout << "Key length in bits: ";
|
||||
cin >> keyLength;
|
||||
std::cout << "Key length in bits: ";
|
||||
std::cin >> keyLength;
|
||||
|
||||
cout << "\nSave private key to file: ";
|
||||
cin >> privFilename;
|
||||
std::cout << "\nSave private key to file: ";
|
||||
std::cin >> privFilename;
|
||||
|
||||
cout << "\nSave public key to file: ";
|
||||
cin >> pubFilename;
|
||||
std::cout << "\nSave public key to file: ";
|
||||
std::cin >> pubFilename;
|
||||
|
||||
cout << "\nRandom Seed: ";
|
||||
ws(cin);
|
||||
cin.getline(thisSeed, 1024);
|
||||
std::cout << "\nRandom Seed: ";
|
||||
std::ws(std::cin);
|
||||
std::cin.getline(thisSeed, 1024);
|
||||
|
||||
GenerateRSAKey(keyLength, privFilename, pubFilename, thisSeed);
|
||||
}
|
||||
@ -188,56 +192,56 @@ int CRYPTOPP_API main(int argc, char *argv[])
|
||||
else if (command == "rv")
|
||||
{
|
||||
bool verified = RSAVerifyFile(argv[2], argv[3], argv[4]);
|
||||
cout << (verified ? "valid signature" : "invalid signature") << endl;
|
||||
std::cout << (verified ? "valid signature" : "invalid signature") << std::endl;
|
||||
}
|
||||
else if (command == "r")
|
||||
{
|
||||
char privFilename[128], pubFilename[128];
|
||||
char thisSeed[1024], message[1024];
|
||||
|
||||
cout << "Private key file: ";
|
||||
cin >> privFilename;
|
||||
std::cout << "Private key file: ";
|
||||
std::cin >> privFilename;
|
||||
|
||||
cout << "\nPublic key file: ";
|
||||
cin >> pubFilename;
|
||||
std::cout << "\nPublic key file: ";
|
||||
std::cin >> pubFilename;
|
||||
|
||||
cout << "\nRandom Seed: ";
|
||||
ws(cin);
|
||||
cin.getline(thisSeed, 1024);
|
||||
std::cout << "\nRandom Seed: ";
|
||||
std::ws(std::cin);
|
||||
std::cin.getline(thisSeed, 1024);
|
||||
|
||||
cout << "\nMessage: ";
|
||||
cin.getline(message, 1024);
|
||||
std::cout << "\nMessage: ";
|
||||
std::cin.getline(message, 1024);
|
||||
|
||||
string ciphertext = RSAEncryptString(pubFilename, thisSeed, message);
|
||||
cout << "\nCiphertext: " << ciphertext << endl;
|
||||
std::string ciphertext = RSAEncryptString(pubFilename, thisSeed, message);
|
||||
std::cout << "\nCiphertext: " << ciphertext << std::endl;
|
||||
|
||||
string decrypted = RSADecryptString(privFilename, ciphertext.c_str());
|
||||
cout << "\nDecrypted: " << decrypted << endl;
|
||||
std::string decrypted = RSADecryptString(privFilename, ciphertext.c_str());
|
||||
std::cout << "\nDecrypted: " << decrypted << std::endl;
|
||||
}
|
||||
else if (command == "mt")
|
||||
{
|
||||
MaurerRandomnessTest mt;
|
||||
FileStore fs(argv[2]);
|
||||
fs.TransferAllTo(mt);
|
||||
cout << "Maurer Test Value: " << mt.GetTestValue() << endl;
|
||||
std::cout << "Maurer Test Value: " << mt.GetTestValue() << std::endl;
|
||||
}
|
||||
else if (command == "mac_dll")
|
||||
{
|
||||
std::string fname(argv[2] ? argv[2] : "");
|
||||
|
||||
// sanity check on file size
|
||||
std::fstream dllFile(fname.c_str(), ios::in | ios::out | ios::binary);
|
||||
std::fstream dllFile(fname.c_str(), std::ios::in | std::ios::out | std::ios::binary);
|
||||
if (!dllFile.good())
|
||||
{
|
||||
cerr << "Failed to open file \"" << fname << "\"\n";
|
||||
std::cerr << "Failed to open file \"" << fname << "\"\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::ifstream::pos_type fileEnd = dllFile.seekg(0, std::ios_base::end).tellg();
|
||||
if (fileEnd > 20*1000*1000)
|
||||
{
|
||||
cerr << "Input file " << fname << " is too large";
|
||||
cerr << "(size is " << fileEnd << ").\n";
|
||||
std::cerr << "Input file " << fname << " is too large";
|
||||
std::cerr << "(size is " << fileEnd << ").\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -253,7 +257,7 @@ int CRYPTOPP_API main(int argc, char *argv[])
|
||||
word16 optionalHeaderMagic = *(word16 *)(void *)(buf+optionalHeaderPos);
|
||||
if (optionalHeaderMagic != 0x10b && optionalHeaderMagic != 0x20b)
|
||||
{
|
||||
cerr << "Target file is not a PE32 or PE32+ image.\n";
|
||||
std::cerr << "Target file is not a PE32 or PE32+ image.\n";
|
||||
return 3;
|
||||
}
|
||||
word32 checksumPos = optionalHeaderPos + 64;
|
||||
@ -261,14 +265,14 @@ int CRYPTOPP_API main(int argc, char *argv[])
|
||||
word32 certificateTablePos = *(word32 *)(void *)(buf+certificateTableDirectoryPos);
|
||||
word32 certificateTableSize = *(word32 *)(void *)(buf+certificateTableDirectoryPos+4);
|
||||
if (certificateTableSize != 0)
|
||||
cerr << "Warning: certificate table (IMAGE_DIRECTORY_ENTRY_SECURITY) of target image is not empty.\n";
|
||||
std::cerr << "Warning: certificate table (IMAGE_DIRECTORY_ENTRY_SECURITY) of target image is not empty.\n";
|
||||
|
||||
// find where to place computed MAC
|
||||
byte mac[] = CRYPTOPP_DUMMY_DLL_MAC;
|
||||
byte *found = std::search(buf.begin(), buf.end(), mac+0, mac+sizeof(mac));
|
||||
if (found == buf.end())
|
||||
{
|
||||
cerr << "MAC placeholder not found. The MAC may already be placed.\n";
|
||||
std::cerr << "MAC placeholder not found. The MAC may already be placed.\n";
|
||||
return 2;
|
||||
}
|
||||
word32 macPos = (unsigned int)(found-buf.begin());
|
||||
@ -284,7 +288,7 @@ int CRYPTOPP_API main(int argc, char *argv[])
|
||||
f.PutMessageEnd(buf.begin(), buf.size());
|
||||
|
||||
// Encode MAC
|
||||
string hexMac;
|
||||
std::string hexMac;
|
||||
HexEncoder encoder;
|
||||
encoder.Put(mac, sizeof(mac)), encoder.MessageEnd();
|
||||
hexMac.resize(static_cast<size_t>(encoder.MaxRetrievable()));
|
||||
@ -308,24 +312,24 @@ int CRYPTOPP_API main(int argc, char *argv[])
|
||||
fname = "TestVectors/" + fname + ".txt";
|
||||
|
||||
PrintSeedAndThreads(seed);
|
||||
return !RunTestDataFile(fname.c_str());
|
||||
return !Test::RunTestDataFile(fname.c_str());
|
||||
}
|
||||
else if (command == "t")
|
||||
{
|
||||
// VC60 workaround: use char array instead of std::string to workaround MSVC's getline bug
|
||||
char passPhrase[MAX_PHRASE_LENGTH], plaintext[1024];
|
||||
|
||||
cout << "Passphrase: ";
|
||||
cin.getline(passPhrase, MAX_PHRASE_LENGTH);
|
||||
std::cout << "Passphrase: ";
|
||||
std::cin.getline(passPhrase, MAX_PHRASE_LENGTH);
|
||||
|
||||
cout << "\nPlaintext: ";
|
||||
cin.getline(plaintext, 1024);
|
||||
std::cout << "\nPlaintext: ";
|
||||
std::cin.getline(plaintext, 1024);
|
||||
|
||||
string ciphertext = EncryptString(plaintext, passPhrase);
|
||||
cout << "\nCiphertext: " << ciphertext << endl;
|
||||
std::string ciphertext = EncryptString(plaintext, passPhrase);
|
||||
std::cout << "\nCiphertext: " << ciphertext << std::endl;
|
||||
|
||||
string decrypted = DecryptString(ciphertext.c_str(), passPhrase);
|
||||
cout << "\nDecrypted: " << decrypted << endl;
|
||||
std::string decrypted = DecryptString(ciphertext.c_str(), passPhrase);
|
||||
std::cout << "\nDecrypted: " << decrypted << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -340,8 +344,8 @@ int CRYPTOPP_API main(int argc, char *argv[])
|
||||
else if (command == "e" || command == "d")
|
||||
{
|
||||
char passPhrase[MAX_PHRASE_LENGTH];
|
||||
cout << "Passphrase: ";
|
||||
cin.getline(passPhrase, MAX_PHRASE_LENGTH);
|
||||
std::cout << "Passphrase: ";
|
||||
std::cin.getline(passPhrase, MAX_PHRASE_LENGTH);
|
||||
if (command == "e")
|
||||
EncryptFile(argv[2], argv[3], passPhrase);
|
||||
else
|
||||
@ -350,23 +354,23 @@ int CRYPTOPP_API main(int argc, char *argv[])
|
||||
else if (command == "ss")
|
||||
{
|
||||
char thisSeed[1024];
|
||||
cout << "\nRandom Seed: ";
|
||||
ws(cin);
|
||||
cin.getline(thisSeed, 1024);
|
||||
SecretShareFile(StringToValue<int, true>(argv[2]), StringToValue<int, true>(argv[3]), argv[4], thisSeed);
|
||||
std::cout << "\nRandom Seed: ";
|
||||
std::ws(std::cin);
|
||||
std::cin.getline(thisSeed, 1024);
|
||||
SecretShareFile(Test::StringToValue<int, true>(argv[2]), Test::StringToValue<int, true>(argv[3]), argv[4], thisSeed);
|
||||
}
|
||||
else if (command == "sr")
|
||||
SecretRecoverFile(argc-3, argv[2], argv+3);
|
||||
else if (command == "id")
|
||||
InformationDisperseFile(StringToValue<int, true>(argv[2]), StringToValue<int, true>(argv[3]), argv[4]);
|
||||
InformationDisperseFile(Test::StringToValue<int, true>(argv[2]), Test::StringToValue<int, true>(argv[3]), argv[4]);
|
||||
else if (command == "ir")
|
||||
InformationRecoverFile(argc-3, argv[2], argv+3);
|
||||
else if (command == "v" || command == "vv")
|
||||
return !Validate(argc>2 ? StringToValue<int, true>(argv[2]) : 0, argv[1][1] == 'v', argc>3 ? argv[3] : NULL);
|
||||
return !Validate(argc>2 ? Test::StringToValue<int, true>(argv[2]) : 0, argv[1][1] == 'v', argc>3 ? argv[3] : NULL);
|
||||
else if (command == "b")
|
||||
BenchmarkAll(argc<3 ? 1 : StringToValue<float, true>(argv[2]), argc<4 ? 0.0f : StringToValue<float, true>(argv[3])*1e9);
|
||||
Test::BenchmarkAll(argc<3 ? 1 : Test::StringToValue<float, true>(argv[2]), argc<4 ? 0.0f : Test::StringToValue<float, true>(argv[3])*1e9);
|
||||
else if (command == "b2")
|
||||
BenchmarkAll2(argc<3 ? 1 : StringToValue<float, true>(argv[2]), argc<4 ? 0.0f : StringToValue<float, true>(argv[3])*1e9);
|
||||
Test::BenchmarkAll2(argc<3 ? 1 : Test::StringToValue<float, true>(argv[2]), argc<4 ? 0.0f : Test::StringToValue<float, true>(argv[3])*1e9);
|
||||
else if (command == "z")
|
||||
GzipFile(argv[3], argv[4], argv[2][0]-'0');
|
||||
else if (command == "u")
|
||||
@ -383,7 +387,7 @@ int CRYPTOPP_API main(int argc, char *argv[])
|
||||
return (*AdhocTest)(argc, argv);
|
||||
else
|
||||
{
|
||||
cerr << "AdhocTest not defined.\n";
|
||||
std::cerr << "AdhocTest not defined.\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -393,28 +397,28 @@ int CRYPTOPP_API main(int argc, char *argv[])
|
||||
AES_CTR_Encrypt(argv[2], argv[3], argv[4], argv[5]);
|
||||
else if (command == "h")
|
||||
{
|
||||
FileSource usage(CRYPTOPP_DATA_DIR "TestData/usage.dat", true, new FileSink(cout));
|
||||
FileSource usage(CRYPTOPP_DATA_DIR "TestData/usage.dat", true, new FileSink(std::cout));
|
||||
return 1;
|
||||
}
|
||||
else if (command == "V")
|
||||
{
|
||||
cout << CRYPTOPP_VERSION / 100 << '.' << (CRYPTOPP_VERSION % 100) / 10 << '.' << CRYPTOPP_VERSION % 10 << endl;
|
||||
std::cout << CRYPTOPP_VERSION / 100 << '.' << (CRYPTOPP_VERSION % 100) / 10 << '.' << CRYPTOPP_VERSION % 10 << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "Unrecognized command. Run \"cryptest h\" to obtain usage information.\n";
|
||||
std::cerr << "Unrecognized command. Run \"cryptest h\" to obtain usage information.\n";
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
catch(const CryptoPP::Exception &e)
|
||||
{
|
||||
cout << "\nCryptoPP::Exception caught: " << e.what() << endl;
|
||||
std::cout << "\nCryptoPP::Exception caught: " << e.what() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
cout << "\nstd::exception caught: " << e.what() << endl;
|
||||
std::cout << "\nstd::exception caught: " << e.what() << std::endl;
|
||||
return -2;
|
||||
}
|
||||
} // End main()
|
||||
@ -428,13 +432,14 @@ void FIPS140_GenerateRandomFiles()
|
||||
for (unsigned int i=0; i<100000; i++)
|
||||
store.TransferTo(FileSink((IntToString(i) + ".rnd").c_str()).Ref(), 20000);
|
||||
#else
|
||||
cout << "OS provided RNG not available.\n";
|
||||
std::cout << "OS provided RNG not available.\n";
|
||||
exit(-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class T, bool NON_NEGATIVE>
|
||||
T StringToValue(const std::string& str) {
|
||||
T Test::StringToValue(const std::string& str)
|
||||
{
|
||||
std::istringstream iss(str);
|
||||
|
||||
// Arbitrary, but we need to clear a Coverity finding TAINTED_SCALAR
|
||||
@ -455,7 +460,7 @@ T StringToValue(const std::string& str) {
|
||||
}
|
||||
|
||||
template<>
|
||||
int StringToValue<int, true>(const std::string& str)
|
||||
int Test::StringToValue<int, true>(const std::string& str)
|
||||
{
|
||||
Integer n(str.c_str());
|
||||
long l = n.ConvertToLong();
|
||||
@ -469,7 +474,7 @@ int StringToValue<int, true>(const std::string& str)
|
||||
|
||||
void PrintSeedAndThreads(const std::string& seed)
|
||||
{
|
||||
cout << "Using seed: " << seed << endl;
|
||||
std::cout << "Using seed: " << seed << std::endl;
|
||||
|
||||
#ifdef _OPENMP
|
||||
int tc = 0;
|
||||
@ -506,7 +511,7 @@ void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char
|
||||
pubFile.MessageEnd();
|
||||
}
|
||||
|
||||
string RSAEncryptString(const char *pubFilename, const char *seed, const char *message)
|
||||
std::string RSAEncryptString(const char *pubFilename, const char *seed, const char *message)
|
||||
{
|
||||
FileSource pubFile(pubFilename, true, new HexDecoder);
|
||||
RSAES_OAEP_SHA_Encryptor pub(pubFile);
|
||||
@ -514,18 +519,18 @@ string RSAEncryptString(const char *pubFilename, const char *seed, const char *m
|
||||
RandomPool randPool;
|
||||
randPool.IncorporateEntropy((byte *)seed, strlen(seed));
|
||||
|
||||
string result;
|
||||
std::string result;
|
||||
StringSource(message, true, new PK_EncryptorFilter(randPool, pub, new HexEncoder(new StringSink(result))));
|
||||
return result;
|
||||
}
|
||||
|
||||
string RSADecryptString(const char *privFilename, const char *ciphertext)
|
||||
std::string RSADecryptString(const char *privFilename, const char *ciphertext)
|
||||
{
|
||||
FileSource privFile(privFilename, true, new HexDecoder);
|
||||
RSAES_OAEP_SHA_Decryptor priv(privFile);
|
||||
|
||||
string result;
|
||||
StringSource(ciphertext, true, new HexDecoder(new PK_DecryptorFilter(GlobalRNG(), priv, new StringSink(result))));
|
||||
std::string result;
|
||||
StringSource(ciphertext, true, new HexDecoder(new PK_DecryptorFilter(Test::GlobalRNG(), priv, new StringSink(result))));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -533,7 +538,7 @@ void RSASignFile(const char *privFilename, const char *messageFilename, const ch
|
||||
{
|
||||
FileSource privFile(privFilename, true, new HexDecoder);
|
||||
RSASS<PKCS1v15, SHA>::Signer priv(privFile);
|
||||
FileSource f(messageFilename, true, new SignerFilter(GlobalRNG(), priv, new HexEncoder(new FileSink(signatureFilename))));
|
||||
FileSource f(messageFilename, true, new SignerFilter(Test::GlobalRNG(), priv, new HexEncoder(new FileSink(signatureFilename))));
|
||||
}
|
||||
|
||||
bool RSAVerifyFile(const char *pubFilename, const char *messageFilename, const char *signatureFilename)
|
||||
@ -562,6 +567,7 @@ void DigestFile(const char *filename)
|
||||
Tiger tiger;
|
||||
SHA512 sha512;
|
||||
Whirlpool whirlpool;
|
||||
|
||||
vector_member_ptrs<HashFilter> filters(6);
|
||||
filters[0].reset(new HashFilter(sha));
|
||||
filters[1].reset(new HashFilter(ripemd));
|
||||
@ -576,12 +582,12 @@ void DigestFile(const char *filename)
|
||||
channelSwitch->AddDefaultRoute(*filters[i]);
|
||||
FileSource(filename, true, channelSwitch.release());
|
||||
|
||||
HexEncoder encoder(new FileSink(cout), false);
|
||||
HexEncoder encoder(new FileSink(std::cout), false);
|
||||
for (i=0; i<filters.size(); i++)
|
||||
{
|
||||
cout << filters[i]->AlgorithmName() << ": ";
|
||||
std::cout << filters[i]->AlgorithmName() << ": ";
|
||||
filters[i]->TransferTo(encoder);
|
||||
cout << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
@ -590,7 +596,7 @@ void HmacFile(const char *hexKey, const char *file)
|
||||
member_ptr<MessageAuthenticationCode> mac;
|
||||
if (strcmp(hexKey, "selftest") == 0)
|
||||
{
|
||||
cerr << "Computing HMAC/SHA1 value for self test.\n";
|
||||
std::cerr << "Computing HMAC/SHA1 value for self test.\n";
|
||||
mac.reset(NewIntegrityCheckingMAC());
|
||||
}
|
||||
else
|
||||
@ -599,7 +605,7 @@ void HmacFile(const char *hexKey, const char *file)
|
||||
StringSource(hexKey, true, new HexDecoder(new StringSink(decodedKey)));
|
||||
mac.reset(new HMAC<SHA1>((const byte *)decodedKey.data(), decodedKey.size()));
|
||||
}
|
||||
FileSource(file, true, new HashFilter(*mac, new HexEncoder(new FileSink(cout))));
|
||||
FileSource(file, true, new HashFilter(*mac, new HexEncoder(new FileSink(std::cout))));
|
||||
}
|
||||
|
||||
void AES_CTR_Encrypt(const char *hexKey, const char *hexIV, const char *infile, const char *outfile)
|
||||
@ -610,9 +616,9 @@ void AES_CTR_Encrypt(const char *hexKey, const char *hexIV, const char *infile,
|
||||
FileSource(infile, true, new StreamTransformationFilter(aes, new FileSink(outfile)));
|
||||
}
|
||||
|
||||
string EncryptString(const char *instr, const char *passPhrase)
|
||||
std::string EncryptString(const char *instr, const char *passPhrase)
|
||||
{
|
||||
string outstr;
|
||||
std::string outstr;
|
||||
|
||||
DefaultEncryptorWithMAC encryptor(passPhrase, new HexEncoder(new StringSink(outstr)));
|
||||
encryptor.Put((byte *)instr, strlen(instr));
|
||||
@ -621,9 +627,9 @@ string EncryptString(const char *instr, const char *passPhrase)
|
||||
return outstr;
|
||||
}
|
||||
|
||||
string DecryptString(const char *instr, const char *passPhrase)
|
||||
std::string DecryptString(const char *instr, const char *passPhrase)
|
||||
{
|
||||
string outstr;
|
||||
std::string outstr;
|
||||
|
||||
HexDecoder decryptor(new DefaultDecryptorWithMAC(passPhrase, new StringSink(outstr)));
|
||||
decryptor.Put((byte *)instr, strlen(instr));
|
||||
@ -655,14 +661,14 @@ void SecretShareFile(int threshold, int nShares, const char *filename, const cha
|
||||
FileSource source(filename, false, new SecretSharing(rng, threshold, nShares, channelSwitch = new ChannelSwitch));
|
||||
|
||||
vector_member_ptrs<FileSink> fileSinks(nShares);
|
||||
string channel;
|
||||
std::string channel;
|
||||
for (int i=0; i<nShares; i++)
|
||||
{
|
||||
char extension[5] = ".000";
|
||||
extension[1]='0'+byte(i/100);
|
||||
extension[2]='0'+byte((i/10)%10);
|
||||
extension[3]='0'+byte(i%10);
|
||||
fileSinks[i].reset(new FileSink((string(filename)+extension).c_str()));
|
||||
fileSinks[i].reset(new FileSink((std::string(filename)+extension).c_str()));
|
||||
|
||||
channel = WordToString<word32>(i);
|
||||
fileSinks[i]->Put((const byte *)channel.data(), 4);
|
||||
@ -688,7 +694,7 @@ void SecretRecoverFile(int threshold, const char *outFilename, char *const *inFi
|
||||
fileSources[i].reset(new FileSource(inFilenames[i], false));
|
||||
fileSources[i]->Pump(4);
|
||||
fileSources[i]->Get(channel, 4);
|
||||
fileSources[i]->Attach(new ChannelSwitch(recovery, string((char *)channel.begin(), 4)));
|
||||
fileSources[i]->Attach(new ChannelSwitch(recovery, std::string((char *)channel.begin(), 4)));
|
||||
}
|
||||
|
||||
while (fileSources[0]->Pump(256))
|
||||
@ -709,14 +715,14 @@ void InformationDisperseFile(int threshold, int nShares, const char *filename)
|
||||
FileSource source(filename, false, new InformationDispersal(threshold, nShares, channelSwitch = new ChannelSwitch));
|
||||
|
||||
vector_member_ptrs<FileSink> fileSinks(nShares);
|
||||
string channel;
|
||||
std::string channel;
|
||||
for (int i=0; i<nShares; i++)
|
||||
{
|
||||
char extension[5] = ".000";
|
||||
extension[1]='0'+byte(i/100);
|
||||
extension[2]='0'+byte((i/10)%10);
|
||||
extension[3]='0'+byte(i%10);
|
||||
fileSinks[i].reset(new FileSink((string(filename)+extension).c_str()));
|
||||
fileSinks[i].reset(new FileSink((std::string(filename)+extension).c_str()));
|
||||
|
||||
channel = WordToString<word32>(i);
|
||||
fileSinks[i]->Put((const byte *)channel.data(), 4);
|
||||
@ -742,7 +748,7 @@ void InformationRecoverFile(int threshold, const char *outFilename, char *const
|
||||
fileSources[i].reset(new FileSource(inFilenames[i], false));
|
||||
fileSources[i]->Pump(4);
|
||||
fileSources[i]->Get(channel, 4);
|
||||
fileSources[i]->Attach(new ChannelSwitch(recovery, string((char *)channel.begin(), 4)));
|
||||
fileSources[i]->Attach(new ChannelSwitch(recovery, std::string((char *)channel.begin(), 4)));
|
||||
}
|
||||
|
||||
while (fileSources[0]->Pump(256))
|
||||
@ -832,18 +838,18 @@ void ForwardTcpPort(const char *sourcePortName, const char *destinationHost, con
|
||||
if(err != 0)
|
||||
throw Socket::Err(sockListen, "setsockopt", sockListen.GetLastError());
|
||||
|
||||
cout << "Listing on port " << sourcePort << ".\n";
|
||||
std::cout << "Listing on port " << sourcePort << ".\n";
|
||||
sockListen.Listen();
|
||||
|
||||
sockListen.Accept(sockSource);
|
||||
cout << "Connection accepted on port " << sourcePort << ".\n";
|
||||
std::cout << "Connection accepted on port " << sourcePort << ".\n";
|
||||
sockListen.CloseSocket();
|
||||
|
||||
cout << "Making connection to " << destinationHost << ", port " << destinationPort << ".\n";
|
||||
std::cout << "Making connection to " << destinationHost << ", port " << destinationPort << ".\n";
|
||||
sockDestination.Create();
|
||||
sockDestination.Connect(destinationHost, destinationPort);
|
||||
|
||||
cout << "Connection made to " << destinationHost << ", starting to forward.\n";
|
||||
std::cout << "Connection made to " << destinationHost << ", starting to forward.\n";
|
||||
|
||||
SocketSource out(sockSource, false, new SocketSink(sockDestination));
|
||||
SocketSource in(sockDestination, false, new SocketSink(sockSource));
|
||||
@ -861,22 +867,22 @@ void ForwardTcpPort(const char *sourcePortName, const char *destinationHost, con
|
||||
|
||||
if (!out.SourceExhausted())
|
||||
{
|
||||
cout << "o" << flush;
|
||||
std::cout << "o" << std::flush;
|
||||
out.PumpAll2(false);
|
||||
if (out.SourceExhausted())
|
||||
cout << "EOF received on source socket.\n";
|
||||
std::cout << "EOF received on source socket.\n";
|
||||
}
|
||||
|
||||
if (!in.SourceExhausted())
|
||||
{
|
||||
cout << "i" << flush;
|
||||
std::cout << "i" << std::flush;
|
||||
in.PumpAll2(false);
|
||||
if (in.SourceExhausted())
|
||||
cout << "EOF received on destination socket.\n";
|
||||
std::cout << "EOF received on destination socket.\n";
|
||||
}
|
||||
}
|
||||
#else
|
||||
cout << "Socket support was not enabled at compile time.\n";
|
||||
std::cout << "Socket support was not enabled at compile time.\n";
|
||||
exit(-1);
|
||||
#endif
|
||||
}
|
||||
@ -890,106 +896,106 @@ bool Validate(int alg, bool thorough, const char *seedInput)
|
||||
std::string seed = (seedInput ? seedInput : IntToString(time(NULL)));
|
||||
seed.resize(16, ' ');
|
||||
|
||||
OFB_Mode<AES>::Encryption& prng = dynamic_cast<OFB_Mode<AES>::Encryption&>(GlobalRNG());
|
||||
OFB_Mode<AES>::Encryption& prng = dynamic_cast<OFB_Mode<AES>::Encryption&>(Test::GlobalRNG());
|
||||
prng.SetKeyWithIV((byte *)seed.data(), 16, (byte *)seed.data());
|
||||
|
||||
PrintSeedAndThreads(seed);
|
||||
|
||||
switch (alg)
|
||||
{
|
||||
case 0: result = ValidateAll(thorough); break;
|
||||
case 1: result = TestSettings(); break;
|
||||
case 2: result = TestOS_RNG(); break;
|
||||
// case 3: result = TestSecRandom(); break;
|
||||
case 4: result = ValidateMD5(); break;
|
||||
case 5: result = ValidateSHA(); break;
|
||||
case 6: result = ValidateDES(); break;
|
||||
case 7: result = ValidateIDEA(); break;
|
||||
case 8: result = ValidateARC4(); break;
|
||||
case 9: result = ValidateRC5(); break;
|
||||
case 10: result = ValidateBlowfish(); break;
|
||||
// case 11: result = ValidateDiamond2(); break;
|
||||
case 12: result = ValidateThreeWay(); break;
|
||||
case 13: result = ValidateBBS(); break;
|
||||
case 14: result = ValidateDH(); break;
|
||||
case 15: result = ValidateRSA(); break;
|
||||
case 16: result = ValidateElGamal(); break;
|
||||
case 17: result = ValidateDSA(thorough); break;
|
||||
// case 18: result = ValidateHAVAL(); break;
|
||||
case 19: result = ValidateSAFER(); break;
|
||||
case 20: result = ValidateLUC(); break;
|
||||
case 21: result = ValidateRabin(); break;
|
||||
// case 22: result = ValidateBlumGoldwasser(); break;
|
||||
case 23: result = ValidateECP(); break;
|
||||
case 24: result = ValidateEC2N(); break;
|
||||
// case 25: result = ValidateMD5MAC(); break;
|
||||
case 26: result = ValidateGOST(); break;
|
||||
case 27: result = ValidateTiger(); break;
|
||||
case 28: result = ValidateRIPEMD(); break;
|
||||
case 29: result = ValidateHMAC(); break;
|
||||
// case 30: result = ValidateXMACC(); break;
|
||||
case 31: result = ValidateSHARK(); break;
|
||||
case 32: result = ValidateLUC_DH(); break;
|
||||
case 33: result = ValidateLUC_DL(); break;
|
||||
case 34: result = ValidateSEAL(); break;
|
||||
case 35: result = ValidateCAST(); break;
|
||||
case 36: result = ValidateSquare(); break;
|
||||
case 37: result = ValidateRC2(); break;
|
||||
case 38: result = ValidateRC6(); break;
|
||||
case 39: result = ValidateMARS(); break;
|
||||
case 40: result = ValidateRW(); break;
|
||||
case 41: result = ValidateMD2(); break;
|
||||
case 42: result = ValidateNR(); break;
|
||||
case 43: result = ValidateMQV(); break;
|
||||
case 44: result = ValidateRijndael(); break;
|
||||
case 45: result = ValidateTwofish(); break;
|
||||
case 46: result = ValidateSerpent(); break;
|
||||
case 47: result = ValidateCipherModes(); break;
|
||||
case 48: result = ValidateCRC32(); break;
|
||||
case 49: result = ValidateCRC32C(); break;
|
||||
case 50: result = ValidateECDSA(); break;
|
||||
case 51: result = ValidateECGDSA(); break;
|
||||
case 52: result = ValidateXTR_DH(); break;
|
||||
case 53: result = ValidateSKIPJACK(); break;
|
||||
case 54: result = ValidateSHA2(); break;
|
||||
case 55: result = ValidatePanama(); break;
|
||||
case 56: result = ValidateAdler32(); break;
|
||||
case 57: result = ValidateMD4(); break;
|
||||
case 58: result = ValidatePBKDF(); break;
|
||||
case 59: result = ValidateESIGN(); break;
|
||||
case 60: result = ValidateDLIES(); break;
|
||||
case 61: result = ValidateBaseCode(); break;
|
||||
case 62: result = ValidateSHACAL2(); break;
|
||||
case 63: result = ValidateCamellia(); break;
|
||||
case 64: result = ValidateWhirlpool(); break;
|
||||
case 65: result = ValidateTTMAC(); break;
|
||||
case 66: result = ValidateSalsa(); break;
|
||||
case 67: result = ValidateSosemanuk(); break;
|
||||
case 68: result = ValidateVMAC(); break;
|
||||
case 69: result = ValidateCCM(); break;
|
||||
case 70: result = ValidateGCM(); break;
|
||||
case 71: result = ValidateCMAC(); break;
|
||||
case 72: result = ValidateHKDF(); break;
|
||||
case 73: result = ValidateBLAKE2s(); break;
|
||||
case 74: result = ValidateBLAKE2b(); break;
|
||||
case 75: result = ValidatePoly1305(); break;
|
||||
case 76: result = ValidateSipHash(); break;
|
||||
case 77: result = ValidateHashDRBG(); break;
|
||||
case 78: result = ValidateHmacDRBG(); break;
|
||||
case 0: result = Test::ValidateAll(thorough); break;
|
||||
case 1: result = Test::TestSettings(); break;
|
||||
case 2: result = Test::TestOS_RNG(); break;
|
||||
// case 3: result = Test::TestSecRandom(); break;
|
||||
case 4: result = Test::ValidateMD5(); break;
|
||||
case 5: result = Test::ValidateSHA(); break;
|
||||
case 6: result = Test::ValidateDES(); break;
|
||||
case 7: result = Test::ValidateIDEA(); break;
|
||||
case 8: result = Test::ValidateARC4(); break;
|
||||
case 9: result = Test::ValidateRC5(); break;
|
||||
case 10: result = Test::ValidateBlowfish(); break;
|
||||
// case 11: result = Test::ValidateDiamond2(); break;
|
||||
case 12: result = Test::ValidateThreeWay(); break;
|
||||
case 13: result = Test::ValidateBBS(); break;
|
||||
case 14: result = Test::ValidateDH(); break;
|
||||
case 15: result = Test::ValidateRSA(); break;
|
||||
case 16: result = Test::ValidateElGamal(); break;
|
||||
case 17: result = Test::ValidateDSA(thorough); break;
|
||||
// case 18: result = Test::ValidateHAVAL(); break;
|
||||
case 19: result = Test::ValidateSAFER(); break;
|
||||
case 20: result = Test::ValidateLUC(); break;
|
||||
case 21: result = Test::ValidateRabin(); break;
|
||||
// case 22: result = Test::ValidateBlumGoldwasser(); break;
|
||||
case 23: result = Test::ValidateECP(); break;
|
||||
case 24: result = Test::ValidateEC2N(); break;
|
||||
// case 25: result = Test::ValidateMD5MAC(); break;
|
||||
case 26: result = Test::ValidateGOST(); break;
|
||||
case 27: result = Test::ValidateTiger(); break;
|
||||
case 28: result = Test::ValidateRIPEMD(); break;
|
||||
case 29: result = Test::ValidateHMAC(); break;
|
||||
// case 30: result = Test::ValidateXMACC(); break;
|
||||
case 31: result = Test::ValidateSHARK(); break;
|
||||
case 32: result = Test::ValidateLUC_DH(); break;
|
||||
case 33: result = Test::ValidateLUC_DL(); break;
|
||||
case 34: result = Test::ValidateSEAL(); break;
|
||||
case 35: result = Test::ValidateCAST(); break;
|
||||
case 36: result = Test::ValidateSquare(); break;
|
||||
case 37: result = Test::ValidateRC2(); break;
|
||||
case 38: result = Test::ValidateRC6(); break;
|
||||
case 39: result = Test::ValidateMARS(); break;
|
||||
case 40: result = Test::ValidateRW(); break;
|
||||
case 41: result = Test::ValidateMD2(); break;
|
||||
case 42: result = Test::ValidateNR(); break;
|
||||
case 43: result = Test::ValidateMQV(); break;
|
||||
case 44: result = Test::ValidateRijndael(); break;
|
||||
case 45: result = Test::ValidateTwofish(); break;
|
||||
case 46: result = Test::ValidateSerpent(); break;
|
||||
case 47: result = Test::ValidateCipherModes(); break;
|
||||
case 48: result = Test::ValidateCRC32(); break;
|
||||
case 49: result = Test::ValidateCRC32C(); break;
|
||||
case 50: result = Test::ValidateECDSA(); break;
|
||||
case 51: result = Test::ValidateECGDSA(); break;
|
||||
case 52: result = Test::ValidateXTR_DH(); break;
|
||||
case 53: result = Test::ValidateSKIPJACK(); break;
|
||||
case 54: result = Test::ValidateSHA2(); break;
|
||||
case 55: result = Test::ValidatePanama(); break;
|
||||
case 56: result = Test::ValidateAdler32(); break;
|
||||
case 57: result = Test::ValidateMD4(); break;
|
||||
case 58: result = Test::ValidatePBKDF(); break;
|
||||
case 59: result = Test::ValidateESIGN(); break;
|
||||
case 60: result = Test::ValidateDLIES(); break;
|
||||
case 61: result = Test::ValidateBaseCode(); break;
|
||||
case 62: result = Test::ValidateSHACAL2(); break;
|
||||
case 63: result = Test::ValidateCamellia(); break;
|
||||
case 64: result = Test::ValidateWhirlpool(); break;
|
||||
case 65: result = Test::ValidateTTMAC(); break;
|
||||
case 66: result = Test::ValidateSalsa(); break;
|
||||
case 67: result = Test::ValidateSosemanuk(); break;
|
||||
case 68: result = Test::ValidateVMAC(); break;
|
||||
case 69: result = Test::ValidateCCM(); break;
|
||||
case 70: result = Test::ValidateGCM(); break;
|
||||
case 71: result = Test::ValidateCMAC(); break;
|
||||
case 72: result = Test::ValidateHKDF(); break;
|
||||
case 73: result = Test::ValidateBLAKE2s(); break;
|
||||
case 74: result = Test::ValidateBLAKE2b(); break;
|
||||
case 75: result = Test::ValidatePoly1305(); break;
|
||||
case 76: result = Test::ValidateSipHash(); break;
|
||||
case 77: result = Test::ValidateHashDRBG(); break;
|
||||
case 78: result = Test::ValidateHmacDRBG(); break;
|
||||
|
||||
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
|
||||
// http://github.com/weidai11/cryptopp/issues/92
|
||||
case 9999: result = TestSecBlock(); break;
|
||||
case 9999: result = Test::TestSecBlock(); break;
|
||||
// http://github.com/weidai11/cryptopp/issues/64
|
||||
case 9998: result = TestPolynomialMod2(); break;
|
||||
case 9998: result = Test::TestPolynomialMod2(); break;
|
||||
// http://github.com/weidai11/cryptopp/issues/336
|
||||
case 9997: result = TestIntegerBitops(); break;
|
||||
case 9997: result = Test::TestIntegerBitops(); break;
|
||||
// http://github.com/weidai11/cryptopp/issues/360
|
||||
case 9996: result = TestRounding(); break;
|
||||
case 9996: result = Test::TestRounding(); break;
|
||||
// http://github.com/weidai11/cryptopp/issues/242
|
||||
case 9995: result = TestHuffmanCodes(); break;
|
||||
case 9995: result = Test::TestHuffmanCodes(); break;
|
||||
// http://github.com/weidai11/cryptopp/issues/346
|
||||
case 9994: result = TestASN1Parse(); break;
|
||||
case 9994: result = Test::TestASN1Parse(); break;
|
||||
#endif
|
||||
|
||||
default: return false;
|
||||
@ -1007,13 +1013,13 @@ bool Validate(int alg, bool thorough, const char *seedInput)
|
||||
err = asctime_s(timeBuf, sizeof(timeBuf), &localTime);
|
||||
CRYPTOPP_ASSERT(err == 0);
|
||||
|
||||
cout << "\nTest ended at " << timeBuf;
|
||||
std::cout << "\nTest ended at " << timeBuf;
|
||||
#else
|
||||
const time_t endTime = time(NULL);
|
||||
cout << "\nTest ended at " << asctime(localtime(&endTime));
|
||||
std::cout << "\nTest ended at " << asctime(localtime(&endTime));
|
||||
#endif
|
||||
|
||||
cout << "Seed used was: " << seed << endl;
|
||||
std::cout << "Seed used was: " << seed << std::endl;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
14
validat0.cpp
14
validat0.cpp
@ -21,11 +21,8 @@
|
||||
# pragma strict_gs_check (on)
|
||||
#endif
|
||||
|
||||
#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
|
||||
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
USING_NAMESPACE(CryptoPP)
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
NAMESPACE_BEGIN(Test)
|
||||
|
||||
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
|
||||
bool TestRounding()
|
||||
@ -735,11 +732,11 @@ bool TestSecBlock()
|
||||
|
||||
{
|
||||
std::basic_string<char, std::char_traits<char>, AllocatorWithCleanup<char, false> > s1;
|
||||
std::basic_string<char, std::char_traits<char>, AllocatorWithCleanup<char, true> > s2;
|
||||
std::basic_string<char, std::char_traits<char>, AllocatorWithCleanup<char, true> > s2;
|
||||
s1.resize(1024); s2.resize(1024);
|
||||
|
||||
std::vector<byte, AllocatorWithCleanup<byte, false> > v1;
|
||||
std::vector<byte, AllocatorWithCleanup<byte, true> > v2;
|
||||
std::vector<byte, AllocatorWithCleanup<byte, true> > v2;
|
||||
v1.resize(1024); v2.resize(1024);
|
||||
}
|
||||
|
||||
@ -2366,3 +2363,6 @@ bool TestIntegerBitops()
|
||||
return opa && opo && opx;
|
||||
}
|
||||
#endif
|
||||
|
||||
NAMESPACE_END // Test
|
||||
NAMESPACE_END // CryptoPP
|
||||
|
498
validat1.cpp
498
validat1.cpp
File diff suppressed because it is too large
Load Diff
226
validat2.cpp
226
validat2.cpp
@ -1,4 +1,5 @@
|
||||
// validat2.cpp - originally written and placed in the public domain by Wei Dai
|
||||
// CryptoPP::Test namespace added by JW in February 2017
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
@ -50,12 +51,8 @@
|
||||
# pragma strict_gs_check (on)
|
||||
#endif
|
||||
|
||||
#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
|
||||
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
USING_NAMESPACE(CryptoPP)
|
||||
USING_NAMESPACE(std)
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
NAMESPACE_BEGIN(Test)
|
||||
|
||||
class FixedRNG : public RandomNumberGenerator
|
||||
{
|
||||
@ -73,7 +70,7 @@ private:
|
||||
|
||||
bool ValidateBBS()
|
||||
{
|
||||
cout << "\nBlumBlumShub validation suite running...\n\n";
|
||||
std::cout << "\nBlumBlumShub validation suite running...\n\n";
|
||||
|
||||
Integer p("212004934506826557583707108431463840565872545889679278744389317666981496005411448865750399674653351");
|
||||
Integer q("100677295735404212434355574418077394581488455772477016953458064183204108039226017738610663984508231");
|
||||
@ -90,37 +87,37 @@ bool ValidateBBS()
|
||||
0xD5,0x0E,0x8E,0x29,0x83,0x75,0x6B,0x27,0x46,0xA1};
|
||||
|
||||
// Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
|
||||
StreamState ss(cout);
|
||||
StreamState ss(std::cout);
|
||||
byte buf[20];
|
||||
|
||||
bbs.GenerateBlock(buf, 20);
|
||||
fail = memcmp(output1, buf, 20) != 0;
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
for (j=0;j<20;j++)
|
||||
cout << setw(2) << setfill('0') << hex << (int)buf[j];
|
||||
cout << endl;
|
||||
std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)buf[j];
|
||||
std::cout << std::endl;
|
||||
|
||||
bbs.Seek(10);
|
||||
bbs.GenerateBlock(buf, 10);
|
||||
fail = memcmp(output1+10, buf, 10) != 0;
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
for (j=0;j<10;j++)
|
||||
cout << setw(2) << setfill('0') << hex << (int)buf[j];
|
||||
cout << endl;
|
||||
std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)buf[j];
|
||||
std::cout << std::endl;
|
||||
|
||||
bbs.Seek(1234567);
|
||||
bbs.GenerateBlock(buf, 20);
|
||||
fail = memcmp(output2, buf, 20) != 0;
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
for (j=0;j<20;j++)
|
||||
cout << setw(2) << setfill('0') << hex << (int)buf[j];
|
||||
cout << endl;
|
||||
std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)buf[j];
|
||||
std::cout << std::endl;
|
||||
|
||||
return pass;
|
||||
}
|
||||
@ -132,8 +129,8 @@ bool SignatureValidate(PK_Signer &priv, PK_Verifier &pub, bool thorough = false)
|
||||
fail = !pub.GetMaterial().Validate(GlobalRNG(), thorough ? 3 : 2) || !priv.GetMaterial().Validate(GlobalRNG(), thorough ? 3 : 2);
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "signature key validation\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "signature key validation\n";
|
||||
|
||||
const byte *message = (byte *)"test message";
|
||||
const int messageLen = 12;
|
||||
@ -143,15 +140,15 @@ bool SignatureValidate(PK_Signer &priv, PK_Verifier &pub, bool thorough = false)
|
||||
fail = !pub.VerifyMessage(message, messageLen, signature, signatureLength);
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "signature and verification\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "signature and verification\n";
|
||||
|
||||
++signature[0];
|
||||
fail = pub.VerifyMessage(message, messageLen, signature, signatureLength);
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "checking invalid signature" << endl;
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "checking invalid signature" << std::endl;
|
||||
|
||||
if (priv.MaxRecoverableLength() > 0)
|
||||
{
|
||||
@ -161,16 +158,16 @@ bool SignatureValidate(PK_Signer &priv, PK_Verifier &pub, bool thorough = false)
|
||||
fail = !(result.isValidCoding && result.messageLength == messageLen && memcmp(recovered, message, messageLen) == 0);
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "signature and verification with recovery" << endl;
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "signature and verification with recovery" << std::endl;
|
||||
|
||||
++signature[0];
|
||||
result = pub.RecoverMessage(recovered, NULL, 0, signature, signatureLength);
|
||||
fail = result.isValidCoding;
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "recovery with invalid signature" << endl;
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "recovery with invalid signature" << std::endl;
|
||||
}
|
||||
|
||||
return pass;
|
||||
@ -183,8 +180,8 @@ bool CryptoSystemValidate(PK_Decryptor &priv, PK_Encryptor &pub, bool thorough =
|
||||
fail = !pub.GetMaterial().Validate(GlobalRNG(), thorough ? 3 : 2) || !priv.GetMaterial().Validate(GlobalRNG(), thorough ? 3 : 2);
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "cryptosystem key validation\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "cryptosystem key validation\n";
|
||||
|
||||
const byte *message = (byte *)"test message";
|
||||
const int messageLen = 12;
|
||||
@ -196,8 +193,8 @@ bool CryptoSystemValidate(PK_Decryptor &priv, PK_Encryptor &pub, bool thorough =
|
||||
fail = fail || memcmp(message, plaintext, messageLen);
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "encryption and decryption\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "encryption and decryption\n";
|
||||
|
||||
return pass;
|
||||
}
|
||||
@ -205,10 +202,10 @@ bool CryptoSystemValidate(PK_Decryptor &priv, PK_Encryptor &pub, bool thorough =
|
||||
bool SimpleKeyAgreementValidate(SimpleKeyAgreementDomain &d)
|
||||
{
|
||||
if (d.GetCryptoParameters().Validate(GlobalRNG(), 3))
|
||||
cout << "passed simple key agreement domain parameters validation" << endl;
|
||||
std::cout << "passed simple key agreement domain parameters validation" << std::endl;
|
||||
else
|
||||
{
|
||||
cout << "FAILED simple key agreement domain parameters invalid" << endl;
|
||||
std::cout << "FAILED simple key agreement domain parameters invalid" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -224,27 +221,27 @@ bool SimpleKeyAgreementValidate(SimpleKeyAgreementDomain &d)
|
||||
|
||||
if (!(d.Agree(val1, priv1, pub2) && d.Agree(val2, priv2, pub1)))
|
||||
{
|
||||
cout << "FAILED simple key agreement failed" << endl;
|
||||
std::cout << "FAILED simple key agreement failed" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (memcmp(val1.begin(), val2.begin(), d.AgreedValueLength()))
|
||||
{
|
||||
cout << "FAILED simple agreed values not equal" << endl;
|
||||
std::cout << "FAILED simple agreed values not equal" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
cout << "passed simple key agreement" << endl;
|
||||
std::cout << "passed simple key agreement" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AuthenticatedKeyAgreementValidate(AuthenticatedKeyAgreementDomain &d)
|
||||
{
|
||||
if (d.GetCryptoParameters().Validate(GlobalRNG(), 3))
|
||||
cout << "passed authenticated key agreement domain parameters validation" << endl;
|
||||
std::cout << "passed authenticated key agreement domain parameters validation" << std::endl;
|
||||
else
|
||||
{
|
||||
cout << "FAILED authenticated key agreement domain parameters invalid" << endl;
|
||||
std::cout << "FAILED authenticated key agreement domain parameters invalid" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -264,23 +261,23 @@ bool AuthenticatedKeyAgreementValidate(AuthenticatedKeyAgreementDomain &d)
|
||||
|
||||
if (!(d.Agree(val1, spriv1, epriv1, spub2, epub2) && d.Agree(val2, spriv2, epriv2, spub1, epub1)))
|
||||
{
|
||||
cout << "FAILED authenticated key agreement failed" << endl;
|
||||
std::cout << "FAILED authenticated key agreement failed" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (memcmp(val1.begin(), val2.begin(), d.AgreedValueLength()))
|
||||
{
|
||||
cout << "FAILED authenticated agreed values not equal" << endl;
|
||||
std::cout << "FAILED authenticated agreed values not equal" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
cout << "passed authenticated key agreement" << endl;
|
||||
std::cout << "passed authenticated key agreement" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ValidateRSA()
|
||||
{
|
||||
cout << "\nRSA validation suite running...\n\n";
|
||||
std::cout << "\nRSA validation suite running...\n\n";
|
||||
|
||||
byte out[100], outPlain[100];
|
||||
bool pass = true, fail;
|
||||
@ -301,21 +298,21 @@ bool ValidateRSA()
|
||||
fail = memcmp(signature, out, 64) != 0;
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "signature check against test vector\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "signature check against test vector\n";
|
||||
|
||||
fail = !rsaPub.VerifyMessage((byte *)plain, strlen(plain), out, signatureLength);
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "verification check against test vector\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "verification check against test vector\n";
|
||||
|
||||
out[10]++;
|
||||
fail = rsaPub.VerifyMessage((byte *)plain, strlen(plain), out, signatureLength);
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "invalid signature verification\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "invalid signature verification\n";
|
||||
}
|
||||
{
|
||||
FileSource keys(CRYPTOPP_DATA_DIR "TestData/rsa1024.dat", true, new HexDecoder);
|
||||
@ -358,8 +355,8 @@ bool ValidateRSA()
|
||||
fail = !result.isValidCoding || (result.messageLength!=8) || memcmp(out, encrypted, 50) || memcmp(plain, outPlain, 8);
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "PKCS 2.0 encryption and decryption\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "PKCS 2.0 encryption and decryption\n";
|
||||
}
|
||||
|
||||
return pass;
|
||||
@ -367,7 +364,7 @@ bool ValidateRSA()
|
||||
|
||||
bool ValidateDH()
|
||||
{
|
||||
cout << "\nDH validation suite running...\n\n";
|
||||
std::cout << "\nDH validation suite running...\n\n";
|
||||
|
||||
FileSource f(CRYPTOPP_DATA_DIR "TestData/dh1024.dat", true, new HexDecoder());
|
||||
DH dh(f);
|
||||
@ -376,7 +373,7 @@ bool ValidateDH()
|
||||
|
||||
bool ValidateMQV()
|
||||
{
|
||||
cout << "\nMQV validation suite running...\n\n";
|
||||
std::cout << "\nMQV validation suite running...\n\n";
|
||||
|
||||
FileSource f(CRYPTOPP_DATA_DIR "TestData/mqv1024.dat", true, new HexDecoder());
|
||||
MQV mqv(f);
|
||||
@ -444,7 +441,7 @@ bool ValidateHMQV()
|
||||
std::cout << "passed authenticated key agreement" << std::endl;
|
||||
|
||||
// Now test HMQV with NIST P-384 curve and SHA384 hash
|
||||
std::cout << endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "HMQV with NIST P-384 and SHA-384:" << std::endl;
|
||||
|
||||
ECHMQV384 hmqvB384(false);
|
||||
@ -561,7 +558,7 @@ bool ValidateFHMQV()
|
||||
std::cout << "passed authenticated key agreement" << std::endl;
|
||||
|
||||
// Now test FHMQV with NIST P-384 curve and SHA384 hash
|
||||
std::cout << endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "FHMQV with NIST P-384 and SHA-384:" << std::endl;
|
||||
|
||||
ECHMQV384 fhmqvB384(false);
|
||||
@ -619,7 +616,7 @@ bool ValidateFHMQV()
|
||||
|
||||
bool ValidateLUC_DH()
|
||||
{
|
||||
cout << "\nLUC-DH validation suite running...\n\n";
|
||||
std::cout << "\nLUC-DH validation suite running...\n\n";
|
||||
|
||||
FileSource f(CRYPTOPP_DATA_DIR "TestData/lucd512.dat", true, new HexDecoder());
|
||||
LUC_DH dh(f);
|
||||
@ -628,7 +625,7 @@ bool ValidateLUC_DH()
|
||||
|
||||
bool ValidateXTR_DH()
|
||||
{
|
||||
cout << "\nXTR-DH validation suite running...\n\n";
|
||||
std::cout << "\nXTR-DH validation suite running...\n\n";
|
||||
|
||||
FileSource f(CRYPTOPP_DATA_DIR "TestData/xtrdh171.dat", true, new HexDecoder());
|
||||
XTR_DH dh(f);
|
||||
@ -637,7 +634,7 @@ bool ValidateXTR_DH()
|
||||
|
||||
bool ValidateElGamal()
|
||||
{
|
||||
cout << "\nElGamal validation suite running...\n\n";
|
||||
std::cout << "\nElGamal validation suite running...\n\n";
|
||||
bool pass = true;
|
||||
{
|
||||
FileSource fc(CRYPTOPP_DATA_DIR "TestData/elgc1024.dat", true, new HexDecoder);
|
||||
@ -655,7 +652,7 @@ bool ValidateElGamal()
|
||||
|
||||
bool ValidateDLIES()
|
||||
{
|
||||
cout << "\nDLIES validation suite running...\n\n";
|
||||
std::cout << "\nDLIES validation suite running...\n\n";
|
||||
bool pass = true;
|
||||
{
|
||||
FileSource fc(CRYPTOPP_DATA_DIR "TestData/dlie1024.dat", true, new HexDecoder);
|
||||
@ -664,7 +661,7 @@ bool ValidateDLIES()
|
||||
pass = CryptoSystemValidate(privC, pubC) && pass;
|
||||
}
|
||||
{
|
||||
cout << "Generating new encryption key..." << endl;
|
||||
std::cout << "Generating new encryption key..." << std::endl;
|
||||
DLIES<>::GroupParameters gp;
|
||||
gp.GenerateRandomWithKeySize(GlobalRNG(), 128);
|
||||
DLIES<>::Decryptor decryptor;
|
||||
@ -678,7 +675,7 @@ bool ValidateDLIES()
|
||||
|
||||
bool ValidateNR()
|
||||
{
|
||||
cout << "\nNR validation suite running...\n\n";
|
||||
std::cout << "\nNR validation suite running...\n\n";
|
||||
bool pass = true;
|
||||
{
|
||||
FileSource f(CRYPTOPP_DATA_DIR "TestData/nr2048.dat", true, new HexDecoder);
|
||||
@ -689,7 +686,7 @@ bool ValidateNR()
|
||||
pass = SignatureValidate(privS, pubS) && pass;
|
||||
}
|
||||
{
|
||||
cout << "Generating new signature key..." << endl;
|
||||
std::cout << "Generating new signature key..." << std::endl;
|
||||
NR<SHA>::Signer privS(GlobalRNG(), 256);
|
||||
NR<SHA>::Verifier pubS(privS);
|
||||
|
||||
@ -700,7 +697,7 @@ bool ValidateNR()
|
||||
|
||||
bool ValidateDSA(bool thorough)
|
||||
{
|
||||
cout << "\nDSA validation suite running...\n\n";
|
||||
std::cout << "\nDSA validation suite running...\n\n";
|
||||
|
||||
bool pass = true;
|
||||
FileSource fs1(CRYPTOPP_DATA_DIR "TestData/dsa1024.dat", true, new HexDecoder());
|
||||
@ -717,7 +714,7 @@ bool ValidateDSA(bool thorough)
|
||||
|
||||
bool ValidateLUC()
|
||||
{
|
||||
cout << "\nLUC validation suite running...\n\n";
|
||||
std::cout << "\nLUC validation suite running...\n\n";
|
||||
bool pass=true;
|
||||
|
||||
{
|
||||
@ -736,14 +733,14 @@ bool ValidateLUC()
|
||||
|
||||
bool ValidateLUC_DL()
|
||||
{
|
||||
cout << "\nLUC-HMP validation suite running...\n\n";
|
||||
std::cout << "\nLUC-HMP validation suite running...\n\n";
|
||||
|
||||
FileSource f(CRYPTOPP_DATA_DIR "TestData/lucs512.dat", true, new HexDecoder);
|
||||
LUC_HMP<SHA>::Signer privS(f);
|
||||
LUC_HMP<SHA>::Verifier pubS(privS);
|
||||
bool pass = SignatureValidate(privS, pubS);
|
||||
|
||||
cout << "\nLUC-IES validation suite running...\n\n";
|
||||
std::cout << "\nLUC-IES validation suite running...\n\n";
|
||||
|
||||
FileSource fc(CRYPTOPP_DATA_DIR "TestData/lucc512.dat", true, new HexDecoder);
|
||||
LUC_IES<>::Decryptor privC(fc);
|
||||
@ -755,7 +752,7 @@ bool ValidateLUC_DL()
|
||||
|
||||
bool ValidateRabin()
|
||||
{
|
||||
cout << "\nRabin validation suite running...\n\n";
|
||||
std::cout << "\nRabin validation suite running...\n\n";
|
||||
bool pass=true;
|
||||
|
||||
{
|
||||
@ -774,7 +771,7 @@ bool ValidateRabin()
|
||||
|
||||
bool ValidateRW()
|
||||
{
|
||||
cout << "\nRW validation suite running...\n\n";
|
||||
std::cout << "\nRW validation suite running...\n\n";
|
||||
|
||||
FileSource f(CRYPTOPP_DATA_DIR "TestData/rw1024.dat", true, new HexDecoder);
|
||||
RWSS<PSSR, SHA>::Signer priv(f);
|
||||
@ -786,7 +783,7 @@ bool ValidateRW()
|
||||
/*
|
||||
bool ValidateBlumGoldwasser()
|
||||
{
|
||||
cout << "\nBlumGoldwasser validation suite running...\n\n";
|
||||
std::cout << "\nBlumGoldwasser validation suite running...\n\n";
|
||||
|
||||
FileSource f(CRYPTOPP_DATA_DIR "TestData/blum512.dat", true, new HexDecoder);
|
||||
BlumGoldwasserPrivateKey priv(f);
|
||||
@ -802,7 +799,7 @@ bool TestPolynomialMod2()
|
||||
{
|
||||
bool pass1 = true, pass2 = true, pass3 = true;
|
||||
|
||||
cout << "\nTesting PolynomialMod2 bit operations...\n\n";
|
||||
std::cout << "\nTesting PolynomialMod2 bit operations...\n\n";
|
||||
|
||||
static const unsigned int start = 0;
|
||||
static const unsigned int stop = 4 * WORD_BITS + 1;
|
||||
@ -890,21 +887,21 @@ bool TestPolynomialMod2()
|
||||
|
||||
if (str1 != str2)
|
||||
{
|
||||
cout << " Oops..." << "\n";
|
||||
cout << " random: " << std::hex << n << std::dec << "\n";
|
||||
cout << " str1: " << str1 << "\n";
|
||||
cout << " str2: " << str2 << "\n";
|
||||
std::cout << " Oops..." << "\n";
|
||||
std::cout << " random: " << std::hex << n << std::dec << "\n";
|
||||
std::cout << " str1: " << str1 << "\n";
|
||||
std::cout << " str2: " << str2 << "\n";
|
||||
}
|
||||
|
||||
pass3 &= (str1 == str2);
|
||||
}
|
||||
|
||||
cout << (!pass1 ? "FAILED" : "passed") << ": " << "1 shifted over range [" << dec << start << "," << stop << "]" << "\n";
|
||||
cout << (!pass2 ? "FAILED" : "passed") << ": " << "0x" << hex << word(SIZE_MAX) << dec << " shifted over range [" << start << "," << stop << "]" << "\n";
|
||||
cout << (!pass3 ? "FAILED" : "passed") << ": " << "random values shifted over range [" << dec << start << "," << stop << "]" << "\n";
|
||||
std::cout << (!pass1 ? "FAILED" : "passed") << ": " << "1 shifted over range [" << std::dec << start << "," << stop << "]" << "\n";
|
||||
std::cout << (!pass2 ? "FAILED" : "passed") << ": " << "0x" << std::hex << word(SIZE_MAX) << std::dec << " shifted over range [" << start << "," << stop << "]" << "\n";
|
||||
std::cout << (!pass3 ? "FAILED" : "passed") << ": " << "random values shifted over range [" << std::dec << start << "," << stop << "]" << "\n";
|
||||
|
||||
if (!(pass1 && pass2 && pass3))
|
||||
cout.flush();
|
||||
std::cout.flush();
|
||||
|
||||
return pass1 && pass2 && pass3;
|
||||
}
|
||||
@ -912,7 +909,7 @@ bool TestPolynomialMod2()
|
||||
|
||||
bool ValidateECP()
|
||||
{
|
||||
cout << "\nECP validation suite running...\n\n";
|
||||
std::cout << "\nECP validation suite running...\n\n";
|
||||
|
||||
ECIES<ECP>::Decryptor cpriv(GlobalRNG(), ASN1::secp192r1());
|
||||
ECIES<ECP>::Encryptor cpub(cpriv);
|
||||
@ -937,7 +934,7 @@ bool ValidateECP()
|
||||
pass = SimpleKeyAgreementValidate(ecdhc) && pass;
|
||||
pass = AuthenticatedKeyAgreementValidate(ecmqvc) && pass;
|
||||
|
||||
cout << "Turning on point compression..." << endl;
|
||||
std::cout << "Turning on point compression..." << std::endl;
|
||||
cpriv.AccessKey().AccessGroupParameters().SetPointCompression(true);
|
||||
cpub.AccessKey().AccessGroupParameters().SetPointCompression(true);
|
||||
ecdhc.AccessGroupParameters().SetPointCompression(true);
|
||||
@ -946,13 +943,13 @@ bool ValidateECP()
|
||||
pass = SimpleKeyAgreementValidate(ecdhc) && pass;
|
||||
pass = AuthenticatedKeyAgreementValidate(ecmqvc) && pass;
|
||||
|
||||
cout << "Testing SEC 2, NIST, and Brainpool recommended curves..." << endl;
|
||||
std::cout << "Testing SEC 2, NIST, and Brainpool recommended curves..." << std::endl;
|
||||
OID oid;
|
||||
while (!(oid = DL_GroupParameters_EC<ECP>::GetNextRecommendedParametersOID(oid)).m_values.empty())
|
||||
{
|
||||
DL_GroupParameters_EC<ECP> params(oid);
|
||||
bool fail = !params.Validate(GlobalRNG(), 2);
|
||||
cout << (fail ? "FAILED" : "passed") << " " << dec << params.GetCurve().GetField().MaxElementBitLength() << " bits" << endl;
|
||||
std::cout << (fail ? "FAILED" : "passed") << " " << std::dec << params.GetCurve().GetField().MaxElementBitLength() << " bits" << std::endl;
|
||||
pass = pass && !fail;
|
||||
}
|
||||
|
||||
@ -961,7 +958,7 @@ bool ValidateECP()
|
||||
|
||||
bool ValidateEC2N()
|
||||
{
|
||||
cout << "\nEC2N validation suite running...\n\n";
|
||||
std::cout << "\nEC2N validation suite running...\n\n";
|
||||
|
||||
ECIES<EC2N>::Decryptor cpriv(GlobalRNG(), ASN1::sect193r1());
|
||||
ECIES<EC2N>::Encryptor cpub(cpriv);
|
||||
@ -984,7 +981,7 @@ bool ValidateEC2N()
|
||||
pass = SimpleKeyAgreementValidate(ecdhc) && pass;
|
||||
pass = AuthenticatedKeyAgreementValidate(ecmqvc) && pass;
|
||||
|
||||
cout << "Turning on point compression..." << endl;
|
||||
std::cout << "Turning on point compression..." << std::endl;
|
||||
cpriv.AccessKey().AccessGroupParameters().SetPointCompression(true);
|
||||
cpub.AccessKey().AccessGroupParameters().SetPointCompression(true);
|
||||
ecdhc.AccessGroupParameters().SetPointCompression(true);
|
||||
@ -994,13 +991,13 @@ bool ValidateEC2N()
|
||||
pass = AuthenticatedKeyAgreementValidate(ecmqvc) && pass;
|
||||
|
||||
#if 0 // TODO: turn this back on when I make EC2N faster for pentanomial basis
|
||||
cout << "Testing SEC 2 recommended curves..." << endl;
|
||||
std::cout << "Testing SEC 2 recommended curves..." << std::endl;
|
||||
OID oid;
|
||||
while (!(oid = DL_GroupParameters_EC<EC2N>::GetNextRecommendedParametersOID(oid)).m_values.empty())
|
||||
{
|
||||
DL_GroupParameters_EC<EC2N> params(oid);
|
||||
bool fail = !params.Validate(GlobalRNG(), 2);
|
||||
cout << (fail ? "FAILED" : "passed") << " " << params.GetCurve().GetField().MaxElementBitLength() << " bits" << endl;
|
||||
std::cout << (fail ? "FAILED" : "passed") << " " << params.GetCurve().GetField().MaxElementBitLength() << " bits" << std::endl;
|
||||
pass = pass && !fail;
|
||||
}
|
||||
#endif
|
||||
@ -1010,7 +1007,7 @@ bool ValidateEC2N()
|
||||
|
||||
bool ValidateECDSA()
|
||||
{
|
||||
cout << "\nECDSA validation suite running...\n\n";
|
||||
std::cout << "\nECDSA validation suite running...\n\n";
|
||||
|
||||
// from Sample Test Vectors for P1363
|
||||
GF2NT gf2n(191, 9, 0);
|
||||
@ -1041,14 +1038,14 @@ bool ValidateECDSA()
|
||||
fail = (rOut != r) || (sOut != s);
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "signature check against test vector\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "signature check against test vector\n";
|
||||
|
||||
fail = !pub.VerifyMessage((byte *)"abc", 3, sig, sizeof(sig));
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "verification check against test vector\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "verification check against test vector\n";
|
||||
|
||||
fail = pub.VerifyMessage((byte *)"xyz", 3, sig, sizeof(sig));
|
||||
pass = pass && !fail;
|
||||
@ -1061,7 +1058,7 @@ bool ValidateECDSA()
|
||||
// from http://www.teletrust.de/fileadmin/files/oid/ecgdsa_final.pdf
|
||||
bool ValidateECGDSA()
|
||||
{
|
||||
cout << "\nECGDSA validation suite running...\n\n";
|
||||
std::cout << "\nECGDSA validation suite running...\n\n";
|
||||
|
||||
bool fail, pass=true;
|
||||
|
||||
@ -1095,8 +1092,8 @@ bool ValidateECGDSA()
|
||||
fail = !verifier.VerifyMessage(msg, len, signature, sizeof(signature));
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "brainpoolP192r1 using RIPEMD-160\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "brainpoolP192r1 using RIPEMD-160\n";
|
||||
|
||||
fail = !SignatureValidate(signer, verifier);
|
||||
pass = pass && !fail;
|
||||
@ -1132,8 +1129,8 @@ bool ValidateECGDSA()
|
||||
fail = !verifier.VerifyMessage(msg, len, signature, sizeof(signature));
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "brainpoolP256r1 using RIPEMD-160\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "brainpoolP256r1 using RIPEMD-160\n";
|
||||
|
||||
fail = !SignatureValidate(signer, verifier);
|
||||
pass = pass && !fail;
|
||||
@ -1169,8 +1166,8 @@ bool ValidateECGDSA()
|
||||
fail = !verifier.VerifyMessage(msg, len, signature, sizeof(signature));
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "brainpoolP320r1 using RIPEMD-160\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "brainpoolP320r1 using RIPEMD-160\n";
|
||||
|
||||
fail = !SignatureValidate(signer, verifier);
|
||||
pass = pass && !fail;
|
||||
@ -1206,8 +1203,8 @@ bool ValidateECGDSA()
|
||||
fail = !verifier.VerifyMessage(msg, len, signature, sizeof(signature));
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "brainpoolP192r1 using SHA-1\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "brainpoolP192r1 using SHA-1\n";
|
||||
|
||||
fail = !SignatureValidate(signer, verifier);
|
||||
pass = pass && !fail;
|
||||
@ -1243,8 +1240,8 @@ bool ValidateECGDSA()
|
||||
fail = !verifier.VerifyMessage(msg, len, signature, sizeof(signature));
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "brainpoolP256r1 using SHA-224\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "brainpoolP256r1 using SHA-224\n";
|
||||
|
||||
fail = !SignatureValidate(signer, verifier);
|
||||
pass = pass && !fail;
|
||||
@ -1280,8 +1277,8 @@ bool ValidateECGDSA()
|
||||
fail = !verifier.VerifyMessage(msg, len, signature, sizeof(signature));
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "brainpoolP320r1 using SHA-224\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "brainpoolP320r1 using SHA-224\n";
|
||||
|
||||
fail = !SignatureValidate(signer, verifier);
|
||||
pass = pass && !fail;
|
||||
@ -1317,8 +1314,8 @@ bool ValidateECGDSA()
|
||||
fail = !verifier.VerifyMessage(msg, len, signature, sizeof(signature));
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "brainpoolP320r1 using SHA-256\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "brainpoolP320r1 using SHA-256\n";
|
||||
|
||||
fail = !SignatureValidate(signer, verifier);
|
||||
pass = pass && !fail;
|
||||
@ -1354,8 +1351,8 @@ bool ValidateECGDSA()
|
||||
fail = !verifier.VerifyMessage(msg, len, signature, sizeof(signature));
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "brainpoolP512r1 using SHA-384\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "brainpoolP512r1 using SHA-384\n";
|
||||
|
||||
fail = !SignatureValidate(signer, verifier);
|
||||
pass = pass && !fail;
|
||||
@ -1391,8 +1388,8 @@ bool ValidateECGDSA()
|
||||
fail = !verifier.VerifyMessage(msg, len, signature, sizeof(signature));
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "brainpoolP512r1 using SHA-512\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "brainpoolP512r1 using SHA-512\n";
|
||||
|
||||
fail = !SignatureValidate(signer, verifier);
|
||||
pass = pass && !fail;
|
||||
@ -1403,7 +1400,7 @@ bool ValidateECGDSA()
|
||||
|
||||
bool ValidateESIGN()
|
||||
{
|
||||
cout << "\nESIGN validation suite running...\n\n";
|
||||
std::cout << "\nESIGN validation suite running...\n\n";
|
||||
|
||||
bool pass = true, fail;
|
||||
|
||||
@ -1426,10 +1423,10 @@ bool ValidateESIGN()
|
||||
fail = !verifier.VerifyMessage((byte *)plain, strlen(plain), signature, verifier.SignatureLength());
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
cout << "verification check against test vector\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << "verification check against test vector\n";
|
||||
|
||||
cout << "Generating signature key from seed..." << endl;
|
||||
std::cout << "Generating signature key from seed..." << std::endl;
|
||||
signer.AccessKey().GenerateRandom(GlobalRNG(), MakeParameters("Seed", ConstByteArrayParameter((const byte *)"test", 4))("KeySize", 3*512));
|
||||
verifier = signer;
|
||||
|
||||
@ -1438,3 +1435,6 @@ bool ValidateESIGN()
|
||||
|
||||
return pass;
|
||||
}
|
||||
|
||||
NAMESPACE_END // Test
|
||||
NAMESPACE_END // CryptoPP
|
||||
|
160
validat3.cpp
160
validat3.cpp
@ -1,4 +1,5 @@
|
||||
// validat3.cpp - originally written and placed in the public domain by Wei Dai
|
||||
// CryptoPP::Test namespace added by JW in February 2017
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
@ -43,12 +44,8 @@
|
||||
# pragma strict_gs_check (on)
|
||||
#endif
|
||||
|
||||
#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
|
||||
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
USING_NAMESPACE(CryptoPP)
|
||||
USING_NAMESPACE(std)
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
NAMESPACE_BEGIN(Test)
|
||||
|
||||
struct HashTestTuple
|
||||
{
|
||||
@ -69,7 +66,7 @@ bool HashModuleTest(HashTransformation &md, const HashTestTuple *testSet, unsign
|
||||
SecByteBlock digest(md.DigestSize());
|
||||
|
||||
// Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
|
||||
StreamState ss(cout);
|
||||
StreamState ss(std::cout);
|
||||
for (unsigned int i=0; i<testSetSize; i++)
|
||||
{
|
||||
unsigned j;
|
||||
@ -80,13 +77,13 @@ bool HashModuleTest(HashTransformation &md, const HashTestTuple *testSet, unsign
|
||||
fail = !!memcmp(digest, testSet[i].output, md.DigestSize()) != 0;
|
||||
pass = pass && !fail;
|
||||
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
for (j=0; j<md.DigestSize(); j++)
|
||||
cout << setw(2) << setfill('0') << hex << (int)digest[j];
|
||||
cout << " \"" << (char *)testSet[i].input << '\"';
|
||||
std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)digest[j];
|
||||
std::cout << " \"" << (char *)testSet[i].input << '\"';
|
||||
if (testSet[i].repeatTimes != 1)
|
||||
cout << " repeated " << dec << testSet[i].repeatTimes << " times";
|
||||
cout << endl;
|
||||
std::cout << " repeated " << std::dec << testSet[i].repeatTimes << " times";
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
return pass;
|
||||
@ -108,7 +105,7 @@ bool ValidateCRC32()
|
||||
|
||||
CRC32 crc;
|
||||
|
||||
cout << "\nCRC-32 validation suite running...\n\n";
|
||||
std::cout << "\nCRC-32 validation suite running...\n\n";
|
||||
return HashModuleTest(crc, testSet, sizeof(testSet)/sizeof(testSet[0]));
|
||||
}
|
||||
|
||||
@ -128,7 +125,7 @@ bool ValidateCRC32C()
|
||||
|
||||
CRC32C crc;
|
||||
|
||||
cout << "\nCRC-32C validation suite running...\n\n";
|
||||
std::cout << "\nCRC-32C validation suite running...\n\n";
|
||||
return HashModuleTest(crc, testSet, sizeof(testSet)/sizeof(testSet[0]));
|
||||
}
|
||||
|
||||
@ -147,7 +144,7 @@ bool ValidateAdler32()
|
||||
|
||||
Adler32 md;
|
||||
|
||||
cout << "\nAdler-32 validation suite running...\n\n";
|
||||
std::cout << "\nAdler-32 validation suite running...\n\n";
|
||||
return HashModuleTest(md, testSet, sizeof(testSet)/sizeof(testSet[0]));
|
||||
}
|
||||
|
||||
@ -166,7 +163,7 @@ bool ValidateMD2()
|
||||
|
||||
Weak::MD2 md2;
|
||||
|
||||
cout << "\nMD2 validation suite running...\n\n";
|
||||
std::cout << "\nMD2 validation suite running...\n\n";
|
||||
return HashModuleTest(md2, testSet, sizeof(testSet)/sizeof(testSet[0]));
|
||||
}
|
||||
|
||||
@ -185,7 +182,7 @@ bool ValidateMD4()
|
||||
|
||||
Weak::MD4 md4;
|
||||
|
||||
cout << "\nMD4 validation suite running...\n\n";
|
||||
std::cout << "\nMD4 validation suite running...\n\n";
|
||||
return HashModuleTest(md4, testSet, sizeof(testSet)/sizeof(testSet[0]));
|
||||
}
|
||||
|
||||
@ -204,25 +201,25 @@ bool ValidateMD5()
|
||||
|
||||
Weak::MD5 md5;
|
||||
|
||||
cout << "\nMD5 validation suite running...\n\n";
|
||||
std::cout << "\nMD5 validation suite running...\n\n";
|
||||
return HashModuleTest(md5, testSet, sizeof(testSet)/sizeof(testSet[0]));
|
||||
}
|
||||
|
||||
bool ValidateSHA()
|
||||
{
|
||||
cout << "\nSHA validation suite running...\n\n";
|
||||
std::cout << "\nSHA validation suite running...\n\n";
|
||||
return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/sha.txt");
|
||||
}
|
||||
|
||||
bool ValidateSHA2()
|
||||
{
|
||||
cout << "\nSHA validation suite running...\n\n";
|
||||
std::cout << "\nSHA validation suite running...\n\n";
|
||||
return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/sha.txt");
|
||||
}
|
||||
|
||||
bool ValidateTiger()
|
||||
{
|
||||
cout << "\nTiger validation suite running...\n\n";
|
||||
std::cout << "\nTiger validation suite running...\n\n";
|
||||
|
||||
HashTestTuple testSet[] =
|
||||
{
|
||||
@ -298,19 +295,19 @@ bool ValidateRIPEMD()
|
||||
|
||||
bool pass = true;
|
||||
|
||||
cout << "\nRIPEMD-128 validation suite running...\n\n";
|
||||
std::cout << "\nRIPEMD-128 validation suite running...\n\n";
|
||||
RIPEMD128 md128;
|
||||
pass = HashModuleTest(md128, testSet128, sizeof(testSet128)/sizeof(testSet128[0])) && pass;
|
||||
|
||||
cout << "\nRIPEMD-160 validation suite running...\n\n";
|
||||
std::cout << "\nRIPEMD-160 validation suite running...\n\n";
|
||||
RIPEMD160 md160;
|
||||
pass = HashModuleTest(md160, testSet160, sizeof(testSet160)/sizeof(testSet160[0])) && pass;
|
||||
|
||||
cout << "\nRIPEMD-256 validation suite running...\n\n";
|
||||
std::cout << "\nRIPEMD-256 validation suite running...\n\n";
|
||||
RIPEMD256 md256;
|
||||
pass = HashModuleTest(md256, testSet256, sizeof(testSet256)/sizeof(testSet256[0])) && pass;
|
||||
|
||||
cout << "\nRIPEMD-320 validation suite running...\n\n";
|
||||
std::cout << "\nRIPEMD-320 validation suite running...\n\n";
|
||||
RIPEMD320 md320;
|
||||
pass = HashModuleTest(md320, testSet320, sizeof(testSet320)/sizeof(testSet320[0])) && pass;
|
||||
|
||||
@ -332,7 +329,7 @@ bool ValidateHAVAL()
|
||||
|
||||
bool pass=true;
|
||||
|
||||
cout << "\nHAVAL validation suite running...\n\n";
|
||||
std::cout << "\nHAVAL validation suite running...\n\n";
|
||||
{
|
||||
HAVAL3 md(16);
|
||||
pass = HashModuleTest(md, testSet+0, 1) && pass;
|
||||
@ -405,20 +402,20 @@ bool ValidateMD5MAC()
|
||||
{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(cout);
|
||||
StreamState ss(std::cout);
|
||||
|
||||
byte digest[MD5MAC::DIGESTSIZE];
|
||||
bool pass=true, fail;
|
||||
|
||||
cout << "\nMD5MAC validation suite running...\n";
|
||||
std::cout << "\nMD5MAC validation suite running...\n";
|
||||
|
||||
for (int k=0; k<2; k++)
|
||||
{
|
||||
MD5MAC mac(keys[k]);
|
||||
cout << "\nKEY: ";
|
||||
std::cout << "\nKEY: ";
|
||||
for (int j=0;j<MD5MAC::KEYLENGTH;j++)
|
||||
cout << setw(2) << setfill('0') << hex << (int)keys[k][j];
|
||||
cout << endl << endl;
|
||||
std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)keys[k][j];
|
||||
std::cout << std::endl << std::endl;
|
||||
for (int i=0;i<7;i++)
|
||||
{
|
||||
mac.Update((byte *)TestVals[i], strlen(TestVals[i]));
|
||||
@ -426,10 +423,10 @@ bool ValidateMD5MAC()
|
||||
fail = !!memcmp(digest, output[k][i], MD5MAC::DIGESTSIZE)
|
||||
|| !mac.VerifyDigest(output[k][i], (byte *)TestVals[i], strlen(TestVals[i]));
|
||||
pass = pass && !fail;
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
for (int j=0;j<MD5MAC::DIGESTSIZE;j++)
|
||||
cout << setw(2) << setfill('0') << hex << (int)digest[j];
|
||||
cout << " \"" << TestVals[i] << '\"' << endl;
|
||||
std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)digest[j];
|
||||
std::cout << " \"" << TestVals[i] << '\"' << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -479,20 +476,20 @@ bool ValidateXMACC()
|
||||
{0x76,0x54,0x32,0x17,0xc6,0xfe,0xe6,0x5f,0xb1,0x35,0x8a,0xf5,0x32,0x7a,0x80,0xbd,0xb8,0x72,0xee,0xae}}};
|
||||
|
||||
// Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
|
||||
StreamState ss(cout);
|
||||
StreamState ss(std::cout);
|
||||
|
||||
byte digest[XMACC_MD5::DIGESTSIZE];
|
||||
bool pass=true, fail;
|
||||
|
||||
cout << "\nXMACC/MD5 validation suite running...\n";
|
||||
std::cout << "\nXMACC/MD5 validation suite running...\n";
|
||||
|
||||
for (int k=0; k<2; k++)
|
||||
{
|
||||
XMACC_MD5 mac(keys[k], counters[k]);
|
||||
cout << "\nKEY: ";
|
||||
std::cout << "\nKEY: ";
|
||||
for (int j=0;j<XMACC_MD5::KEYLENGTH;j++)
|
||||
cout << setw(2) << setfill('0') << hex << (int)keys[k][j];
|
||||
cout << " COUNTER: 0x" << hex << counters[k] << endl << endl;
|
||||
std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)keys[k][j];
|
||||
std::cout << " COUNTER: 0x" << std::hex << counters[k] << std::endl << std::endl;
|
||||
for (int i=0;i<7;i++)
|
||||
{
|
||||
mac.Update((byte *)TestVals[i], strlen(TestVals[i]));
|
||||
@ -500,10 +497,10 @@ bool ValidateXMACC()
|
||||
fail = !!memcmp(digest, output[k][i], XMACC_MD5::DIGESTSIZE)
|
||||
|| !mac.VerifyDigest(output[k][i], (byte *)TestVals[i], strlen(TestVals[i]));
|
||||
pass = pass && !fail;
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
for (int j=0;j<XMACC_MD5::DIGESTSIZE;j++)
|
||||
cout << setw(2) << setfill('0') << hex << (int)digest[j];
|
||||
cout << " \"" << TestVals[i] << '\"' << endl;
|
||||
std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)digest[j];
|
||||
std::cout << " \"" << TestVals[i] << '\"' << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -538,12 +535,12 @@ bool ValidateTTMAC()
|
||||
{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(cout);
|
||||
StreamState ss(std::cout);
|
||||
|
||||
byte digest[TTMAC::DIGESTSIZE];
|
||||
bool pass=true, fail;
|
||||
|
||||
cout << "\nTwo-Track-MAC validation suite running...\n";
|
||||
std::cout << "\nTwo-Track-MAC validation suite running...\n";
|
||||
|
||||
TTMAC mac(key, sizeof(key));
|
||||
for (unsigned int k=0; k<sizeof(TestVals)/sizeof(TestVals[0]); k++)
|
||||
@ -553,10 +550,10 @@ bool ValidateTTMAC()
|
||||
fail = !!memcmp(digest, output[k], TTMAC::DIGESTSIZE)
|
||||
|| !mac.VerifyDigest(output[k], (byte *)TestVals[k], strlen(TestVals[k]));
|
||||
pass = pass && !fail;
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
for (int j=0;j<TTMAC::DIGESTSIZE;j++)
|
||||
cout << setw(2) << setfill('0') << hex << (int)digest[j];
|
||||
cout << " \"" << TestVals[k] << '\"' << endl;
|
||||
std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)digest[j];
|
||||
std::cout << " \"" << TestVals[k] << '\"' << std::endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -577,7 +574,7 @@ bool TestPBKDF(PasswordBasedKeyDerivationFunction &pbkdf, const PBKDF_TestTuple
|
||||
{
|
||||
const PBKDF_TestTuple &tuple = testSet[i];
|
||||
|
||||
string password, salt, derivedKey;
|
||||
std::string password, salt, derivedKey;
|
||||
StringSource(tuple.hexPassword, true, new HexDecoder(new StringSink(password)));
|
||||
StringSource(tuple.hexSalt, true, new HexDecoder(new StringSink(salt)));
|
||||
StringSource(tuple.hexDerivedKey, true, new HexDecoder(new StringSink(derivedKey)));
|
||||
@ -587,13 +584,13 @@ bool TestPBKDF(PasswordBasedKeyDerivationFunction &pbkdf, const PBKDF_TestTuple
|
||||
bool fail = !!memcmp(derived, derivedKey.data(), derived.size()) != 0;
|
||||
pass = pass && !fail;
|
||||
|
||||
HexEncoder enc(new FileSink(cout));
|
||||
cout << (fail ? "FAILED " : "passed ");
|
||||
HexEncoder enc(new FileSink(std::cout));
|
||||
std::cout << (fail ? "FAILED " : "passed ");
|
||||
enc.Put(tuple.purpose);
|
||||
cout << " " << tuple.iterations;
|
||||
cout << " " << tuple.hexPassword << " " << tuple.hexSalt << " ";
|
||||
std::cout << " " << tuple.iterations;
|
||||
std::cout << " " << tuple.hexPassword << " " << tuple.hexSalt << " ";
|
||||
enc.Put(derived, derived.size());
|
||||
cout << endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
return pass;
|
||||
@ -621,7 +618,7 @@ bool ValidatePBKDF()
|
||||
|
||||
PKCS12_PBKDF<SHA1> pbkdf;
|
||||
|
||||
cout << "\nPKCS #12 PBKDF validation suite running...\n\n";
|
||||
std::cout << "\nPKCS #12 PBKDF validation suite running...\n\n";
|
||||
pass = TestPBKDF(pbkdf, testSet, sizeof(testSet)/sizeof(testSet[0])) && pass;
|
||||
}
|
||||
|
||||
@ -635,7 +632,7 @@ bool ValidatePBKDF()
|
||||
|
||||
PKCS5_PBKDF2_HMAC<SHA1> pbkdf;
|
||||
|
||||
cout << "\nPKCS #5 PBKDF2 validation suite running...\n\n";
|
||||
std::cout << "\nPKCS #5 PBKDF2 validation suite running...\n\n";
|
||||
pass = TestPBKDF(pbkdf, testSet, sizeof(testSet)/sizeof(testSet[0])) && pass;
|
||||
}
|
||||
|
||||
@ -781,12 +778,12 @@ struct Poly1305_TestTuples
|
||||
|
||||
bool ValidatePoly1305()
|
||||
{
|
||||
cout << "\nPoly1305 validation suite running...\n\n";
|
||||
std::cout << "\nPoly1305 validation suite running...\n\n";
|
||||
bool fail, pass = true;
|
||||
|
||||
{
|
||||
fail = (Poly1305<AES>::StaticAlgorithmName() != "Poly1305(AES)");
|
||||
cout << (fail ? "FAILED " : "passed ") << "algorithm name\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ") << "algorithm name\n";
|
||||
pass = pass && !fail;
|
||||
}
|
||||
|
||||
@ -849,7 +846,7 @@ bool ValidatePoly1305()
|
||||
fail = !!memcmp(digest, tests[i].digest, tests[i].dlen) != 0;
|
||||
if (fail)
|
||||
{
|
||||
cout << "FAILED " << "Poly1305 test set " << count << endl;
|
||||
std::cout << "FAILED " << "Poly1305 test set " << count << std::endl;
|
||||
}
|
||||
|
||||
count++;
|
||||
@ -866,7 +863,7 @@ bool ValidatePoly1305()
|
||||
fail = !!memcmp(digest, tests[i].digest, tests[i].dlen) != 0;
|
||||
if (fail)
|
||||
{
|
||||
cout << "FAILED " << "Poly1305 test set " << count << endl;
|
||||
std::cout << "FAILED " << "Poly1305 test set " << count << std::endl;
|
||||
}
|
||||
|
||||
count++;
|
||||
@ -885,46 +882,46 @@ bool ValidatePoly1305()
|
||||
fail = !!memcmp(digest, tests[next].digest, tests[next].dlen) == 0;
|
||||
if (fail)
|
||||
{
|
||||
cout << "FAILED " << "Poly1305 test set " << count << endl;
|
||||
std::cout << "FAILED " << "Poly1305 test set " << count << std::endl;
|
||||
}
|
||||
|
||||
count++;
|
||||
pass = pass && !fail;
|
||||
}
|
||||
|
||||
cout << (!pass ? "FAILED " : "passed ") << count << " message authentication codes" << endl;
|
||||
std::cout << (!pass ? "FAILED " : "passed ") << count << " message authentication codes" << std::endl;
|
||||
|
||||
return pass;
|
||||
}
|
||||
|
||||
bool ValidateSipHash()
|
||||
{
|
||||
cout << "\nSipHash validation suite running...\n\n";
|
||||
std::cout << "\nSipHash validation suite running...\n\n";
|
||||
bool fail, pass = true, pass1=true, pass2=true, pass3=true, pass4=true;
|
||||
|
||||
{
|
||||
fail = (SipHash<2,4>::StaticAlgorithmName() != "SipHash-2-4");
|
||||
cout << (fail ? "FAILED " : "passed ") << "SipHash-2-4 algorithm name\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ") << "SipHash-2-4 algorithm name\n";
|
||||
pass = pass && !fail;
|
||||
|
||||
fail = (SipHash<2,4, false>::DIGESTSIZE != 8);
|
||||
cout << (fail ? "FAILED " : "passed ") << "SipHash-2-4 64-bit digest size\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ") << "SipHash-2-4 64-bit digest size\n";
|
||||
pass = pass && !fail;
|
||||
|
||||
fail = (SipHash<2,4, true>::DIGESTSIZE != 16);
|
||||
cout << (fail ? "FAILED " : "passed ") << "SipHash-2-4 128-bit digest size\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ") << "SipHash-2-4 128-bit digest size\n";
|
||||
pass = pass && !fail;
|
||||
|
||||
fail = (SipHash<4,8>::StaticAlgorithmName() != "SipHash-4-8");
|
||||
cout << (fail ? "FAILED " : "passed ") << "SipHash-4-8 algorithm name\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ") << "SipHash-4-8 algorithm name\n";
|
||||
pass = pass && !fail;
|
||||
|
||||
fail = (SipHash<4,8, false>::DIGESTSIZE != 8);
|
||||
cout << (fail ? "FAILED " : "passed ") << "SipHash-4-8 64-bit digest size\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ") << "SipHash-4-8 64-bit digest size\n";
|
||||
pass = pass && !fail;
|
||||
|
||||
fail = (SipHash<4,8, true>::DIGESTSIZE != 16);
|
||||
cout << (fail ? "FAILED " : "passed ") << "SipHash-4-8 128-bit digest size\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ") << "SipHash-4-8 128-bit digest size\n";
|
||||
pass = pass && !fail;
|
||||
}
|
||||
|
||||
@ -959,7 +956,7 @@ bool ValidateSipHash()
|
||||
fail = !!memcmp("\xB0\xE4\xA9\x0B\xDF\x82\x00\x9E", digest, COUNTOF(digest));
|
||||
pass1 = !fail && pass1;
|
||||
|
||||
cout << (pass1 ? "passed " : "FAILED ") << "SipHash-2-4 64-bit MAC\n";
|
||||
std::cout << (pass1 ? "passed " : "FAILED ") << "SipHash-2-4 64-bit MAC\n";
|
||||
pass = pass1 && pass;
|
||||
}
|
||||
|
||||
@ -994,7 +991,7 @@ bool ValidateSipHash()
|
||||
fail = !!memcmp("\x26\x44\x99\x06\x0A\xD9\xBA\xAB\xC4\x7F\x8B\x02\xBB\x6D\x71\xED", digest, COUNTOF(digest));
|
||||
pass3 = !fail && pass3;
|
||||
|
||||
cout << (pass3 ? "passed " : "FAILED ") << "SipHash-2-4 128-bit MAC\n";
|
||||
std::cout << (pass3 ? "passed " : "FAILED ") << "SipHash-2-4 128-bit MAC\n";
|
||||
pass = pass3 && pass;
|
||||
}
|
||||
|
||||
@ -1029,7 +1026,7 @@ bool ValidateSipHash()
|
||||
fail = !!memcmp("\x36\x31\x9A\xF3\x5E\xE1\x12\x53", digest, COUNTOF(digest));
|
||||
pass2 = !fail && pass2;
|
||||
|
||||
cout << (pass2 ? "passed " : "FAILED ") << "SipHash-4-8 64-bit MAC\n";
|
||||
std::cout << (pass2 ? "passed " : "FAILED ") << "SipHash-4-8 64-bit MAC\n";
|
||||
pass = pass2 && pass;
|
||||
}
|
||||
|
||||
@ -1064,7 +1061,7 @@ bool ValidateSipHash()
|
||||
fail = !!memcmp("\x9E\x73\x14\xB7\x54\x5C\xEC\xA3\x8B\x9A\x55\x49\xE4\xFB\x0B\xE8", digest, COUNTOF(digest));
|
||||
pass4 = !fail && pass4;
|
||||
|
||||
cout << (pass4 ? "passed " : "FAILED ") << "SipHash-4-8 128-bit MAC\n";
|
||||
std::cout << (pass4 ? "passed " : "FAILED ") << "SipHash-4-8 128-bit MAC\n";
|
||||
pass = pass4 && pass;
|
||||
}
|
||||
|
||||
@ -1079,12 +1076,12 @@ struct BLAKE2_TestTuples
|
||||
|
||||
bool ValidateBLAKE2s()
|
||||
{
|
||||
cout << "\nBLAKE2s validation suite running...\n\n";
|
||||
std::cout << "\nBLAKE2s validation suite running...\n\n";
|
||||
bool fail, pass = true;
|
||||
|
||||
{
|
||||
fail = strcmp(BLAKE2s::StaticAlgorithmName(), "BLAKE2s") != 0;
|
||||
cout << (fail ? "FAILED " : "passed ") << "algorithm name\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ") << "algorithm name\n";
|
||||
pass = pass && !fail;
|
||||
}
|
||||
|
||||
@ -1461,25 +1458,25 @@ bool ValidateBLAKE2s()
|
||||
fail = !!memcmp(digest, tests[i].digest, sizeof(digest)) != 0;
|
||||
if (fail)
|
||||
{
|
||||
cout << "FAILED " << "BLAKE2s test set " << i << endl;
|
||||
std::cout << "FAILED " << "BLAKE2s test set " << i << std::endl;
|
||||
}
|
||||
|
||||
pass = pass && !fail;
|
||||
}
|
||||
|
||||
cout << (!pass ? "FAILED " : "passed ") << COUNTOF(tests) << " hashes and keyed hashes" << endl;
|
||||
std::cout << (!pass ? "FAILED " : "passed ") << COUNTOF(tests) << " hashes and keyed hashes" << std::endl;
|
||||
|
||||
return pass;
|
||||
}
|
||||
|
||||
bool ValidateBLAKE2b()
|
||||
{
|
||||
cout << "\nBLAKE2b validation suite running...\n\n";
|
||||
std::cout << "\nBLAKE2b validation suite running...\n\n";
|
||||
bool fail, pass = true;
|
||||
|
||||
{
|
||||
fail = strcmp(BLAKE2b::StaticAlgorithmName(), "BLAKE2b") != 0;
|
||||
cout << (fail ? "FAILED " : "passed ") << "algorithm name\n";
|
||||
std::cout << (fail ? "FAILED " : "passed ") << "algorithm name\n";
|
||||
pass = pass && !fail;
|
||||
}
|
||||
|
||||
@ -1856,13 +1853,16 @@ bool ValidateBLAKE2b()
|
||||
fail = !!memcmp(digest, tests[i].digest, sizeof(digest)) != 0;
|
||||
if (fail)
|
||||
{
|
||||
cout << "FAILED " << "BLAKE2b test set " << i << endl;
|
||||
std::cout << "FAILED " << "BLAKE2b test set " << i << std::endl;
|
||||
}
|
||||
|
||||
pass = pass && !fail;
|
||||
}
|
||||
|
||||
cout << (!pass ? "FAILED " : "passed ") << COUNTOF(tests) << " hashes and keyed hashes" << endl;
|
||||
std::cout << (!pass ? "FAILED " : "passed ") << COUNTOF(tests) << " hashes and keyed hashes" << std::endl;
|
||||
|
||||
return pass;
|
||||
}
|
||||
|
||||
NAMESPACE_END // Test
|
||||
NAMESPACE_END // CryptoPP
|
||||
|
@ -5,6 +5,9 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
NAMESPACE_BEGIN(Test)
|
||||
|
||||
bool ValidateAll(bool thorough);
|
||||
bool TestSettings();
|
||||
bool TestOS_RNG();
|
||||
@ -146,4 +149,7 @@ CryptoPP::RandomNumberGenerator & GlobalRNG();
|
||||
|
||||
bool RunTestDataFile(const char *filename, const CryptoPP::NameValuePairs &overrideParameters=CryptoPP::g_nullNameValuePairs, bool thorough=true);
|
||||
|
||||
NAMESPACE_END // Test
|
||||
NAMESPACE_END // CryptoPP
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user