Skip to content

Commit 1c88fd6

Browse files
committed
Add search for test vectors and test data (GH #760)
1 parent 5203558 commit 1c88fd6

File tree

11 files changed

+185
-140
lines changed

11 files changed

+185
-140
lines changed

bench3.cpp

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ void BenchMarkAgreement(const char *name, AuthenticatedKeyAgreementDomain &d, do
273273
template <class SCHEME>
274274
void BenchMarkCrypto(const char *filename, const char *name, double timeTotal)
275275
{
276-
FileSource f(filename, true, new HexDecoder);
276+
FileSource f(DataDir(filename).c_str(), true, new HexDecoder);
277277
typename SCHEME::Decryptor priv(f);
278278
typename SCHEME::Encryptor pub(priv);
279279
BenchMarkEncryption(name, pub, timeTotal);
@@ -283,7 +283,7 @@ void BenchMarkCrypto(const char *filename, const char *name, double timeTotal)
283283
template <class SCHEME>
284284
void BenchMarkSignature(const char *filename, const char *name, double timeTotal)
285285
{
286-
FileSource f(filename, true, new HexDecoder);
286+
FileSource f(DataDir(filename).c_str(), true, new HexDecoder);
287287
typename SCHEME::Signer priv(f);
288288
typename SCHEME::Verifier pub(priv);
289289
BenchMarkSigning(name, priv, timeTotal);
@@ -293,7 +293,7 @@ void BenchMarkSignature(const char *filename, const char *name, double timeTotal
293293
template <class D>
294294
void BenchMarkKeyAgreement(const char *filename, const char *name, double timeTotal)
295295
{
296-
FileSource f(filename, true, new HexDecoder);
296+
FileSource f(DataDir(filename).c_str(), true, new HexDecoder);
297297
D d(f);
298298
BenchMarkKeyGen(name, d, timeTotal);
299299
BenchMarkAgreement(name, d, timeTotal);
@@ -318,63 +318,63 @@ void Benchmark3(double t, double hertz)
318318

319319
std::cout << "\n<TBODY style=\"background: white;\">";
320320
{
321-
BenchMarkCrypto<RSAES<OAEP<SHA1> > >(CRYPTOPP_DATA_DIR "TestData/rsa1024.dat", "RSA 1024", t);
322-
BenchMarkCrypto<LUCES<OAEP<SHA1> > >(CRYPTOPP_DATA_DIR "TestData/luc1024.dat", "LUC 1024", t);
323-
BenchMarkCrypto<DLIES<> >(CRYPTOPP_DATA_DIR "TestData/dlie1024.dat", "DLIES 1024", t);
324-
BenchMarkCrypto<LUC_IES<> >(CRYPTOPP_DATA_DIR "TestData/lucc512.dat", "LUCELG 512", t);
321+
BenchMarkCrypto<RSAES<OAEP<SHA1> > >("TestData/rsa1024.dat", "RSA 1024", t);
322+
BenchMarkCrypto<LUCES<OAEP<SHA1> > >("TestData/luc1024.dat", "LUC 1024", t);
323+
BenchMarkCrypto<DLIES<> >("TestData/dlie1024.dat", "DLIES 1024", t);
324+
BenchMarkCrypto<LUC_IES<> >("TestData/lucc512.dat", "LUCELG 512", t);
325325
}
326326

327327
std::cout << "\n<TBODY style=\"background: yellow;\">";
328328
{
329-
BenchMarkCrypto<RSAES<OAEP<SHA1> > >(CRYPTOPP_DATA_DIR "TestData/rsa2048.dat", "RSA 2048", t);
330-
BenchMarkCrypto<LUCES<OAEP<SHA1> > >(CRYPTOPP_DATA_DIR "TestData/luc2048.dat", "LUC 2048", t);
331-
BenchMarkCrypto<DLIES<> >(CRYPTOPP_DATA_DIR "TestData/dlie2048.dat", "DLIES 2048", t);
332-
BenchMarkCrypto<LUC_IES<> >(CRYPTOPP_DATA_DIR "TestData/lucc1024.dat", "LUCELG 1024", t);
329+
BenchMarkCrypto<RSAES<OAEP<SHA1> > >("TestData/rsa2048.dat", "RSA 2048", t);
330+
BenchMarkCrypto<LUCES<OAEP<SHA1> > >("TestData/luc2048.dat", "LUC 2048", t);
331+
BenchMarkCrypto<DLIES<> >("TestData/dlie2048.dat", "DLIES 2048", t);
332+
BenchMarkCrypto<LUC_IES<> >("TestData/lucc1024.dat", "LUCELG 1024", t);
333333
}
334334

335335
std::cout << "\n<TBODY style=\"background: white;\">";
336336
{
337-
BenchMarkSignature<RSASS<PSSR, SHA1> >(CRYPTOPP_DATA_DIR "TestData/rsa1024.dat", "RSA 1024", t);
338-
BenchMarkSignature<RWSS<PSSR, SHA1> >(CRYPTOPP_DATA_DIR "TestData/rw1024.dat", "RW 1024", t);
339-
BenchMarkSignature<LUCSS<PSSR, SHA1> >(CRYPTOPP_DATA_DIR "TestData/luc1024.dat", "LUC 1024", t);
340-
BenchMarkSignature<NR<SHA1> >(CRYPTOPP_DATA_DIR "TestData/nr1024.dat", "NR 1024", t);
341-
BenchMarkSignature<DSA>(CRYPTOPP_DATA_DIR "TestData/dsa1024.dat", "DSA 1024", t);
342-
BenchMarkSignature<LUC_HMP<SHA1> >(CRYPTOPP_DATA_DIR "TestData/lucs512.dat", "LUC-HMP 512", t);
343-
BenchMarkSignature<ESIGN<SHA1> >(CRYPTOPP_DATA_DIR "TestData/esig1023.dat", "ESIGN 1023", t);
344-
BenchMarkSignature<ESIGN<SHA1> >(CRYPTOPP_DATA_DIR "TestData/esig1536.dat", "ESIGN 1536", t);
337+
BenchMarkSignature<RSASS<PSSR, SHA1> >("TestData/rsa1024.dat", "RSA 1024", t);
338+
BenchMarkSignature<RWSS<PSSR, SHA1> >("TestData/rw1024.dat", "RW 1024", t);
339+
BenchMarkSignature<LUCSS<PSSR, SHA1> >("TestData/luc1024.dat", "LUC 1024", t);
340+
BenchMarkSignature<NR<SHA1> >("TestData/nr1024.dat", "NR 1024", t);
341+
BenchMarkSignature<DSA>("TestData/dsa1024.dat", "DSA 1024", t);
342+
BenchMarkSignature<LUC_HMP<SHA1> >("TestData/lucs512.dat", "LUC-HMP 512", t);
343+
BenchMarkSignature<ESIGN<SHA1> >("TestData/esig1023.dat", "ESIGN 1023", t);
344+
BenchMarkSignature<ESIGN<SHA1> >("TestData/esig1536.dat", "ESIGN 1536", t);
345345
}
346346

347347
std::cout << "\n<TBODY style=\"background: yellow;\">";
348348
{
349-
BenchMarkSignature<RSASS<PSSR, SHA1> >(CRYPTOPP_DATA_DIR "TestData/rsa2048.dat", "RSA 2048", t);
350-
BenchMarkSignature<RWSS<PSSR, SHA1> >(CRYPTOPP_DATA_DIR "TestData/rw2048.dat", "RW 2048", t);
351-
BenchMarkSignature<LUCSS<PSSR, SHA1> >(CRYPTOPP_DATA_DIR "TestData/luc2048.dat", "LUC 2048", t);
352-
BenchMarkSignature<NR<SHA1> >(CRYPTOPP_DATA_DIR "TestData/nr2048.dat", "NR 2048", t);
353-
BenchMarkSignature<LUC_HMP<SHA1> >(CRYPTOPP_DATA_DIR "TestData/lucs1024.dat", "LUC-HMP 1024", t);
354-
BenchMarkSignature<ESIGN<SHA1> >(CRYPTOPP_DATA_DIR "TestData/esig2046.dat", "ESIGN 2046", t);
349+
BenchMarkSignature<RSASS<PSSR, SHA1> >("TestData/rsa2048.dat", "RSA 2048", t);
350+
BenchMarkSignature<RWSS<PSSR, SHA1> >("TestData/rw2048.dat", "RW 2048", t);
351+
BenchMarkSignature<LUCSS<PSSR, SHA1> >("TestData/luc2048.dat", "LUC 2048", t);
352+
BenchMarkSignature<NR<SHA1> >("TestData/nr2048.dat", "NR 2048", t);
353+
BenchMarkSignature<LUC_HMP<SHA1> >("TestData/lucs1024.dat", "LUC-HMP 1024", t);
354+
BenchMarkSignature<ESIGN<SHA1> >("TestData/esig2046.dat", "ESIGN 2046", t);
355355
}
356356

357357
std::cout << "\n<TBODY style=\"background: white;\">";
358358
{
359-
BenchMarkKeyAgreement<XTR_DH>(CRYPTOPP_DATA_DIR "TestData/xtrdh171.dat", "XTR-DH 171", t);
360-
BenchMarkKeyAgreement<XTR_DH>(CRYPTOPP_DATA_DIR "TestData/xtrdh342.dat", "XTR-DH 342", t);
361-
BenchMarkKeyAgreement<DH>(CRYPTOPP_DATA_DIR "TestData/dh1024.dat", "DH 1024", t);
362-
BenchMarkKeyAgreement<DH>(CRYPTOPP_DATA_DIR "TestData/dh2048.dat", "DH 2048", t);
363-
BenchMarkKeyAgreement<LUC_DH>(CRYPTOPP_DATA_DIR "TestData/lucd512.dat", "LUCDIF 512", t);
364-
BenchMarkKeyAgreement<LUC_DH>(CRYPTOPP_DATA_DIR "TestData/lucd1024.dat", "LUCDIF 1024", t);
365-
BenchMarkKeyAgreement<MQV>(CRYPTOPP_DATA_DIR "TestData/mqv1024.dat", "MQV 1024", t);
366-
BenchMarkKeyAgreement<MQV>(CRYPTOPP_DATA_DIR "TestData/mqv2048.dat", "MQV 2048", t);
359+
BenchMarkKeyAgreement<XTR_DH>("TestData/xtrdh171.dat", "XTR-DH 171", t);
360+
BenchMarkKeyAgreement<XTR_DH>("TestData/xtrdh342.dat", "XTR-DH 342", t);
361+
BenchMarkKeyAgreement<DH>("TestData/dh1024.dat", "DH 1024", t);
362+
BenchMarkKeyAgreement<DH>("TestData/dh2048.dat", "DH 2048", t);
363+
BenchMarkKeyAgreement<LUC_DH>("TestData/lucd512.dat", "LUCDIF 512", t);
364+
BenchMarkKeyAgreement<LUC_DH>("TestData/lucd1024.dat", "LUCDIF 1024", t);
365+
BenchMarkKeyAgreement<MQV>("TestData/mqv1024.dat", "MQV 1024", t);
366+
BenchMarkKeyAgreement<MQV>("TestData/mqv2048.dat", "MQV 2048", t);
367367

368368
#if 0
369-
BenchMarkKeyAgreement<ECHMQV160>(CRYPTOPP_DATA_DIR "TestData/hmqv160.dat", "HMQV P-160", t);
370-
BenchMarkKeyAgreement<ECHMQV256>(CRYPTOPP_DATA_DIR "TestData/hmqv256.dat", "HMQV P-256", t);
371-
BenchMarkKeyAgreement<ECHMQV384>(CRYPTOPP_DATA_DIR "TestData/hmqv384.dat", "HMQV P-384", t);
372-
BenchMarkKeyAgreement<ECHMQV512>(CRYPTOPP_DATA_DIR "TestData/hmqv512.dat", "HMQV P-512", t);
373-
374-
BenchMarkKeyAgreement<ECFHMQV160>(CRYPTOPP_DATA_DIR "TestData/fhmqv160.dat", "FHMQV P-160", t);
375-
BenchMarkKeyAgreement<ECFHMQV256>(CRYPTOPP_DATA_DIR "TestData/fhmqv256.dat", "FHMQV P-256", t);
376-
BenchMarkKeyAgreement<ECFHMQV384>(CRYPTOPP_DATA_DIR "TestData/fhmqv384.dat", "FHMQV P-384", t);
377-
BenchMarkKeyAgreement<ECFHMQV512>(CRYPTOPP_DATA_DIR "TestData/fhmqv512.dat", "FHMQV P-512", t);
369+
BenchMarkKeyAgreement<ECHMQV160>("TestData/hmqv160.dat", "HMQV P-160", t);
370+
BenchMarkKeyAgreement<ECHMQV256>("TestData/hmqv256.dat", "HMQV P-256", t);
371+
BenchMarkKeyAgreement<ECHMQV384>("TestData/hmqv384.dat", "HMQV P-384", t);
372+
BenchMarkKeyAgreement<ECHMQV512>("TestData/hmqv512.dat", "HMQV P-512", t);
373+
374+
BenchMarkKeyAgreement<ECFHMQV160>("TestData/fhmqv160.dat", "FHMQV P-160", t);
375+
BenchMarkKeyAgreement<ECFHMQV256>("TestData/fhmqv256.dat", "FHMQV P-256", t);
376+
BenchMarkKeyAgreement<ECFHMQV384>("TestData/fhmqv384.dat", "FHMQV P-384", t);
377+
BenchMarkKeyAgreement<ECFHMQV512>("TestData/fhmqv512.dat", "FHMQV P-512", t);
378378
#endif
379379
}
380380

config.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,23 @@
9595
#define CRYPTOPP_VERSION 710
9696

9797
// Define this if you want to set a prefix for TestData/ and TestVectors/
98-
// Be mindful of the trailing slash since its simple concatenation.
99-
// g++ ... -DCRYPTOPP_DATA_DIR='"/tmp/cryptopp_test/share/"'
98+
// Be sure to add the trailing slash since its simple concatenation.
99+
// After https://github.com/weidai11/cryptopp/issues/760 the library
100+
// should find the test vectors and data without much effort. It
101+
// will search in "./" and "$ORIGIN/../share/cryptopp" automatically.
100102
#ifndef CRYPTOPP_DATA_DIR
101103
# define CRYPTOPP_DATA_DIR ""
102104
#endif
103105

106+
// Define this to disable the test suite from searching for test
107+
// vectors and data in "./" and "$ORIGIN/../share/cryptopp". The
108+
// library will still search in CRYPTOPP_DATA_DIR, regardless.
109+
// Some distros may want to disable this feature. Also see
110+
// https://github.com/weidai11/cryptopp/issues/760
111+
// #ifndef CRYPTOPP_DISABLE_DATA_DIR_SEARCH
112+
// # define CRYPTOPP_DISABLE_DATA_DIR_SEARCH
113+
// #endif
114+
104115
// Define this if you want or need the library's memcpy_s and memmove_s.
105116
// See http://github.com/weidai11/cryptopp/issues/28.
106117
// #if !defined(CRYPTOPP_WANT_SECURE_LIB)

datatest.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -913,13 +913,7 @@ void OutputNameValuePairs(const NameValuePairs &v)
913913

914914
void TestDataFile(std::string filename, const NameValuePairs &overrideParameters, unsigned int &totalTests, unsigned int &failedTests)
915915
{
916-
static const std::string dataDirectory(CRYPTOPP_DATA_DIR);
917-
if (!dataDirectory.empty())
918-
{
919-
if(dataDirectory != filename.substr(0, dataDirectory.length()))
920-
filename.insert(0, dataDirectory);
921-
}
922-
916+
filename = DataDir(filename);
923917
std::ifstream file(filename.c_str());
924918
if (!file.good())
925919
throw Exception(Exception::OTHER_ERROR, "Can not open file " + filename + " for reading");

test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ int scoped_main(int argc, char *argv[])
398398
AES_CTR_Encrypt(argv[2], argv[3], argv[4], argv[5]);
399399
else if (command == "h")
400400
{
401-
FileSource usage(CRYPTOPP_DATA_DIR "TestData/usage.dat", true, new FileSink(std::cout));
401+
FileSource usage(DataDir("TestData/usage.dat").c_str(), true, new FileSink(std::cout));
402402
return 1;
403403
}
404404
else if (command == "V")

validat3.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ bool ValidateAll(bool thorough)
9999
pass=ValidateMD5() && pass;
100100
pass=ValidateSHA() && pass;
101101

102-
pass=RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/keccak.txt") && pass;
103-
pass=RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/sha3.txt") && pass;
102+
pass=RunTestDataFile("TestVectors/keccak.txt") && pass;
103+
pass=RunTestDataFile("TestVectors/sha3.txt") && pass;
104104

105105
pass=ValidateHashDRBG() && pass;
106106
pass=ValidateHmacDRBG() && pass;
@@ -158,15 +158,15 @@ bool ValidateAll(bool thorough)
158158
pass=ValidateRabbit() && pass;
159159
pass=ValidateHC128() && pass;
160160
pass=ValidateHC256() && pass;
161-
pass=RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/seed.txt") && pass;
162-
pass=RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/threefish.txt") && pass;
163-
pass=RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/kalyna.txt") && pass;
164-
pass=RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/sm4.txt") && pass;
161+
pass=RunTestDataFile("TestVectors/seed.txt") && pass;
162+
pass=RunTestDataFile("TestVectors/threefish.txt") && pass;
163+
pass=RunTestDataFile("TestVectors/kalyna.txt") && pass;
164+
pass=RunTestDataFile("TestVectors/sm4.txt") && pass;
165165
pass=ValidateVMAC() && pass;
166166
pass=ValidateCCM() && pass;
167167
pass=ValidateGCM() && pass;
168168
pass=ValidateCMAC() && pass;
169-
pass=RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/eax.txt") && pass;
169+
pass=RunTestDataFile("TestVectors/eax.txt") && pass;
170170

171171
pass=ValidateBBS() && pass;
172172
pass=ValidateDH() && pass;

0 commit comments

Comments
 (0)