Skip to content

Commit

Permalink
Added CRYPTOPP_DATA_DIR patch (Issue 82)
Browse files Browse the repository at this point in the history
  • Loading branch information
noloader committed Dec 26, 2015
1 parent 19f72fc commit a0b0785
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 103 deletions.
60 changes: 30 additions & 30 deletions bench2.cpp
Expand Up @@ -257,44 +257,44 @@ void BenchmarkAll2(double t, double hertz)
cout << "<THEAD><TR><TH>Operation<TH>Milliseconds/Operation" << (g_hertz ? "<TH>Megacycles/Operation" : "") << endl;

cout << "\n<TBODY style=\"background: yellow\">";
BenchMarkCrypto<RSAES<OAEP<SHA> > >("TestData/rsa1024.dat", "RSA 1024", t);
BenchMarkCrypto<LUCES<OAEP<SHA> > >("TestData/luc1024.dat", "LUC 1024", t);
BenchMarkCrypto<DLIES<> >("TestData/dlie1024.dat", "DLIES 1024", t);
BenchMarkCrypto<LUC_IES<> >("TestData/lucc512.dat", "LUCELG 512", t);
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\">";
BenchMarkCrypto<RSAES<OAEP<SHA> > >("TestData/rsa2048.dat", "RSA 2048", t);
BenchMarkCrypto<LUCES<OAEP<SHA> > >("TestData/luc2048.dat", "LUC 2048", t);
BenchMarkCrypto<DLIES<> >("TestData/dlie2048.dat", "DLIES 2048", t);
BenchMarkCrypto<LUC_IES<> >("TestData/lucc1024.dat", "LUCELG 1024", t);
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\">";
BenchMarkSignature<RSASS<PSSR, SHA> >("TestData/rsa1024.dat", "RSA 1024", t);
BenchMarkSignature<RWSS<PSSR, SHA> >("TestData/rw1024.dat", "RW 1024", t);
BenchMarkSignature<LUCSS<PSSR, SHA> >("TestData/luc1024.dat", "LUC 1024", t);
BenchMarkSignature<NR<SHA> >("TestData/nr1024.dat", "NR 1024", t);
BenchMarkSignature<DSA>("TestData/dsa1024.dat", "DSA 1024", t);
BenchMarkSignature<LUC_HMP<SHA> >("TestData/lucs512.dat", "LUC-HMP 512", t);
BenchMarkSignature<ESIGN<SHA> >("TestData/esig1023.dat", "ESIGN 1023", t);
BenchMarkSignature<ESIGN<SHA> >("TestData/esig1536.dat", "ESIGN 1536", t);
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);
BenchMarkSignature<NR<SHA> >(CRYPTOPP_DATA_DIR "TestData/nr1024.dat", "NR 1024", t);
BenchMarkSignature<DSA>(CRYPTOPP_DATA_DIR "TestData/dsa1024.dat", "DSA 1024", t);
BenchMarkSignature<LUC_HMP<SHA> >(CRYPTOPP_DATA_DIR "TestData/lucs512.dat", "LUC-HMP 512", t);
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\">";
BenchMarkSignature<RSASS<PSSR, SHA> >("TestData/rsa2048.dat", "RSA 2048", t);
BenchMarkSignature<RWSS<PSSR, SHA> >("TestData/rw2048.dat", "RW 2048", t);
BenchMarkSignature<LUCSS<PSSR, SHA> >("TestData/luc2048.dat", "LUC 2048", t);
BenchMarkSignature<NR<SHA> >("TestData/nr2048.dat", "NR 2048", t);
BenchMarkSignature<LUC_HMP<SHA> >("TestData/lucs1024.dat", "LUC-HMP 1024", t);
BenchMarkSignature<ESIGN<SHA> >("TestData/esig2046.dat", "ESIGN 2046", t);
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);
BenchMarkSignature<NR<SHA> >(CRYPTOPP_DATA_DIR "TestData/nr2048.dat", "NR 2048", t);
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\">";
BenchMarkKeyAgreement<XTR_DH>("TestData/xtrdh171.dat", "XTR-DH 171", t);
BenchMarkKeyAgreement<XTR_DH>("TestData/xtrdh342.dat", "XTR-DH 342", t);
BenchMarkKeyAgreement<DH>("TestData/dh1024.dat", "DH 1024", t);
BenchMarkKeyAgreement<DH>("TestData/dh2048.dat", "DH 2048", t);
BenchMarkKeyAgreement<LUC_DH>("TestData/lucd512.dat", "LUCDIF 512", t);
BenchMarkKeyAgreement<LUC_DH>("TestData/lucd1024.dat", "LUCDIF 1024", t);
BenchMarkKeyAgreement<MQV>("TestData/mqv1024.dat", "MQV 1024", t);
BenchMarkKeyAgreement<MQV>("TestData/mqv2048.dat", "MQV 2048", t);
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);
BenchMarkKeyAgreement<DH>(CRYPTOPP_DATA_DIR "TestData/dh2048.dat", "DH 2048", t);
BenchMarkKeyAgreement<LUC_DH>(CRYPTOPP_DATA_DIR "TestData/lucd512.dat", "LUCDIF 512", t);
BenchMarkKeyAgreement<LUC_DH>(CRYPTOPP_DATA_DIR "TestData/lucd1024.dat", "LUCDIF 1024", t);
BenchMarkKeyAgreement<MQV>(CRYPTOPP_DATA_DIR "TestData/mqv1024.dat", "MQV 1024", t);
BenchMarkKeyAgreement<MQV>(CRYPTOPP_DATA_DIR "TestData/mqv2048.dat", "MQV 2048", t);

