1dnl Aircrack-ng
2dnl
3dnl Copyright (C) 2017 Joseph Benden <joe@benden.us>
4dnl
5dnl Autotool support was written by: Joseph Benden <joe@benden.us>
6dnl
7dnl This program is free software; you can redistribute it and/or modify
8dnl it under the terms of the GNU General Public License as published by
9dnl the Free Software Foundation; either version 2 of the License, or
10dnl (at your option) any later version.
11dnl
12dnl This program is distributed in the hope that it will be useful,
13dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
14dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15dnl GNU General Public License for more details.
16dnl
17dnl You should have received a copy of the GNU General Public License
18dnl along with this program; if not, write to the Free Software
19dnl Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20dnl
21dnl In addition, as a special exception, the copyright holders give
22dnl permission to link the code of portions of this program with the
23dnl OpenSSL library under certain conditions as described in each
24dnl individual source file, and distribute linked combinations
25dnl including the two.
26dnl
27dnl You must obey the GNU General Public License in all respects
28dnl for all of the code used other than OpenSSL.
29dnl
30dnl If you modify file(s) with this exception, you may extend this
31dnl exception to your dnl version of the file(s), but you are not obligated
32dnl to do so.
33dnl
34dnl If you dnl do not wish to do so, delete this exception statement from your
35dnl version.
36dnl
37dnl If you delete this exception statement from all source files in the
38dnl program, then also delete it here.
39
40AC_DEFUN([AIRCRACK_NG_CRYPTO],[
41
42AC_ARG_ENABLE(static-crypto,
43    AS_HELP_STRING([--enable-static-crypto],
44		[Enable statically linked OpenSSL libcrypto.]),
45    [static_crypto=$enableval], [static_crypto=no])
46
47if test "x$static_crypto" != "xno"; then
48	AC_REQUIRE([AX_EXT_HAVE_STATIC_LIB_DETECT])
49	AX_EXT_HAVE_STATIC_LIB(ZLIB, ${DEFAULT_STATIC_LIB_SEARCH_PATHS}, z libz, compress)
50	AX_EXT_HAVE_STATIC_LIB(OPENSSL, ${DEFAULT_STATIC_LIB_SEARCH_PATHS}, crypto libcrypto, HMAC, -lz -ldl)
51else
52	AC_CHECK_LIB([crypto], [OPENSSL_init], [
53		OPENSSL_LIBS="-lcrypto"
54		OPENSSL_LDFLAGS=""
55
56		AC_CHECK_HEADERS([openssl/crypto.h], [
57			OPENSSL_FOUND=yes
58			OPENSSL_INCLUDES=""
59		], [
60			AX_CHECK_OPENSSL([OPENSSL_FOUND=yes],[OPENSSL_FOUND=no])
61		])
62	], [
63		AX_CHECK_OPENSSL([OPENSSL_FOUND=yes],[OPENSSL_FOUND=no])
64	])
65
66	AX_LIB_GCRYPT
67fi
68
69CRYPTO_CFLAGS=
70CRYPTO_INCLUDES=
71CRYPTO_LIBS=
72CRYPTO_LDFLAGS=
73CRYPTO_TYPE=
74
75AC_MSG_CHECKING([for OpenSSL or libgcrypt])
76if test x"$GCRYPT_LIBS" != x; then
77    AC_MSG_RESULT([libgcrypt])
78    CRYPTO_CFLAGS="$GCRYPT_CFLAGS -DUSE_GCRYPT"
79    CRYPTO_INCLUDES=""
80    CRYPTO_LIBS="$GCRYPT_LIBS"
81    CRYPTO_LDFLAGS=""
82    CRYPTO_TYPE=libgcrypt
83elif test "$OPENSSL_FOUND" = yes; then
84    AC_MSG_RESULT([OpenSSL])
85    CRYPTO_INCLUDES="$OPENSSL_INCLUDES"
86    CRYPTO_LIBS="$OPENSSL_LIBS"
87    CRYPTO_LDFLAGS="$OPENSSL_LDFLAGS"
88    CRYPTO_TYPE=openssl
89
90    AC_CHECK_HEADERS([openssl/cmac.h], [
91        AC_DEFINE([HAVE_OPENSSL_CMAC_H], [1], [Define if you have openssl/cmac.h header present.])
92        HAVE_CMAC=yes
93    ], [HAVE_CMAC=no])
94else
95    AC_MSG_ERROR([one of OpenSSL or Gcrypt was not found])
96fi
97
98AC_SUBST(CRYPTO_CFLAGS)
99AC_SUBST(CRYPTO_INCLUDES)
100AC_SUBST(CRYPTO_LIBS)
101AC_SUBST(CRYPTO_LDFLAGS)
102
103AM_CONDITIONAL([LIBGCRYPT], [test "$CRYPTO_TYPE" = libgcrypt])
104AM_CONDITIONAL([STATIC_CRYPTO], [test "$static_crypto" != no])
105])
106