1 From 5ea6b3859ebe16ff47856b58262b14463e119c13 Mon Sep 17 00:00:00 2001
2 From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
3 Date: Tue, 19 Apr 2016 22:14:42 +0200
4 Subject: [PATCH] Don't assume cryptopp is system-wide installed
6 The current build system adds "-isystem /usr/include/$(CRYPTOLIB)" to
7 AM_CPPFLAGS, but this is wrong because cryptopp might not be installed
8 in this location. Instead, the build system should simply include
9 <cryptopp/...> or <crypto++/...> and rely on the compiler include
12 The tricky part is that it can be <cryptopp/...> or <crypto++/...>. To
13 solve this, we use a solution similar to the one used in
14 https://github.com/bingmann/crypto-speedtest/blob/master/m4/cryptopp.m4
16 https://github.com/bingmann/crypto-speedtest/blob/master/src/speedtest_cryptopp.cpp:
17 the configure script fills in a variable called
18 CRYPTOLIB_HEADER_PREFIX, and we use that in the C++ code to include
19 the right header file.
21 It is worth mentioning that doing #include
22 <CRYPTOLIB_HEADER_PREFIX/foobar.h> doesn't work, and we have to use an
23 intermediate #define'd constant to overcome this C preprocessor
26 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
27 Submitted upstream at https://github.com/NVIDIA/tegrarcm/pull/2
30 src/Makefile.am | 2 +-
31 src/aes-cmac.cpp | 28 +++++++++++++++++-----------
32 3 files changed, 19 insertions(+), 12 deletions(-)
34 diff --git a/configure.ac b/configure.ac
35 index 943654f..620e158 100644
38 @@ -33,6 +33,7 @@ AC_LINK_IFELSE(
39 [AC_MSG_ERROR([libcrypto++/libcryptopp is not installed.])])]
42 +AC_DEFINE_UNQUOTED([CRYPTOLIB_HEADER_PREFIX], [$CRYPTOLIB], [Location of cryptolib header])
43 LDFLAGS=$SAVED_LDFLAGS
46 diff --git a/src/Makefile.am b/src/Makefile.am
47 index 3dad0e6..35a606f 100644
51 AM_CFLAGS = -Wall -std=c99
52 -AM_CPPFLAGS = -isystem /usr/include/$(CRYPTOLIB) $(LIBUSB_CFLAGS)
53 +AM_CPPFLAGS = $(LIBUSB_CFLAGS)
55 bin_PROGRAMS = tegrarcm
57 diff --git a/src/aes-cmac.cpp b/src/aes-cmac.cpp
58 index 24c89f8..da8be5a 100644
59 --- a/src/aes-cmac.cpp
60 +++ b/src/aes-cmac.cpp
62 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
63 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
71 @@ -40,26 +43,29 @@ using std::string;
75 -#include "cryptlib.h"
76 -using CryptoPP::Exception;
77 +#define CRYPTOPP_INCLUDE_CRYPTLIB <CRYPTOLIB_HEADER_PREFIX/cryptlib.h>
78 +#define CRYPTOPP_INCLUDE_CMAC <CRYPTOLIB_HEADER_PREFIX/cmac.h>
79 +#define CRYPTOPP_INCLUDE_AES <CRYPTOLIB_HEADER_PREFIX/aes.h>
80 +#define CRYPTOPP_INCLUDE_HEX <CRYPTOLIB_HEADER_PREFIX/hex.h>
81 +#define CRYPTOPP_INCLUDE_FILTERS <CRYPTOLIB_HEADER_PREFIX/filters.h>
82 +#define CRYPTOPP_INCLUDE_SECBLOCK <CRYPTOLIB_HEADER_PREFIX/secblock.h>
85 -using CryptoPP::CMAC;
86 +#include CRYPTOPP_INCLUDE_CRYPTLIB
87 +#include CRYPTOPP_INCLUDE_CMAC
88 +#include CRYPTOPP_INCLUDE_AES
89 +#include CRYPTOPP_INCLUDE_HEX
90 +#include CRYPTOPP_INCLUDE_FILTERS
91 +#include CRYPTOPP_INCLUDE_SECBLOCK
94 +using CryptoPP::Exception;
95 +using CryptoPP::CMAC;
99 using CryptoPP::HexEncoder;
100 using CryptoPP::HexDecoder;
102 -#include "filters.h"
103 using CryptoPP::StringSink;
104 using CryptoPP::StringSource;
105 using CryptoPP::HashFilter;
106 using CryptoPP::HashVerificationFilter;
108 -#include "secblock.h"
109 using CryptoPP::SecByteBlock;
111 extern "C" int cmac_hash(const unsigned char *msg, int len, unsigned char *cmac_buf)