summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2018-12-07 12:25:52 -0500
committerJeffrey Walton <noloader@gmail.com>2018-12-07 12:25:52 -0500
commit1c88fd6f59564f4933fd3d897503a5492feb726c (patch)
tree6a8be7f9450da1d651330e58a0eca5caa1791ac7
parent52035583de5c9e41a29899256857a0ff18818664 (diff)
downloadcryptopp-git-1c88fd6f59564f4933fd3d897503a5492feb726c.tar.gz
Add search for test vectors and test data (GH #760)
-rw-r--r--bench3.cpp84
-rw-r--r--config.h15
-rw-r--r--datatest.cpp8
-rw-r--r--test.cpp2
-rw-r--r--validat3.cpp14
-rw-r--r--validat4.cpp78
-rw-r--r--validat5.cpp20
-rw-r--r--validat7.cpp20
-rw-r--r--validat8.cpp16
-rw-r--r--validat9.cpp32
-rw-r--r--validate.h36
11 files changed, 185 insertions, 140 deletions
diff --git a/bench3.cpp b/bench3.cpp
index c52647fa..be19ab0b 100644
--- a/bench3.cpp
+++ b/bench3.cpp
@@ -273,7 +273,7 @@ void BenchMarkAgreement(const char *name, AuthenticatedKeyAgreementDomain &d, do
template <class SCHEME>
void BenchMarkCrypto(const char *filename, const char *name, double timeTotal)
{
- FileSource f(filename, true, new HexDecoder);
+ FileSource f(DataDir(filename).c_str(), true, new HexDecoder);
typename SCHEME::Decryptor priv(f);
typename SCHEME::Encryptor pub(priv);
BenchMarkEncryption(name, pub, timeTotal);
@@ -283,7 +283,7 @@ void BenchMarkCrypto(const char *filename, const char *name, double timeTotal)
template <class SCHEME>
void BenchMarkSignature(const char *filename, const char *name, double timeTotal)
{
- FileSource f(filename, true, new HexDecoder);
+ FileSource f(DataDir(filename).c_str(), true, new HexDecoder);
typename SCHEME::Signer priv(f);
typename SCHEME::Verifier pub(priv);
BenchMarkSigning(name, priv, timeTotal);
@@ -293,7 +293,7 @@ void BenchMarkSignature(const char *filename, const char *name, double timeTotal
template <class D>
void BenchMarkKeyAgreement(const char *filename, const char *name, double timeTotal)
{
- FileSource f(filename, true, new HexDecoder);
+ FileSource f(DataDir(filename).c_str(), true, new HexDecoder);
D d(f);
BenchMarkKeyGen(name, d, timeTotal);
BenchMarkAgreement(name, d, timeTotal);
@@ -318,63 +318,63 @@ void Benchmark3(double t, double hertz)
std::cout << "\n<TBODY style=\"background: white;\">";
{
- BenchMarkCrypto<RSAES<OAEP<SHA1> > >(CRYPTOPP_DATA_DIR "TestData/rsa1024.dat", "RSA 1024", t);
- BenchMarkCrypto<LUCES<OAEP<SHA1> > >(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);
+ BenchMarkCrypto<RSAES<OAEP<SHA1> > >("TestData/rsa1024.dat", "RSA 1024", t);
+ BenchMarkCrypto<LUCES<OAEP<SHA1> > >("TestData/luc1024.dat", "LUC 1024", t);
+ BenchMarkCrypto<DLIES<> >("TestData/dlie1024.dat", "DLIES 1024", t);
+ BenchMarkCrypto<LUC_IES<> >("TestData/lucc512.dat", "LUCELG 512", t);
}
std::cout << "\n<TBODY style=\"background: yellow;\">";
{
- BenchMarkCrypto<RSAES<OAEP<SHA1> > >(CRYPTOPP_DATA_DIR "TestData/rsa2048.dat", "RSA 2048", t);
- BenchMarkCrypto<LUCES<OAEP<SHA1> > >(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);
+ BenchMarkCrypto<RSAES<OAEP<SHA1> > >("TestData/rsa2048.dat", "RSA 2048", t);
+ BenchMarkCrypto<LUCES<OAEP<SHA1> > >("TestData/luc2048.dat", "LUC 2048", t);
+ BenchMarkCrypto<DLIES<> >("TestData/dlie2048.dat", "DLIES 2048", t);
+ BenchMarkCrypto<LUC_IES<> >("TestData/lucc1024.dat", "LUCELG 1024", t);
}
std::cout << "\n<TBODY style=\"background: white;\">";
{
- BenchMarkSignature<RSASS<PSSR, SHA1> >(CRYPTOPP_DATA_DIR "TestData/rsa1024.dat", "RSA 1024", t);
- BenchMarkSignature<RWSS<PSSR, SHA1> >(CRYPTOPP_DATA_DIR "TestData/rw1024.dat", "RW 1024", t);
- BenchMarkSignature<LUCSS<PSSR, SHA1> >(CRYPTOPP_DATA_DIR "TestData/luc1024.dat", "LUC 1024", t);
- BenchMarkSignature<NR<SHA1> >(CRYPTOPP_DATA_DIR "TestData/nr1024.dat", "NR 1024", t);
- BenchMarkSignature<DSA>(CRYPTOPP_DATA_DIR "TestData/dsa1024.dat", "DSA 1024", t);
- BenchMarkSignature<LUC_HMP<SHA1> >(CRYPTOPP_DATA_DIR "TestData/lucs512.dat", "LUC-HMP 512", t);
- BenchMarkSignature<ESIGN<SHA1> >(CRYPTOPP_DATA_DIR "TestData/esig1023.dat", "ESIGN 1023", t);
- BenchMarkSignature<ESIGN<SHA1> >(CRYPTOPP_DATA_DIR "TestData/esig1536.dat", "ESIGN 1536", t);
+ BenchMarkSignature<RSASS<PSSR, SHA1> >("TestData/rsa1024.dat", "RSA 1024", t);
+ BenchMarkSignature<RWSS<PSSR, SHA1> >("TestData/rw1024.dat", "RW 1024", t);
+ BenchMarkSignature<LUCSS<PSSR, SHA1> >("TestData/luc1024.dat", "LUC 1024", t);
+ BenchMarkSignature<NR<SHA1> >("TestData/nr1024.dat", "NR 1024", t);
+ BenchMarkSignature<DSA>("TestData/dsa1024.dat", "DSA 1024", t);
+ BenchMarkSignature<LUC_HMP<SHA1> >("TestData/lucs512.dat", "LUC-HMP 512", t);
+ BenchMarkSignature<ESIGN<SHA1> >("TestData/esig1023.dat", "ESIGN 1023", t);
+ BenchMarkSignature<ESIGN<SHA1> >("TestData/esig1536.dat", "ESIGN 1536", t);
}
std::cout << "\n<TBODY style=\"background: yellow;\">";
{
- BenchMarkSignature<RSASS<PSSR, SHA1> >(CRYPTOPP_DATA_DIR "TestData/rsa2048.dat", "RSA 2048", t);
- BenchMarkSignature<RWSS<PSSR, SHA1> >(CRYPTOPP_DATA_DIR "TestData/rw2048.dat", "RW 2048", t);
- BenchMarkSignature<LUCSS<PSSR, SHA1> >(CRYPTOPP_DATA_DIR "TestData/luc2048.dat", "LUC 2048", t);
- BenchMarkSignature<NR<SHA1> >(CRYPTOPP_DATA_DIR "TestData/nr2048.dat", "NR 2048", t);
- BenchMarkSignature<LUC_HMP<SHA1> >(CRYPTOPP_DATA_DIR "TestData/lucs1024.dat", "LUC-HMP 1024", t);
- BenchMarkSignature<ESIGN<SHA1> >(CRYPTOPP_DATA_DIR "TestData/esig2046.dat", "ESIGN 2046", t);
+ BenchMarkSignature<RSASS<PSSR, SHA1> >("TestData/rsa2048.dat", "RSA 2048", t);
+ BenchMarkSignature<RWSS<PSSR, SHA1> >("TestData/rw2048.dat", "RW 2048", t);
+ BenchMarkSignature<LUCSS<PSSR, SHA1> >("TestData/luc2048.dat", "LUC 2048", t);
+ BenchMarkSignature<NR<SHA1> >("TestData/nr2048.dat", "NR 2048", t);
+ BenchMarkSignature<LUC_HMP<SHA1> >("TestData/lucs1024.dat", "LUC-HMP 1024", t);
+ BenchMarkSignature<ESIGN<SHA1> >("TestData/esig2046.dat", "ESIGN 2046", t);
}
std::cout << "\n<TBODY style=\"background: white;\">";
{
- 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);
+ 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);
#if 0
- BenchMarkKeyAgreement<ECHMQV160>(CRYPTOPP_DATA_DIR "TestData/hmqv160.dat", "HMQV P-160", t);
- BenchMarkKeyAgreement<ECHMQV256>(CRYPTOPP_DATA_DIR "TestData/hmqv256.dat", "HMQV P-256", t);
- BenchMarkKeyAgreement<ECHMQV384>(CRYPTOPP_DATA_DIR "TestData/hmqv384.dat", "HMQV P-384", t);
- BenchMarkKeyAgreement<ECHMQV512>(CRYPTOPP_DATA_DIR "TestData/hmqv512.dat", "HMQV P-512", t);
-
- BenchMarkKeyAgreement<ECFHMQV160>(CRYPTOPP_DATA_DIR "TestData/fhmqv160.dat", "FHMQV P-160", t);
- BenchMarkKeyAgreement<ECFHMQV256>(CRYPTOPP_DATA_DIR "TestData/fhmqv256.dat", "FHMQV P-256", t);
- BenchMarkKeyAgreement<ECFHMQV384>(CRYPTOPP_DATA_DIR "TestData/fhmqv384.dat", "FHMQV P-384", t);
- BenchMarkKeyAgreement<ECFHMQV512>(CRYPTOPP_DATA_DIR "TestData/fhmqv512.dat", "FHMQV P-512", t);
+ BenchMarkKeyAgreement<ECHMQV160>("TestData/hmqv160.dat", "HMQV P-160", t);
+ BenchMarkKeyAgreement<ECHMQV256>("TestData/hmqv256.dat", "HMQV P-256", t);
+ BenchMarkKeyAgreement<ECHMQV384>("TestData/hmqv384.dat", "HMQV P-384", t);
+ BenchMarkKeyAgreement<ECHMQV512>("TestData/hmqv512.dat", "HMQV P-512", t);
+
+ BenchMarkKeyAgreement<ECFHMQV160>("TestData/fhmqv160.dat", "FHMQV P-160", t);
+ BenchMarkKeyAgreement<ECFHMQV256>("TestData/fhmqv256.dat", "FHMQV P-256", t);
+ BenchMarkKeyAgreement<ECFHMQV384>("TestData/fhmqv384.dat", "FHMQV P-384", t);
+ BenchMarkKeyAgreement<ECFHMQV512>("TestData/fhmqv512.dat", "FHMQV P-512", t);
#endif
}
diff --git a/config.h b/config.h
index 7ca27c19..a71e5cf5 100644
--- a/config.h
+++ b/config.h
@@ -95,12 +95,23 @@
#define CRYPTOPP_VERSION 710
// 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/"'
+// Be sure to add the trailing slash since its simple concatenation.
+// After https://github.com/weidai11/cryptopp/issues/760 the library
+// should find the test vectors and data without much effort. It
+// will search in "./" and "$ORIGIN/../share/cryptopp" automatically.
#ifndef CRYPTOPP_DATA_DIR
# define CRYPTOPP_DATA_DIR ""
#endif
+// Define this to disable the test suite from searching for test
+// vectors and data in "./" and "$ORIGIN/../share/cryptopp". The
+// library will still search in CRYPTOPP_DATA_DIR, regardless.
+// Some distros may want to disable this feature. Also see
+// https://github.com/weidai11/cryptopp/issues/760
+// #ifndef CRYPTOPP_DISABLE_DATA_DIR_SEARCH
+// # define CRYPTOPP_DISABLE_DATA_DIR_SEARCH
+// #endif
+
// Define this if you want or need the library's memcpy_s and memmove_s.
// See http://github.com/weidai11/cryptopp/issues/28.
// #if !defined(CRYPTOPP_WANT_SECURE_LIB)
diff --git a/datatest.cpp b/datatest.cpp
index 4d0d7988..6a15ecb2 100644
--- a/datatest.cpp
+++ b/datatest.cpp
@@ -913,13 +913,7 @@ void OutputNameValuePairs(const NameValuePairs &v)
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);
- }
-
+ filename = DataDir(filename);
std::ifstream file(filename.c_str());
if (!file.good())
throw Exception(Exception::OTHER_ERROR, "Can not open file " + filename + " for reading");
diff --git a/test.cpp b/test.cpp
index 2f400eaa..8879c2c3 100644
--- a/test.cpp
+++ b/test.cpp
@@ -398,7 +398,7 @@ int scoped_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(std::cout));
+ FileSource usage(DataDir("TestData/usage.dat").c_str(), true, new FileSink(std::cout));
return 1;
}
else if (command == "V")
diff --git a/validat3.cpp b/validat3.cpp
index feecb14f..fb55dd54 100644
--- a/validat3.cpp
+++ b/validat3.cpp
@@ -99,8 +99,8 @@ bool ValidateAll(bool thorough)
pass=ValidateMD5() && pass;
pass=ValidateSHA() && pass;
- pass=RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/keccak.txt") && pass;
- pass=RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/sha3.txt") && pass;
+ pass=RunTestDataFile("TestVectors/keccak.txt") && pass;
+ pass=RunTestDataFile("TestVectors/sha3.txt") && pass;
pass=ValidateHashDRBG() && pass;
pass=ValidateHmacDRBG() && pass;
@@ -158,15 +158,15 @@ bool ValidateAll(bool thorough)
pass=ValidateRabbit() && pass;
pass=ValidateHC128() && pass;
pass=ValidateHC256() && pass;
- pass=RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/seed.txt") && pass;
- pass=RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/threefish.txt") && pass;
- pass=RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/kalyna.txt") && pass;
- pass=RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/sm4.txt") && pass;
+ pass=RunTestDataFile("TestVectors/seed.txt") && pass;
+ pass=RunTestDataFile("TestVectors/threefish.txt") && pass;
+ pass=RunTestDataFile("TestVectors/kalyna.txt") && pass;
+ pass=RunTestDataFile("TestVectors/sm4.txt") && pass;
pass=ValidateVMAC() && pass;
pass=ValidateCCM() && pass;
pass=ValidateGCM() && pass;
pass=ValidateCMAC() && pass;
- pass=RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/eax.txt") && pass;
+ pass=RunTestDataFile("TestVectors/eax.txt") && pass;
pass=ValidateBBS() && pass;
pass=ValidateDH() && pass;
diff --git a/validat4.cpp b/validat4.cpp
index 8b384999..96161a81 100644
--- a/validat4.cpp
+++ b/validat4.cpp
@@ -327,12 +327,12 @@ bool ValidateDES()
{
std::cout << "\nDES validation suite running...\n\n";
- FileSource valdata(CRYPTOPP_DATA_DIR "TestData/descert.dat", true, new HexDecoder);
+ FileSource valdata(DataDir("TestData/descert.dat").c_str(), true, new HexDecoder);
bool pass = BlockTransformationTest(FixedRoundsCipherFactory<DESEncryption, DESDecryption>(), valdata);
std::cout << "\nTesting EDE2, EDE3, and XEX3 variants...\n\n";
- FileSource valdata1(CRYPTOPP_DATA_DIR "TestData/3desval.dat", true, new HexDecoder);
+ FileSource valdata1(DataDir("TestData/3desval.dat").c_str(), true, new HexDecoder);
pass = BlockTransformationTest(FixedRoundsCipherFactory<DES_EDE2_Encryption, DES_EDE2_Decryption>(), valdata1, 1) && pass;
pass = BlockTransformationTest(FixedRoundsCipherFactory<DES_EDE3_Encryption, DES_EDE3_Decryption>(), valdata1, 1) && pass;
pass = BlockTransformationTest(FixedRoundsCipherFactory<DES_XEX3_Encryption, DES_XEX3_Decryption>(), valdata1, 1) && pass;
@@ -649,7 +649,7 @@ bool ValidateIDEA()
{
std::cout << "\nIDEA validation suite running...\n\n";
- FileSource valdata(CRYPTOPP_DATA_DIR "TestData/ideaval.dat", true, new HexDecoder);
+ FileSource valdata(DataDir("TestData/ideaval.dat").c_str(), true, new HexDecoder);
return BlockTransformationTest(FixedRoundsCipherFactory<IDEAEncryption, IDEADecryption>(), valdata);
}
@@ -657,7 +657,7 @@ bool ValidateSAFER()
{
std::cout << "\nSAFER validation suite running...\n\n";
- FileSource valdata(CRYPTOPP_DATA_DIR "TestData/saferval.dat", true, new HexDecoder);
+ FileSource valdata(DataDir("TestData/saferval.dat").c_str(), true, new HexDecoder);
bool pass = true;
pass = BlockTransformationTest(VariableRoundsCipherFactory<SAFER_K_Encryption, SAFER_K_Decryption>(8,6), valdata, 4) && pass;
pass = BlockTransformationTest(VariableRoundsCipherFactory<SAFER_K_Encryption, SAFER_K_Decryption>(16,12), valdata, 4) && pass;
@@ -670,7 +670,7 @@ bool ValidateRC2()
{
std::cout << "\nRC2 validation suite running...\n\n";
- FileSource valdata(CRYPTOPP_DATA_DIR "TestData/rc2val.dat", true, new HexDecoder);
+ FileSource valdata(DataDir("TestData/rc2val.dat").c_str(), true, new HexDecoder);
HexEncoder output(new FileSink(std::cout));
SecByteBlock plain(RC2Encryption::BLOCKSIZE), cipher(RC2Encryption::BLOCKSIZE), out(RC2Encryption::BLOCKSIZE), outplain(RC2Encryption::BLOCKSIZE);
SecByteBlock key(128);
@@ -899,7 +899,7 @@ bool ValidateRC5()
pass2 = dec.StaticGetValidKeyLength(SIZE_MAX) == dec.MaxKeyLength() && pass2;
std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
- FileSource valdata(CRYPTOPP_DATA_DIR "TestData/rc5val.dat", true, new HexDecoder);
+ FileSource valdata(DataDir("TestData/rc5val.dat").c_str(), true, new HexDecoder);
return BlockTransformationTest(VariableRoundsCipherFactory<RC5Encryption, RC5Decryption>(16, 12), valdata) && pass1 && pass2;
}
@@ -929,7 +929,7 @@ bool ValidateRC6()
pass2 = dec.StaticGetValidKeyLength(SIZE_MAX) == dec.MaxKeyLength() && pass2;
std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
- FileSource valdata(CRYPTOPP_DATA_DIR "TestData/rc6val.dat", true, new HexDecoder);
+ FileSource valdata(DataDir("TestData/rc6val.dat").c_str(), true, new HexDecoder);
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(16), valdata, 2) && pass3;
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(24), valdata, 2) && pass3;
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(32), valdata, 2) && pass3;
@@ -962,7 +962,7 @@ bool ValidateMARS()
pass2 = dec.StaticGetValidKeyLength(SIZE_MAX) == dec.MaxKeyLength() && pass2;
std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
- FileSource valdata(CRYPTOPP_DATA_DIR "TestData/marsval.dat", true, new HexDecoder);
+ FileSource valdata(DataDir("TestData/marsval.dat").c_str(), true, new HexDecoder);
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(16), valdata, 4) && pass3;
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(24), valdata, 3) && pass3;
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(32), valdata, 2) && pass3;
@@ -995,11 +995,11 @@ bool ValidateRijndael()
pass2 = dec.StaticGetValidKeyLength(SIZE_MAX) == dec.MaxKeyLength() && pass2;
std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
- FileSource valdata(CRYPTOPP_DATA_DIR "TestData/rijndael.dat", true, new HexDecoder);
+ FileSource valdata(DataDir("TestData/rijndael.dat").c_str(), true, new HexDecoder);
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<RijndaelEncryption, RijndaelDecryption>(16), valdata, 4) && pass3;
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<RijndaelEncryption, RijndaelDecryption>(24), valdata, 3) && pass3;
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<RijndaelEncryption, RijndaelDecryption>(32), valdata, 2) && pass3;
- pass3 = RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/aes.txt") && pass3;
+ pass3 = RunTestDataFile("TestVectors/aes.txt") && pass3;
return pass1 && pass2 && pass3;
}
@@ -1025,7 +1025,7 @@ bool ValidateTwofish()
pass2 = dec.StaticGetValidKeyLength(128) == 32 && pass2;
std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
- FileSource valdata(CRYPTOPP_DATA_DIR "TestData/twofishv.dat", true, new HexDecoder);
+ FileSource valdata(DataDir("TestData/twofishv.dat").c_str(), true, new HexDecoder);
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<TwofishEncryption, TwofishDecryption>(16), valdata, 4) && pass3;
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<TwofishEncryption, TwofishDecryption>(24), valdata, 3) && pass3;
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<TwofishEncryption, TwofishDecryption>(32), valdata, 2) && pass3;
@@ -1054,7 +1054,7 @@ bool ValidateSerpent()
pass2 = dec.StaticGetValidKeyLength(128) == 32 && pass2;
std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
- FileSource valdata(CRYPTOPP_DATA_DIR "TestData/serpentv.dat", true, new HexDecoder);
+ FileSource valdata(DataDir("TestData/serpentv.dat").c_str(), true, new HexDecoder);
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<SerpentEncryption, SerpentDecryption>(16), valdata, 5) && pass3;
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<SerpentEncryption, SerpentDecryption>(24), valdata, 4) && pass3;
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<SerpentEncryption, SerpentDecryption>(32), valdata, 3) && pass3;
@@ -1142,7 +1142,7 @@ bool ValidateThreeWay()
pass2 = dec.StaticGetValidKeyLength(16) == 12 && pass2;
std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
- FileSource valdata(CRYPTOPP_DATA_DIR "TestData/3wayval.dat", true, new HexDecoder);
+ FileSource valdata(DataDir("TestData/3wayval.dat").c_str(), true, new HexDecoder);
return BlockTransformationTest(FixedRoundsCipherFactory<ThreeWayEncryption, ThreeWayDecryption>(), valdata) && pass1 && pass2;
}
@@ -1168,7 +1168,7 @@ bool ValidateGOST()
pass2 = dec.StaticGetValidKeyLength(64) == 32 && pass2;
std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
- FileSource valdata(CRYPTOPP_DATA_DIR "TestData/gostval.dat", true, new HexDecoder);
+ FileSource valdata(DataDir("TestData/gostval.dat").c_str(), true, new HexDecoder);
return BlockTransformationTest(FixedRoundsCipherFactory<GOSTEncryption, GOSTDecryption>(), valdata) && pass1 && pass2;
}
@@ -1194,7 +1194,7 @@ bool ValidateSHARK()
pass2 = dec.StaticGetValidKeyLength(32) == 16 && pass2;
std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
- FileSource valdata(CRYPTOPP_DATA_DIR "TestData/sharkval.dat", true, new HexDecoder);
+ FileSource valdata(DataDir("TestData/sharkval.dat").c_str(), true, new HexDecoder);
return BlockTransformationTest(FixedRoundsCipherFactory<SHARKEncryption, SHARKDecryption>(), valdata) && pass1 && pass2;
}
@@ -1220,7 +1220,7 @@ bool ValidateCAST()
pass2 = dec1.StaticGetValidKeyLength(17) == 16 && pass2;
std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
- FileSource val128(CRYPTOPP_DATA_DIR "TestData/cast128v.dat", true, new HexDecoder);
+ FileSource val128(DataDir("TestData/cast128v.dat").c_str(), true, new HexDecoder);
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<CAST128Encryption, CAST128Decryption>(16), val128, 1) && pass3;
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<CAST128Encryption, CAST128Decryption>(10), val128, 1) && pass3;
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<CAST128Encryption, CAST128Decryption>(5), val128, 1) && pass3;
@@ -1253,7 +1253,7 @@ bool ValidateCAST()
pass5 = dec2.StaticGetValidKeyLength(33) == 32 && pass5;
std::cout << (pass4 && pass5 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
- FileSource val256(CRYPTOPP_DATA_DIR "TestData/cast256v.dat", true, new HexDecoder);
+ FileSource val256(DataDir("TestData/cast256v.dat").c_str(), true, new HexDecoder);
pass6 = BlockTransformationTest(FixedRoundsCipherFactory<CAST256Encryption, CAST256Decryption>(16), val256, 1) && pass6;
pass6 = BlockTransformationTest(FixedRoundsCipherFactory<CAST256Encryption, CAST256Decryption>(24), val256, 1) && pass6;
pass6 = BlockTransformationTest(FixedRoundsCipherFactory<CAST256Encryption, CAST256Decryption>(32), val256, 1) && pass6;
@@ -1279,7 +1279,7 @@ bool ValidateSquare()
pass2 = dec.StaticGetValidKeyLength(17) == 16 && pass2;
std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
- FileSource valdata(CRYPTOPP_DATA_DIR "TestData/squareva.dat", true, new HexDecoder);
+ FileSource valdata(DataDir("TestData/squareva.dat").c_str(), true, new HexDecoder);
return BlockTransformationTest(FixedRoundsCipherFactory<SquareEncryption, SquareDecryption>(), valdata) && pass1 && pass2;
}
@@ -1301,7 +1301,7 @@ bool ValidateSKIPJACK()
pass2 = dec.StaticGetValidKeyLength(16) == 10 && pass2;
std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
- FileSource valdata(CRYPTOPP_DATA_DIR "TestData/skipjack.dat", true, new HexDecoder);
+ FileSource valdata(DataDir("TestData/skipjack.dat").c_str(), true, new HexDecoder);
return BlockTransformationTest(FixedRoundsCipherFactory<SKIPJACKEncryption, SKIPJACKDecryption>(), valdata) && pass1 && pass2;
}
@@ -1615,7 +1615,7 @@ bool ValidateSHACAL2()
pass2 = dec.StaticGetValidKeyLength(SIZE_MAX) == dec.MaxKeyLength() && pass2;
std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
- FileSource valdata(CRYPTOPP_DATA_DIR "TestData/shacal2v.dat", true, new HexDecoder);
+ FileSource valdata(DataDir("TestData/shacal2v.dat").c_str(), true, new HexDecoder);
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<SHACAL2Encryption, SHACAL2Decryption>(16), valdata, 4) && pass3;
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<SHACAL2Encryption, SHACAL2Decryption>(64), valdata, 10) && pass3;
return pass1 && pass2 && pass3;
@@ -1647,7 +1647,7 @@ bool ValidateARIA()
pass2 = dec.StaticGetValidKeyLength(SIZE_MAX) == dec.MaxKeyLength() && pass2;
std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
- FileSource valdata(CRYPTOPP_DATA_DIR "TestData/aria.dat", true, new HexDecoder);
+ FileSource valdata(DataDir("TestData/aria.dat").c_str(), true, new HexDecoder);
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<ARIAEncryption, ARIADecryption>(16), valdata, 15) && pass3;
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<ARIAEncryption, ARIADecryption>(24), valdata, 15) && pass3;
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<ARIAEncryption, ARIADecryption>(32), valdata, 15) && pass3;
@@ -1658,42 +1658,42 @@ bool ValidateSIMECK()
{
std::cout << "\nSIMECK validation suite running...\n";
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/simeck.txt");
+ return RunTestDataFile("TestVectors/simeck.txt");
}
bool ValidateCHAM()
{
std::cout << "\nCHAM validation suite running...\n";
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/cham.txt");
+ return RunTestDataFile("TestVectors/cham.txt");
}
bool ValidateHIGHT()
{
std::cout << "\nHIGHT validation suite running...\n";
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/hight.txt");
+ return RunTestDataFile("TestVectors/hight.txt");
}
bool ValidateLEA()
{
std::cout << "\nLEA validation suite running...\n";
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/lea.txt");
+ return RunTestDataFile("TestVectors/lea.txt");
}
bool ValidateSIMON()
{
std::cout << "\nSIMON validation suite running...\n";
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/simon.txt");
+ return RunTestDataFile("TestVectors/simon.txt");
}
bool ValidateSPECK()
{
std::cout << "\nSPECK validation suite running...\n";
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/speck.txt");
+ return RunTestDataFile("TestVectors/speck.txt");
}
bool ValidateCamellia()
@@ -1722,7 +1722,7 @@ bool ValidateCamellia()
pass2 = dec.StaticGetValidKeyLength(SIZE_MAX) == dec.MaxKeyLength() && pass2;
std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
- FileSource valdata(CRYPTOPP_DATA_DIR "TestData/camellia.dat", true, new HexDecoder);
+ FileSource valdata(DataDir("TestData/camellia.dat").c_str(), true, new HexDecoder);
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(16), valdata, 15) && pass3;
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(24), valdata, 15) && pass3;
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(32), valdata, 15) && pass3;
@@ -1733,65 +1733,65 @@ bool ValidateSalsa()
{
std::cout << "\nSalsa validation suite running...\n";
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/salsa.txt");
+ return RunTestDataFile("TestVectors/salsa.txt");
}
bool ValidateChaCha()
{
std::cout << "\nChaCha validation suite running...\n";
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/chacha.txt");
+ return RunTestDataFile("TestVectors/chacha.txt");
}
bool ValidateSosemanuk()
{
std::cout << "\nSosemanuk validation suite running...\n";
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/sosemanuk.txt");
+ return RunTestDataFile("TestVectors/sosemanuk.txt");
}
bool ValidateRabbit()
{
std::cout << "\nRabbit validation suite running...\n";
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/rabbit.txt");
+ return RunTestDataFile("TestVectors/rabbit.txt");
}
bool ValidateHC128()
{
std::cout << "\nHC-128 validation suite running...\n";
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/hc128.txt");
+ return RunTestDataFile("TestVectors/hc128.txt");
}
bool ValidateHC256()
{
std::cout << "\nHC-256 validation suite running...\n";
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/hc256.txt");
+ return RunTestDataFile("TestVectors/hc256.txt");
}
bool ValidateVMAC()
{
std::cout << "\nVMAC validation suite running...\n";
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/vmac.txt");
+ return RunTestDataFile("TestVectors/vmac.txt");
}
bool ValidateCCM()
{
std::cout << "\nAES/CCM validation suite running...\n";
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/ccm.txt");
+ return RunTestDataFile("TestVectors/ccm.txt");
}
bool ValidateGCM()
{
std::cout << "\nAES/GCM validation suite running...\n";
std::cout << "\n2K tables:";
- bool pass = RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/gcm.txt", MakeParameters(Name::TableSize(), (int)2048));
+ bool pass = RunTestDataFile("TestVectors/gcm.txt", MakeParameters(Name::TableSize(), (int)2048));
std::cout << "\n64K tables:";
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/gcm.txt", MakeParameters(Name::TableSize(), (int)64*1024)) && pass;
+ return RunTestDataFile("TestVectors/gcm.txt", MakeParameters(Name::TableSize(), (int)64*1024)) && pass;
}
bool ValidateCMAC()
{
std::cout << "\nCMAC validation suite running...\n";
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/cmac.txt");
+ return RunTestDataFile("TestVectors/cmac.txt");
}
NAMESPACE_END // Test
diff --git a/validat5.cpp b/validat5.cpp
index b0b27849..e451c308 100644
--- a/validat5.cpp
+++ b/validat5.cpp
@@ -214,13 +214,19 @@ bool ValidateMD5()
bool ValidateSHA()
{
std::cout << "\nSHA validation suite running...\n";
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/sha.txt");
+ return RunTestDataFile("TestVectors/sha.txt");
}
bool ValidateSHA2()
{
- std::cout << "\nSHA validation suite running...\n";
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/sha.txt");
+ std::cout << "\nSHA-2 validation suite running...\n";
+ return RunTestDataFile("TestVectors/sha2.txt");
+}
+
+bool ValidateSHA3()
+{
+ std::cout << "\nSHA-3 validation suite running...\n";
+ return RunTestDataFile("TestVectors/sha3.txt");
}
bool ValidateTiger()
@@ -367,12 +373,12 @@ bool ValidateHAVAL()
bool ValidatePanama()
{
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/panama.txt");
+ return RunTestDataFile("TestVectors/panama.txt");
}
bool ValidateWhirlpool()
{
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/whrlpool.txt");
+ return RunTestDataFile("TestVectors/whrlpool.txt");
}
#ifdef CRYPTOPP_REMOVED
@@ -441,7 +447,7 @@ bool ValidateMD5MAC()
bool ValidateHMAC()
{
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/hmac.txt");
+ return RunTestDataFile("TestVectors/hmac.txt");
}
#ifdef CRYPTOPP_REMOVED
@@ -2016,7 +2022,7 @@ bool ValidateBLAKE2b()
bool ValidateSM3()
{
- return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/sm3.txt");
+ return RunTestDataFile("TestVectors/sm3.txt");
}
NAMESPACE_END // Test
diff --git a/validat7.cpp b/validat7.cpp
index a406650d..708176f9 100644
--- a/validat7.cpp
+++ b/validat7.cpp
@@ -45,7 +45,7 @@ bool ValidateDH()
{
std::cout << "\nDH validation suite running...\n\n";
- FileSource f(CRYPTOPP_DATA_DIR "TestData/dh1024.dat", true, new HexDecoder());
+ FileSource f(DataDir("TestData/dh1024.dat").c_str(), true, new HexDecoder);
DH dh(f);
return SimpleKeyAgreementValidate(dh);
}
@@ -54,7 +54,7 @@ bool ValidateMQV()
{
std::cout << "\nMQV validation suite running...\n\n";
- FileSource f(CRYPTOPP_DATA_DIR "TestData/mqv1024.dat", true, new HexDecoder());
+ FileSource f(DataDir("TestData/mqv1024.dat").c_str(), true, new HexDecoder);
MQV mqv(f);
return AuthenticatedKeyAgreementValidate(mqv);
}
@@ -64,9 +64,9 @@ bool ValidateHMQV()
std::cout << "\nHMQV validation suite running...\n\n";
ECHMQV256 hmqvB(false);
- FileSource f256(CRYPTOPP_DATA_DIR "TestData/hmqv256.dat", true, new HexDecoder());
- FileSource f384(CRYPTOPP_DATA_DIR "TestData/hmqv384.dat", true, new HexDecoder());
- FileSource f512(CRYPTOPP_DATA_DIR "TestData/hmqv512.dat", true, new HexDecoder());
+ FileSource f256(DataDir("TestData/hmqv256.dat").c_str(), true, new HexDecoder);
+ FileSource f384(DataDir("TestData/hmqv384.dat").c_str(), true, new HexDecoder);
+ FileSource f512(DataDir("TestData/hmqv512.dat").c_str(), true, new HexDecoder);
hmqvB.AccessGroupParameters().BERDecode(f256);
std::cout << "HMQV with NIST P-256 and SHA-256:" << std::endl;
@@ -181,9 +181,9 @@ std::cout << "\nFHMQV validation suite running...\n\n";
//ECFHMQV< ECP >::Domain fhmqvB(false /*server*/);
ECFHMQV256 fhmqvB(false);
- FileSource f256(CRYPTOPP_DATA_DIR "TestData/fhmqv256.dat", true, new HexDecoder());
- FileSource f384(CRYPTOPP_DATA_DIR "TestData/fhmqv384.dat", true, new HexDecoder());
- FileSource f512(CRYPTOPP_DATA_DIR "TestData/fhmqv512.dat", true, new HexDecoder());
+ FileSource f256(DataDir("TestData/fhmqv256.dat").c_str(), true, new HexDecoder);
+ FileSource f384(DataDir("TestData/fhmqv384.dat").c_str(), true, new HexDecoder);
+ FileSource f512(DataDir("TestData/fhmqv512.dat").c_str(), true, new HexDecoder);
fhmqvB.AccessGroupParameters().BERDecode(f256);
std::cout << "FHMQV with NIST P-256 and SHA-256:" << std::endl;
@@ -296,7 +296,7 @@ bool ValidateLUC_DH()
{
std::cout << "\nLUC-DH validation suite running...\n\n";
- FileSource f(CRYPTOPP_DATA_DIR "TestData/lucd512.dat", true, new HexDecoder());
+ FileSource f(DataDir("TestData/lucd512.dat").c_str(), true, new HexDecoder);
LUC_DH dh(f);
return SimpleKeyAgreementValidate(dh);
}
@@ -305,7 +305,7 @@ bool ValidateXTR_DH()
{
std::cout << "\nXTR-DH validation suite running...\n\n";
- FileSource f(CRYPTOPP_DATA_DIR "TestData/xtrdh171.dat", true, new HexDecoder());
+ FileSource f(DataDir("TestData/xtrdh171.dat").c_str(), true, new HexDecoder);
XTR_DH dh(f);
return SimpleKeyAgreementValidate(dh);
}
diff --git a/validat8.cpp b/validat8.cpp
index 1562d27c..c168a406 100644
--- a/validat8.cpp
+++ b/validat8.cpp
@@ -45,7 +45,7 @@ bool ValidateRSA_Encrypt()
bool pass = true, fail;
{
- FileSource keys(CRYPTOPP_DATA_DIR "TestData/rsa1024.dat", true, new HexDecoder);
+ FileSource keys(DataDir("TestData/rsa1024.dat").c_str(), true, new HexDecoder);
RSAES_PKCS1v15_Decryptor rsaPriv(keys);
RSAES_PKCS1v15_Encryptor rsaPub(rsaPriv);
@@ -72,8 +72,8 @@ bool ValidateRSA_Encrypt()
bq.Put(oaepSeed, 20);
FixedRNG rng(bq);
- FileSource privFile(CRYPTOPP_DATA_DIR "TestData/rsa400pv.dat", true, new HexDecoder);
- FileSource pubFile(CRYPTOPP_DATA_DIR "TestData/rsa400pb.dat", true, new HexDecoder);
+ FileSource privFile(DataDir("TestData/rsa400pv.dat").c_str(), true, new HexDecoder);
+ FileSource pubFile(DataDir("TestData/rsa400pb.dat").c_str(), true, new HexDecoder);
RSAES_OAEP_SHA_Decryptor rsaPriv;
rsaPriv.AccessKey().BERDecodePrivateKey(privFile, false, 0);
RSAES_OAEP_SHA_Encryptor rsaPub(pubFile);
@@ -94,7 +94,7 @@ bool ValidateRSA_Encrypt()
bool ValidateLUC_Encrypt()
{
- FileSource f(CRYPTOPP_DATA_DIR "TestData/luc1024.dat", true, new HexDecoder);
+ FileSource f(DataDir("TestData/luc1024.dat").c_str(), true, new HexDecoder);
LUCES_OAEP_SHA_Decryptor priv(GlobalRNG(), 512);
LUCES_OAEP_SHA_Encryptor pub(priv);
return CryptoSystemValidate(priv, pub);
@@ -104,7 +104,7 @@ bool ValidateLUC_DL_Encrypt()
{
std::cout << "\nLUC-IES validation suite running...\n\n";
- FileSource fc(CRYPTOPP_DATA_DIR "TestData/lucc512.dat", true, new HexDecoder);
+ FileSource fc(DataDir("TestData/lucc512.dat").c_str(), true, new HexDecoder);
LUC_IES<>::Decryptor privC(fc);
LUC_IES<>::Encryptor pubC(privC);
return CryptoSystemValidate(privC, pubC);
@@ -112,7 +112,7 @@ bool ValidateLUC_DL_Encrypt()
bool ValidateRabin_Encrypt()
{
- FileSource f(CRYPTOPP_DATA_DIR "TestData/rabi1024.dat", true, new HexDecoder);
+ FileSource f(DataDir("TestData/rabi1024.dat").c_str(), true, new HexDecoder);
RabinES<OAEP<SHA1> >::Decryptor priv(f);
RabinES<OAEP<SHA1> >::Encryptor pub(priv);
return CryptoSystemValidate(priv, pub);
@@ -163,7 +163,7 @@ bool ValidateElGamal()
std::cout << "\nElGamal validation suite running...\n\n";
bool pass = true;
{
- FileSource fc(CRYPTOPP_DATA_DIR "TestData/elgc1024.dat", true, new HexDecoder);
+ FileSource fc(DataDir("TestData/elgc1024.dat").c_str(), true, new HexDecoder);
ElGamalDecryptor privC(fc);
ElGamalEncryptor pubC(privC);
privC.AccessKey().Precompute();
@@ -181,7 +181,7 @@ bool ValidateDLIES()
std::cout << "\nDLIES validation suite running...\n\n";
bool pass = true;
{
- FileSource fc(CRYPTOPP_DATA_DIR "TestData/dlie1024.dat", true, new HexDecoder);
+ FileSource fc(DataDir("TestData/dlie1024.dat").c_str(), true, new HexDecoder);
DLIES<>::Decryptor privC(fc);
DLIES<>::Encryptor pubC(privC);
pass = CryptoSystemValidate(privC, pubC) && pass;
diff --git a/validat9.cpp b/validat9.cpp
index 159a3e4c..89c42a03 100644
--- a/validat9.cpp
+++ b/validat9.cpp
@@ -56,13 +56,13 @@ bool ValidateRSA_Sign()
{
const char plain[] = "Everyone gets Friday off.";
- static const byte signature[] =
+ const byte signature[] =
"\x05\xfa\x6a\x81\x2f\xc7\xdf\x8b\xf4\xf2\x54\x25\x09\xe0\x3e\x84"
"\x6e\x11\xb9\xc6\x20\xbe\x20\x09\xef\xb4\x40\xef\xbc\xc6\x69\x21"
"\x69\x94\xac\x04\xf3\x41\xb5\x7d\x05\x20\x2d\x42\x8f\xb2\xa2\x7b"
"\x5c\x77\xdf\xd9\xb1\x5b\xfc\x3d\x55\x93\x53\x50\x34\x10\xc1\xe1";
- FileSource keys(CRYPTOPP_DATA_DIR "TestData/rsa512a.dat", true, new HexDecoder);
+ FileSource keys(DataDir("TestData/rsa512a.dat").c_str(), true, new HexDecoder);
Weak::RSASSA_PKCS1v15_MD2_Signer rsaPriv(keys);
Weak::RSASSA_PKCS1v15_MD2_Verifier rsaPub(rsaPriv);
@@ -90,7 +90,7 @@ bool ValidateRSA_Sign()
/////
{
const char plain[] = "Everyone gets Friday off.";
- static const byte signature[] =
+ const byte signature[] =
"\x2e\x87\xda\x1f\xe4\xda\x1d\x7a\xb7\xf2\x42\x36\xe9\xc0\x4e\xab\x3f\x03\x71\xe1"
"\x2b\xc5\x3c\xbf\x21\x21\xa8\xd6\x28\xb0\x08\xfd\x9c\xf6\x94\xbd\x37\x32\xda\xfc"
"\x42\x1c\x8e\xdb\x8a\x81\x90\x46\x45\xb4\xde\x9e\xce\x90\xfe\xa1\xfd\xbc\x5a\xce"
@@ -105,7 +105,7 @@ bool ValidateRSA_Sign()
"\xeb\x89\x65\x53\x35\xe7\x13\x7e\xbb\x26\xb0\x76\x9c\xf2\x80\xaa\xe1\xb1\x0a\xa6"
"\x47\xfc\x5f\xe0\x7f\x82\xd7\x83\x41\xc3\x50\xa1\xe0\x0e\x1a\xe4";
- FileSource keys(CRYPTOPP_DATA_DIR "TestData/rsa2048a.dat", true, new HexDecoder);
+ FileSource keys(DataDir("TestData/rsa2048a.dat").c_str(), true, new HexDecoder);
RSASS<PKCS1v15, SHA3_256>::Signer rsaPriv(keys);
RSASS<PKCS1v15, SHA3_256>::Verifier rsaPub(rsaPriv);
@@ -139,7 +139,7 @@ bool ValidateNR()
std::cout << "\nNR validation suite running...\n\n";
bool pass = true;
{
- FileSource f(CRYPTOPP_DATA_DIR "TestData/nr2048.dat", true, new HexDecoder);
+ FileSource f(DataDir("TestData/nr2048.dat").c_str(), true, new HexDecoder);
NR<SHA1>::Signer privS(f);
privS.AccessKey().Precompute();
NR<SHA1>::Verifier pubS(privS);
@@ -161,21 +161,21 @@ bool ValidateDSA(bool thorough)
std::cout << "\nDSA validation suite running...\n\n";
bool pass = true;
- FileSource fs1(CRYPTOPP_DATA_DIR "TestData/dsa1024.dat", true, new HexDecoder());
+ FileSource fs1(DataDir("TestData/dsa1024.dat").c_str(), true, new HexDecoder);
DSA::Signer priv(fs1);
DSA::Verifier pub(priv);
- FileSource fs2(CRYPTOPP_DATA_DIR "TestData/dsa1024b.dat", true, new HexDecoder());
+ FileSource fs2(DataDir("TestData/dsa1024b.dat").c_str(), true, new HexDecoder);
DSA::Verifier pub1(fs2);
CRYPTOPP_ASSERT(pub.GetKey() == pub1.GetKey());
pass = SignatureValidate(priv, pub, thorough) && pass;
- pass = RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/dsa.txt", g_nullNameValuePairs, thorough) && pass;
+ pass = RunTestDataFile("TestVectors/dsa.txt", g_nullNameValuePairs, thorough) && pass;
return pass;
}
bool ValidateLUC_Sign()
{
- FileSource f(CRYPTOPP_DATA_DIR "TestData/luc1024.dat", true, new HexDecoder);
+ FileSource f(DataDir("TestData/luc1024.dat").c_str(), true, new HexDecoder);
LUCSSA_PKCS1v15_SHA_Signer priv(f);
LUCSSA_PKCS1v15_SHA_Verifier pub(priv);
return SignatureValidate(priv, pub);
@@ -185,7 +185,7 @@ bool ValidateLUC_DL_Sign()
{
std::cout << "\nLUC-HMP validation suite running...\n\n";
- FileSource f(CRYPTOPP_DATA_DIR "TestData/lucs512.dat", true, new HexDecoder);
+ FileSource f(DataDir("TestData/lucs512.dat").c_str(), true, new HexDecoder);
LUC_HMP<SHA1>::Signer privS(f);
LUC_HMP<SHA1>::Verifier pubS(privS);
return SignatureValidate(privS, pubS);
@@ -193,7 +193,7 @@ bool ValidateLUC_DL_Sign()
bool ValidateRabin_Sign()
{
- FileSource f(CRYPTOPP_DATA_DIR "TestData/rabi1024.dat", true, new HexDecoder);
+ FileSource f(DataDir("TestData/rabi1024.dat").c_str(), true, new HexDecoder);
RabinSS<PSSR, SHA1>::Signer priv(f);
RabinSS<PSSR, SHA1>::Verifier pub(priv);
return SignatureValidate(priv, pub);
@@ -203,7 +203,7 @@ bool ValidateRW()
{
std::cout << "\nRW validation suite running...\n\n";
- FileSource f(CRYPTOPP_DATA_DIR "TestData/rw1024.dat", true, new HexDecoder);
+ FileSource f(DataDir("TestData/rw1024.dat").c_str(), true, new HexDecoder);
RWSS<PSSR, SHA1>::Signer priv(f);
RWSS<PSSR, SHA1>::Verifier pub(priv);
@@ -272,7 +272,7 @@ bool ValidateECDSA()
Integer h("A9993E364706816ABA3E25717850C26C9CD0D89DH");
Integer k("3eeace72b4919d991738d521879f787cb590aff8189d2b69H");
- static const byte sig[]="\x03\x8e\x5a\x11\xfb\x55\xe4\xc6\x54\x71\xdc\xd4\x99\x84\x52\xb1\xe0\x2d\x8a\xf7\x09\x9b\xb9\x30"
+ const byte sig[]="\x03\x8e\x5a\x11\xfb\x55\xe4\xc6\x54\x71\xdc\xd4\x99\x84\x52\xb1\xe0\x2d\x8a\xf7\x09\x9b\xb9\x30"
"\x0c\x9a\x08\xc3\x44\x68\xc2\x44\xb4\xe5\xd6\xb2\x1b\x3c\x68\x36\x28\x07\x41\x60\x20\x32\x8b\x6e";
Integer r(sig, 24);
Integer s(sig+24, 24);
@@ -636,8 +636,8 @@ bool ValidateESIGN()
bool pass = true, fail;
- static const char plain[] = "test";
- static const byte signature[] =
+ const char plain[] = "test";
+ const byte signature[] =
"\xA3\xE3\x20\x65\xDE\xDA\xE7\xEC\x05\xC1\xBF\xCD\x25\x79\x7D\x99\xCD\xD5\x73\x9D\x9D\xF3\xA4\xAA\x9A\xA4\x5A\xC8\x23\x3D\x0D\x37"
"\xFE\xBC\x76\x3F\xF1\x84\xF6\x59\x14\x91\x4F\x0C\x34\x1B\xAE\x9A\x5C\x2E\x2E\x38\x08\x78\x77\xCB\xDC\x3C\x7E\xA0\x34\x44\x5B\x0F"
"\x67\xD9\x35\x2A\x79\x47\x1A\x52\x37\x71\xDB\x12\x67\xC1\xB6\xC6\x66\x73\xB3\x40\x2E\xD6\xF2\x1A\x84\x0A\xB6\x7B\x0F\xEB\x8B\x88"
@@ -645,7 +645,7 @@ bool ValidateESIGN()
"\xF4\x15\x65\xB8\xE1\xD1\x45\xAE\x39\x19\xB4\xFF\x5D\xF1\x45\x7B\xE0\xFE\x72\xED\x11\x92\x8F\x61\x41\x4F\x02\x00\xF2\x76\x6F\x7C"
"\x79\xA2\xE5\x52\x20\x5D\x97\x5E\xFE\x39\xAE\x21\x10\xFB\x35\xF4\x80\x81\x41\x13\xDD\xE8\x5F\xCA\x1E\x4F\xF8\x9B\xB2\x68\xFB\x28";
- FileSource keys(CRYPTOPP_DATA_DIR "TestData/esig1536.dat", true, new HexDecoder);
+ FileSource keys(DataDir("TestData/esig1536.dat").c_str(), true, new HexDecoder);
ESIGN<SHA1>::Signer signer(keys);
ESIGN<SHA1>::Verifier verifier(signer);
diff --git a/validate.h b/validate.h
index f892ca8b..99b42a7c 100644
--- a/validate.h
+++ b/validate.h
@@ -246,8 +246,42 @@ inline int StringToValue<int, true>(const std::string& str)
return r;
}
+inline std::string AddSeparator(std::string str)
+{
+ const char last = (str.empty() ? '\0' : *str.end()-1);
+ if (last != '/' && last != '\\')
+ return str + "/";
+ return str;
+}
+
+inline std::string DataDir(const std::string& filename)
+{
+ std::ifstream file;
+#ifndef CRYPTOPP_DISABLE_DATA_DIR_SEARCH
+ // Data files in PWD are probably the newest. This is probably a build directory.
+ file.open(std::string("./") + filename);
+ if (file.is_open())
+ return std::string("./") + filename;
+#endif
+#ifdef CRYPTOPP_DATA_DIR
+ // Honor the user's setting next. This is likely an install directory if it is not "./".
+ std::string data_dir(AddSeparator(CRYPTOPP_DATA_DIR));
+ file.open(data_dir + filename);
+ if (file.is_open())
+ data_dir + filename;
+#endif
+#ifndef CRYPTOPP_DISABLE_DATA_DIR_SEARCH
+ // Finally look in {$ORIGIN}/bin/../share/
+ file.open(std::string("../share/cryptopp/") + filename);
+ if (file.is_open())
+ return std::string("../share/cryptopp/") + filename;
+#endif
+ // This will cause the expected exception in the caller
+ return filename;
+}
+
// Definition in test.cpp
-RandomNumberGenerator & GlobalRNG();
+RandomNumberGenerator& GlobalRNG();
// Definition in datatest.cpp
bool RunTestDataFile(const char *filename, const NameValuePairs &overrideParameters=g_nullNameValuePairs, bool thorough=true);