Reputation: 73
I cannot include the hkdf.h from the crypto++ library into my code.
It says cryptopp/hkdf.h not found
. Although I can import other parts from the same library into my code, such as cryptopp/sha.h
I am using the g++
with the -std=c++11
and the -lcryptopp
flags
I looked into the docs and it suggested the -lcryptopp
flag which I am using. This should not be an issue, am I missing something ?
Edit 1:
Compile command :
g++ -std=c++11 mycode.cpp -lcryptopp
Edit 2:
How do I check the version of my crypto++ library ? Download command was:
sudo apt-get install libcrypto++-dev
My OS is Ubuntu 16.04
Upvotes: 2
Views: 676
Reputation: 102366
Cannot include the hkdf.h from the crypto++ library into my code.
It says cryptopp/hkdf.h not found.
HKDF
was added at Crypto++ 5.6.3. Older versions of the library do not have it, like one supplied on Ubuntu 14 or CentOS 5.
It is a header-only implementation using the file hkdf.h
. You can download it and drop it in the Crypto++ installation directory. Maybe something like the following for Crypto++ 5.6.3:
# Crypto++ 5.6.3
wget https://raw.githubusercontent.com/weidai11/cryptopp/217cb1f983c6/hkdf.h
sudo cp hkdf.h /usr/include/cryptopp/
The key derivation functions interface changed at Crypto++ 7.0. More correctly, at Crypto++ 7.0, we added a base class to use as the interface (previously there was none). The base class is KeyDerivationFunction
, and it allowed us to improve self tests for the key derivation function classes. So maybe something like the following for Crypto++ 7.0:
# Crypto++ 7.0
wget https://raw.githubusercontent.com/weidai11/cryptopp/c8d8caf70074/hkdf.h
sudo cp hkdf.h /usr/include/cryptopp/
To summarize:
KeyDerivationFunction
and HKDF.Put another way, if you try to use Crypto++ 7.0 HKDF with Crypto++ 5.6.2, then it will never compile because KeyDerivationFunction
is missing from the library.
This should not be an issue, am I missing something ?
I think your problem is probably dependent on your distro (or whomever is supplying Crypto++). We could say more if you provided details of the distribution and the library version they supply.
To hazard a guess... Debian and Fedora stay up to date with the Crypto++ releases. Or they have for the last several years. So you are probably not using Debian 8, Ubuntu 17, Fedora 22 or their respective variants.
However, you may be using Debian 7 or earlier, Ubuntu 12 or earlier, or Fedora 21 or earlier. In this case I believe you are using Crypto++ 5.6.2.
I believe Gentoo, the BSDs and some others are behind on the release curve. As far as I know, some distros are still providing Crypto++ 5.6.2.
Upvotes: 2
Reputation: 102366
Compile command :
g++ -std=c++11 mycode.cpp -lcryptopp
This does not answer your question. It is just a heads up...
Be careful with g++ -std=c++11 mycode.cpp -lcryptopp
. The library and your program have to be built using mostly the same options. I don't believe Debian uses -std=c++11
, so you should not use it.
The "use mostly the same options" rule applies to all distros and all C++ libraries; and not just Crypto++ on Debian. You will encounter similar problems if you do the same with the PCRE library on Fedora.
You can check the flags Debian is using to build the library at Debian Package Auto-Building | Crypto++. The flags Debian uses are:
-DHAVE_CONFIG_H -I. -Wdate-time -D_FORTIFY_SOURCE=2 -g -O2 \
-fstack-protector-strong -Wformat -Werror=format-security \
-DCRYPTOPP_NO_UNALIGNED_DATA_ACCESS -DNDEBUG -fPIC -DPIC
For your purposes the important flags are -g -O2 -DNDEBUG -fPIC
. Those flags are the ones you should use with your program. -DCRYPTOPP_NO_UNALIGNED_DATA_ACCESS
is applied in the file config.h
so you don't need to pass it on the command line. (Unaligned access was removed recently because it caused too many problems, so you don't even have to worry about -DCRYPTOPP_NO_UNALIGNED_DATA_ACCESS
in the future).
You can use -std=c++11
if you like. However, you have to download and build the library yourself from sources to ensure the same flags are used by the library and your program.
If you build the library yourself then see GNUmakefile | Building the Library on the Crypto++ wiki.
If you build the library yourself then do yourself a favor and remove the distro provided version of the library. Something like sudo apt-get remove --purge libcrypto++ libcrypto++-dev libcrypto++-dbg
. Otherwise you will inadvertently be mixing and matching them.
Upvotes: 1