cout << "\n<TBODY style=\"background: white\">";
{
Expand Down
9 changes: 8 additions & 1 deletion config.h
Expand Up @@ -48,10 +48,17 @@
// Library version
#define CRYPTOPP_VERSION 563

// Define this if you want to set a prefix for TestData/ and TestVectors/
// Be mindful of the trailing slash since its simple concatenation.
// g++ ... -DCRYPTOPP_DATA_DIR='"/tmp/cryptopp_test/share/"'
#ifndef CRYPTOPP_DATA_DIR
# define CRYPTOPP_DATA_DIR ""
#endif

// define this to retain (as much as possible) old deprecated function and class names
// #define CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY

// define this to retain (as much as possible) ABI and binary compatibility with Crypto++ 5.6.2.
// Define this to retain (as much as possible) ABI and binary compatibility with Crypto++ 5.6.2.
// Also see https://cryptopp.com/wiki/Config.h#Avoid_MAINTAIN_BACKWARDS_COMPATIBILITY
#if (CRYPTOPP_VERSION <= 600)
# if !defined(CRYPTOPP_NO_BACKWARDS_COMPATIBILITY_562) && !defined(CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562)
Expand Down
9 changes: 8 additions & 1 deletion config.recommend
Expand Up @@ -28,7 +28,7 @@
# error "IS_LITTLE_ENDIAN is set, but __BYTE_ORDER__ does not equal __ORDER_LITTLE_ENDIAN__"
#endif

// define this if you want to disable all OS-dependent features,
// Define this if you want to disable all OS-dependent features,
// such as sockets and OS-provided random number generators
// #define NO_OS_DEPENDENCE

Expand All @@ -48,6 +48,13 @@
// Library version
#define CRYPTOPP_VERSION 563

// Define this if you want to set a prefix for TestData/ and TestVectors/
// Be mindful of the trailing slash since its simple concatenation.
// g++ ... -DCRYPTOPP_DATA_DIR='"/tmp/cryptopp_test/share/"'
#ifndef CRYPTOPP_DATA_DIR
# define CRYPTOPP_DATA_DIR ""
#endif

// define this to retain (as much as possible) old deprecated function and class names
// #define CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY

Expand Down
68 changes: 59 additions & 9 deletions cryptest.sh
Expand Up @@ -780,7 +780,7 @@ if [ "$HAVE_CXX03" -ne "0" ]; then
"$MAKE" clean > /dev/null 2>&1
export CXXFLAGS="-DNDEBUG -O3 -std=c++03 $ADD_CXXFLAGS"
"$MAKE" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
./cryptest.exe b 3 2.4+1e9 2>&1 | tee -a "$BENCHMARK_RESULTS"
./cryptest.exe b 1 2.4+1e9 2>&1 | tee -a "$BENCHMARK_RESULTS"
fi

############################################
Expand All @@ -795,7 +795,7 @@ if [ "$HAVE_CXX11" -ne "0" ]; then
"$MAKE" clean > /dev/null 2>&1
export CXXFLAGS="-DNDEBUG -O3 -std=c++11 $ADD_CXXFLAGS"
"$MAKE" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
./cryptest.exe b 3 2.4+1e9 2>&1 | tee -a "$BENCHMARK_RESULTS"
./cryptest.exe b 1 2.4+1e9 2>&1 | tee -a "$BENCHMARK_RESULTS"
fi

# For Cygwin, we need to test both PREFER_BERKELEY_STYLE_SOCKETS
Expand Down Expand Up @@ -865,7 +865,6 @@ if [ "$HAVE_VALGRIND" -ne "0" ] && [ "$HAVE_CXX11" -ne "0" ]; then
valgrind --track-origins=yes ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
fi

############################################
############################################

if [ "$CXX" == "g++" ] && [ "$HAVE_CXX11" -ne "0" ]; then
Expand Down Expand Up @@ -895,14 +894,14 @@ if [ "$CXX" == "g++" ] && [ "$HAVE_CXX11" -ne "0" ]; then
"$MAKE" static dynamic cryptest.exe 2>&1 | tee -a "$WARN_RESULTS"
fi

############################################
############################################

# If using GCC (likely Linux), then perform a quick check with Clang.
# This check was added after testing on Ubuntu 14.04 with Clang 3.4.
if [ "$CXX" == "g++" ]; then

$(which clang++ | head -1) -x c++ -c adhoc.cpp.proto -o $TMP/adhoc > /dev/null 2>&1
CLANG_COMPILER=$(which clang++)
"$CLANG_COMPILER" -x c++ -c adhoc.cpp.proto -o $TMP/adhoc > /dev/null 2>&1
if [ "$?" -eq "0" ]; then

############################################
Expand All @@ -912,15 +911,66 @@ if [ "$CXX" == "g++" ]; then
echo "Testing: Clang" | tee -a "$TEST_RESULTS"
echo

unset CXX
unset CXXFLAGS
export CXX="clang++"

"$MAKE" clean > /dev/null 2>&1
"$MAKE" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
"$MAKE" CXX="$CLANG_COMPILER" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"

./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
fi
fi

############################################

# Test an install with CRYPTOPP_DATA_DIR

echo
echo "************************************" | tee -a "$TEST_RESULTS"
echo "Testing: Test install with data directory" | tee -a "$TEST_RESULTS"
echo

unset CXXFLAGS
"$MAKE" clean > /dev/null 2>&1
rm -rf /tmp/cryptopp_test/ > /dev/null 2>&1

export CXXFLAGS="-DNDEBUG -g2 -O2 -DCRYPTOPP_DATA_DIR='\"/tmp/cryptopp_test/share/\"' "
"$MAKE" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"

# Still need to manulally place TestData and TestVectors
mkdir -p /tmp/cryptopp_test/share/TestData /tmp/cryptopp_test/share/TestVectors
cp -r TestData /tmp/cryptopp_test/share/
cp -r TestVectors /tmp/cryptopp_test/share/

OLD_DIR=$(pwd)
make install PREFIX=/tmp/cryptopp_test/ 2>&1 | tee -a "$TEST_RESULTS"
cd /tmp/cryptopp_test/bin

echo
echo "************************************" | tee -a "$TEST_RESULTS"
echo "Testing: Test install (validation suite)" | tee -a "$TEST_RESULTS"
echo
./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"

echo
echo "************************************" | tee -a "$TEST_RESULTS"
echo "Testing: Test install (test vectors)" | tee -a "$TEST_RESULTS"
echo
./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"

echo
echo "************************************" | tee -a "$TEST_RESULTS"
echo "Testing: Test install (benchmarks)" | tee -a "$TEST_RESULTS"
echo
./cryptest.exe b 1 2.4+1e9 2>&1 | tee -a "$BENCHMARK_RESULTS"

echo
echo "************************************" | tee -a "$TEST_RESULTS"
echo "Testing: Test install (help file)" | tee -a "$TEST_RESULTS"
echo
./cryptest.exe h 2>&1 | tee -a "$BENCHMARK_RESULTS"

cd "$OLD_DIR"

############################################
############################################

Expand Down
11 changes: 9 additions & 2 deletions datatest.cpp
Expand Up @@ -721,8 +721,15 @@ void OutputNameValuePairs(const NameValuePairs &v)
}
}

