From patchwork Tue Apr 19 20:25:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Petazzoni X-Patchwork-Id: 612298 X-Patchwork-Delegate: swarren@nvidia.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3qqGjV6RBYz9t6l for ; Wed, 20 Apr 2016 06:25:34 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754341AbcDSUZd (ORCPT ); Tue, 19 Apr 2016 16:25:33 -0400 Received: from down.free-electrons.com ([37.187.137.238]:34944 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754219AbcDSUZc (ORCPT ); Tue, 19 Apr 2016 16:25:32 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id 6F6F6219; Tue, 19 Apr 2016 22:25:30 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (LFbn-1-6691-76.w90-120.abo.wanadoo.fr [90.120.129.76]) by mail.free-electrons.com (Postfix) with ESMTPSA id 1E6A1141; Tue, 19 Apr 2016 22:25:20 +0200 (CEST) From: Thomas Petazzoni To: linux-tegra@vger.kernel.org Cc: Thomas Petazzoni Subject: [tegrarcm PATCH] Don't assume cryptopp is system-wide installed Date: Tue, 19 Apr 2016 22:25:17 +0200 Message-Id: <1461097517-21626-1-git-send-email-thomas.petazzoni@free-electrons.com> X-Mailer: git-send-email 2.6.4 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The current build system adds "-isystem /usr/include/$(CRYPTOLIB)" to AM_CPPFLAGS, but this is wrong because cryptopp might not be installed in this location. Instead, the build system should simply include or and rely on the compiler include path. The tricky part is that it can be or . To solve this, we use a solution similar to the one used in https://github.com/bingmann/crypto-speedtest/blob/master/m4/cryptopp.m4 and https://github.com/bingmann/crypto-speedtest/blob/master/src/speedtest_cryptopp.cpp: the configure script fills in a variable called CRYPTOLIB_HEADER_PREFIX, and we use that in the C++ code to include the right header file. It is worth mentioning that doing #include doesn't work, and we have to use an intermediate #define'd constant to overcome this C preprocessor limitation. Signed-off-by: Thomas Petazzoni --- configure.ac | 1 + src/Makefile.am | 2 +- src/aes-cmac.cpp | 28 +++++++++++++++++----------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index 943654f..620e158 100644 --- a/configure.ac +++ b/configure.ac @@ -33,6 +33,7 @@ AC_LINK_IFELSE( [AC_MSG_ERROR([libcrypto++/libcryptopp is not installed.])])] ) AC_SUBST(CRYPTOLIB) +AC_DEFINE_UNQUOTED([CRYPTOLIB_HEADER_PREFIX], [$CRYPTOLIB], [Location of cryptolib header]) LDFLAGS=$SAVED_LDFLAGS AC_LANG(C) diff --git a/src/Makefile.am b/src/Makefile.am index 3dad0e6..35a606f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ AM_CFLAGS = -Wall -std=c99 -AM_CPPFLAGS = -isystem /usr/include/$(CRYPTOLIB) $(LIBUSB_CFLAGS) +AM_CPPFLAGS = $(LIBUSB_CFLAGS) bin_PROGRAMS = tegrarcm tegrarcm_SOURCES = \ diff --git a/src/aes-cmac.cpp b/src/aes-cmac.cpp index 24c89f8..da8be5a 100644 --- a/src/aes-cmac.cpp +++ b/src/aes-cmac.cpp @@ -26,6 +26,9 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "config.h" + #include using std::cout; using std::cerr; @@ -40,26 +43,29 @@ using std::string; #include using std::exit; -#include "cryptlib.h" -using CryptoPP::Exception; +#define CRYPTOPP_INCLUDE_CRYPTLIB +#define CRYPTOPP_INCLUDE_CMAC +#define CRYPTOPP_INCLUDE_AES +#define CRYPTOPP_INCLUDE_HEX +#define CRYPTOPP_INCLUDE_FILTERS +#define CRYPTOPP_INCLUDE_SECBLOCK -#include "cmac.h" -using CryptoPP::CMAC; +#include CRYPTOPP_INCLUDE_CRYPTLIB +#include CRYPTOPP_INCLUDE_CMAC +#include CRYPTOPP_INCLUDE_AES +#include CRYPTOPP_INCLUDE_HEX +#include CRYPTOPP_INCLUDE_FILTERS +#include CRYPTOPP_INCLUDE_SECBLOCK -#include "aes.h" +using CryptoPP::Exception; +using CryptoPP::CMAC; using CryptoPP::AES; - -#include "hex.h" using CryptoPP::HexEncoder; using CryptoPP::HexDecoder; - -#include "filters.h" using CryptoPP::StringSink; using CryptoPP::StringSource; using CryptoPP::HashFilter; using CryptoPP::HashVerificationFilter; - -#include "secblock.h" using CryptoPP::SecByteBlock; extern "C" int cmac_hash(const unsigned char *msg, int len, unsigned char *cmac_buf)