From Crypto++ Wiki
Jump to: navigation, search

DataDir is a Crypto++ 5.6.3 and earlier patch for Windows and Linux that allows the self tests and benchmarks to run after installation. Crypto++ 5.6.4 and above includes the patch and needs no special actions. Also see Issue 82, Add Debian-style Data Directory patch and Commit a0b078543abdfb5a.

Crypto++ 5.6.3 and earlier hard codes its TestData and TestVectors directories. After performing a make install, the tests and benchmarks no longer run because the data files are not copied during the install, and the cryptest.exe program implicitly searches for them in a different location.

After applying the patch, you will be able to run the validation tests (cryptest.exe v and cryptest.exe tv all) or benchmarks (cryptest.exe b) after installing the library in directories like /usr and /usr/local. Existing behavior is preserved so if you do not specify a location, then the library will continue to search in the present working directory.

The page and patch are called DataDir because a wrapper C++ object was used to abstract away the location of the data directories. The wrapper no longer exists and the library now uses simple preprocessor macro and concatenation. But the name stuck.

Note well: this patch was applied after the release of the Crypto++ 5.6.3 library. You must download and install the patch below if working with 5.6.3 and earlier.


The changes the patch makes can be found in datadir.diff. The essence of the patch is to wrap calls that specify data files in TestData and TestVectors in a DataDir object, and let the DataDir find the data files based on CRYPTOPP_DATA_DIR. CRYPTOPP_DATA_DIR is a preprocessor macro with a string value. (See below on setting the path).

The modified files are:

  • GNUmakefile
  • test.cpp, datatest.cpp
  • bench.cpp, bench2.cpp
  • validat1.cpp, validat2.cpp, validat3.cpp

An example of wrapping is shown below from validat1.cpp.

bool ValidateVMAC()
    cout << "\nVMAC validation suite running...\n";
    return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/vmac.txt");

In config.h, CRYPTOPP_DATA_DIR is set to the empty string, so folks compiling and testing in-place don't have to do anything special. Things "just work" as before. However, someone who wants a different data directory, like a package maintainer, should set CRYPTOPP_DATA_DIR in CXXFLAGS. For example, the following is from

rm -rf "$INSTALL_DIR" > /dev/null 2>&1

export CXXFLAGS="-DNDEBUG -g2 -O2 -DCRYPTOPP_DATA_DIR='\"$INSTALL_DIR/share/cryptopp/\"'"

Notice CRYPTOPP_DATA_DIR uses the actual path to the directory within share/, and not the PREFIX.

Downloads - Patch to update the library to install the self tests and locate the self tests after installation.