void TestDataFile(const std::string &filename, const NameValuePairs &overrideParameters, unsigned int &totalTests, unsigned int &failedTests)
void TestDataFile(std::string filename, const NameValuePairs &overrideParameters, unsigned int &totalTests, unsigned int &failedTests)
{
static const std::string dataDirectory(CRYPTOPP_DATA_DIR);
if (!dataDirectory.empty())
{
if(dataDirectory != filename.substr(0, dataDirectory.length()))
filename.insert(0, dataDirectory);
}

std::ifstream file(filename.c_str());
if (!file.good())
throw Exception(Exception::OTHER_ERROR, "Can not open file " + filename + " for reading");
Expand Down Expand Up @@ -805,7 +812,7 @@ bool RunTestDataFile(const char *filename, const NameValuePairs &overrideParamet
{
s_thorough = thorough;
unsigned int totalTests = 0, failedTests = 0;
TestDataFile(filename, overrideParameters, totalTests, failedTests);
TestDataFile((filename ? filename : ""), overrideParameters, totalTests, failedTests);
cout << dec << "\nTests complete. Total tests = " << totalTests << ". Failed tests = " << failedTests << ".\n";
if (failedTests != 0)
cout << "SOME TESTS FAILED!\n";
Expand Down
3 changes: 2 additions & 1 deletion test.cpp
Expand Up @@ -279,6 +279,7 @@ int CRYPTOPP_API main(int argc, char *argv[])
DigestFile(argv[2]);
else if (command == "tv")
{
// TestDataFile() adds CRYPTOPP_DATA_DIR as required
std::string fname = (argv[2] ? argv[2] : "all");
if (fname.find(".txt") == std::string::npos)
fname = "TestVectors/" + fname + ".txt";
Expand Down Expand Up @@ -369,7 +370,7 @@ 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("TestData/usage.dat", true, new FileSink(cout));
FileSource usage(CRYPTOPP_DATA_DIR "TestData/usage.dat", true, new FileSink(cout));
return 1;
}
else if (command == "V")
Expand Down

0 comments on commit a0b0785

Please sign in to comment.