Makefile: Add security compiling option (RELRO, SC, and FORTIFY)
[platform/upstream/cryptsetup.git] / configure.ac
1 AC_PREREQ([2.67])
2 AC_INIT([cryptsetup],[1.6.7])
3
4 dnl library version from <major>.<minor>.<release>[-<suffix>]
5 LIBCRYPTSETUP_VERSION=$(echo $PACKAGE_VERSION | cut -f1 -d-)
6 LIBCRYPTSETUP_VERSION_INFO=11:0:7
7
8 AM_SILENT_RULES([yes])
9 AC_CONFIG_SRCDIR(src/cryptsetup.c)
10 AC_CONFIG_MACRO_DIR([m4])
11
12 AC_CONFIG_HEADERS([config.h:config.h.in])
13
14 # We do not want to run test in parallel. Really.
15 # http://lists.gnu.org/archive/html/automake/2013-01/msg00060.html
16
17 # For old automake use this
18 #AM_INIT_AUTOMAKE(dist-xz)
19 AM_INIT_AUTOMAKE([dist-xz 1.12 serial-tests])
20
21 if test "x$prefix" = "xNONE"; then
22         sysconfdir=/etc
23 fi
24 AC_PREFIX_DEFAULT(/usr)
25
26 AC_CANONICAL_HOST
27 AC_USE_SYSTEM_EXTENSIONS
28 AC_PROG_CC
29 AM_PROG_CC_C_O
30 AC_PROG_CPP
31 AC_PROG_INSTALL
32 AC_PROG_MAKE_SET
33 AC_ENABLE_STATIC(no)
34 LT_INIT
35 PKG_PROG_PKG_CONFIG
36
37 AC_HEADER_DIRENT
38 AC_HEADER_STDC
39 AC_CHECK_HEADERS(fcntl.h malloc.h inttypes.h sys/ioctl.h sys/mman.h \
40         sys/sysmacros.h ctype.h unistd.h locale.h byteswap.h endian.h)
41
42 AC_CHECK_HEADERS(uuid/uuid.h,,[AC_MSG_ERROR([You need the uuid library.])])
43 AC_CHECK_HEADER(libdevmapper.h,,[AC_MSG_ERROR([You need the device-mapper library.])])
44
45 saved_LIBS=$LIBS
46 AC_CHECK_LIB(uuid, uuid_clear, ,[AC_MSG_ERROR([You need the uuid library.])])
47 AC_SUBST(UUID_LIBS, $LIBS)
48 LIBS=$saved_LIBS
49
50 AC_SEARCH_LIBS([clock_gettime],[rt posix4])
51 AC_CHECK_FUNCS([posix_memalign clock_gettime])
52
53 if test "x$enable_largefile" = "xno" ; then
54   AC_MSG_ERROR([Building with --disable-largefile is not supported, it can cause data corruption.])
55 fi
56
57 AC_C_CONST
58 AC_C_BIGENDIAN
59 AC_TYPE_OFF_T
60 AC_SYS_LARGEFILE
61 AC_FUNC_FSEEKO
62 AC_PROG_GCC_TRADITIONAL
63 AC_FUNC_STRERROR_R
64
65 dnl ==========================================================================
66
67 AM_GNU_GETTEXT([external],[need-ngettext])
68 AM_GNU_GETTEXT_VERSION([0.15])
69
70 dnl ==========================================================================
71
72 saved_LIBS=$LIBS
73 AC_CHECK_LIB(popt, poptConfigFileToString,,
74         [AC_MSG_ERROR([You need popt 1.7 or newer to compile.])])
75 AC_SUBST(POPT_LIBS, $LIBS)
76 LIBS=$saved_LIBS
77
78 dnl ==========================================================================
79 dnl FIPS extensions (only for RHEL)
80 AC_ARG_ENABLE([fips], AS_HELP_STRING([--enable-fips],[enable FIPS mode restrictions]),
81 [with_fips=$enableval],
82 [with_fips=no])
83
84 if test "x$with_fips" = "xyes"; then
85         AC_DEFINE(ENABLE_FIPS, 1, [Enable FIPS mode restrictions])
86
87         if test "x$enable_static" = "xyes" -o "x$enable_static_cryptsetup" = "xyes" ; then
88                 AC_MSG_ERROR([Static build is not compatible with FIPS.])
89         fi
90 fi
91
92 AC_DEFUN([NO_FIPS], [
93         if test "x$with_fips" = "xyes"; then
94                 AC_MSG_ERROR([This option is not compatible with FIPS.])
95         fi
96 ])
97
98 dnl ==========================================================================
99 dnl pwquality library (cryptsetup CLI only)
100 AC_ARG_ENABLE([pwquality], AS_HELP_STRING([--enable-pwquality],[enable password quality checking]),
101 [with_pwquality=$enableval],
102 [with_pwquality=no])
103
104 if test "x$with_pwquality" = "xyes"; then
105         AC_DEFINE(ENABLE_PWQUALITY, 1, [Enable password quality checking])
106         PKG_CHECK_MODULES([PWQUALITY], [pwquality >= 1.0.0],,
107                 AC_MSG_ERROR([You need pwquality library.]))
108
109         dnl FIXME: this is really hack for now
110         PWQUALITY_STATIC_LIBS="$PWQUALITY_LIBS -lcrack -lz"
111 fi
112
113 dnl ==========================================================================
114 dnl Crypto backend functions
115
116 AC_DEFUN([CONFIGURE_GCRYPT], [
117         if test "x$with_fips" = "xyes"; then
118                 GCRYPT_REQ_VERSION=1.4.5
119         else
120                 GCRYPT_REQ_VERSION=1.1.42
121         fi
122         dnl Check if we can use gcrypt PBKDF2 (1.6.0 supports empty password)
123         AC_ARG_ENABLE([gcrypt-pbkdf2], AS_HELP_STRING([--enable-gcrypt-pbkdf2],[force enable internal gcrypt PBKDF2]),
124                 if test "x$enableval" = "xyes"; then
125                         [use_internal_pbkdf2=0]
126                 else
127                         [use_internal_pbkdf2=1]
128                 fi,
129                 [AM_PATH_LIBGCRYPT([1.6.1], [use_internal_pbkdf2=0], [use_internal_pbkdf2=1])])
130         AM_PATH_LIBGCRYPT($GCRYPT_REQ_VERSION,,[AC_MSG_ERROR([You need the gcrypt library.])])
131
132         AC_MSG_CHECKING([if internal cryptsetup PBKDF2 is compiled-in])
133         if test $use_internal_pbkdf2 = 0; then
134                 AC_MSG_RESULT([no])
135         else
136                 AC_MSG_RESULT([yes])
137                 NO_FIPS([])
138         fi
139
140         if test x$enable_static_cryptsetup = xyes; then
141                 saved_LIBS=$LIBS
142                 LIBS="$saved_LIBS $LIBGCRYPT_LIBS -static"
143                 AC_CHECK_LIB(gcrypt, gcry_check_version,,
144                         AC_MSG_ERROR([Cannot find static gcrypt library.]),
145                         [-lgpg-error])
146                 LIBGCRYPT_STATIC_LIBS="$LIBGCRYPT_LIBS -lgpg-error"
147                 LIBS=$saved_LIBS
148         fi
149
150         CRYPTO_CFLAGS=$LIBGCRYPT_CFLAGS
151         CRYPTO_LIBS=$LIBGCRYPT_LIBS
152         CRYPTO_STATIC_LIBS=$LIBGCRYPT_STATIC_LIBS
153
154         AC_DEFINE_UNQUOTED(GCRYPT_REQ_VERSION, ["$GCRYPT_REQ_VERSION"], [Requested gcrypt version])
155 ])
156
157 AC_DEFUN([CONFIGURE_OPENSSL], [
158         PKG_CHECK_MODULES([OPENSSL], [openssl >= 0.9.8],,
159                 AC_MSG_ERROR([You need openssl library.]))
160         CRYPTO_CFLAGS=$OPENSSL_CFLAGS
161         CRYPTO_LIBS=$OPENSSL_LIBS
162         use_internal_pbkdf2=0
163
164         if test x$enable_static_cryptsetup = xyes; then
165                 saved_PKG_CONFIG=$PKG_CONFIG
166                 PKG_CONFIG="$PKG_CONFIG --static"
167                 PKG_CHECK_MODULES([OPENSSL_STATIC], [openssl])
168                 CRYPTO_STATIC_LIBS=$OPENSSL_STATIC_LIBS
169                 PKG_CONFIG=$saved_PKG_CONFIG
170         fi
171         NO_FIPS([])
172 ])
173
174 AC_DEFUN([CONFIGURE_NSS], [
175         if test x$enable_static_cryptsetup = xyes; then
176                 AC_MSG_ERROR([Static build of cryptsetup is not supported with NSS.])
177         fi
178
179         AC_MSG_WARN([NSS backend does NOT provide backward compatibility (missing ripemd160 hash).])
180
181         PKG_CHECK_MODULES([NSS], [nss],,
182                 AC_MSG_ERROR([You need nss library.]))
183
184         saved_CFLAGS=$CFLAGS
185         CFLAGS="$CFLAGS $NSS_CFLAGS"
186         AC_CHECK_DECLS([NSS_GetVersion], [], [], [#include <nss.h>])
187         CFLAGS=$saved_CFLAGS
188
189         CRYPTO_CFLAGS=$NSS_CFLAGS
190         CRYPTO_LIBS=$NSS_LIBS
191         use_internal_pbkdf2=1
192         NO_FIPS([])
193 ])
194
195 AC_DEFUN([CONFIGURE_KERNEL], [
196         AC_CHECK_HEADERS(linux/if_alg.h,,
197                 [AC_MSG_ERROR([You need Linux kernel headers with userspace crypto interface.])])
198 #       AC_CHECK_DECLS([AF_ALG],,
199 #               [AC_MSG_ERROR([You need Linux kernel with userspace crypto interface.])],
200 #               [#include <sys/socket.h>])
201         use_internal_pbkdf2=1
202         NO_FIPS([])
203 ])
204
205 AC_DEFUN([CONFIGURE_NETTLE], [
206         AC_CHECK_HEADERS(nettle/sha.h,,
207                 [AC_MSG_ERROR([You need Nettle cryptographic library.])])
208
209         saved_LIBS=$LIBS
210         AC_CHECK_LIB(nettle, nettle_pbkdf2_hmac_sha256,,
211                 [AC_MSG_ERROR([You need Nettle library version 2.6 or more recent.])])
212         CRYPTO_LIBS=$LIBS
213         LIBS=$saved_LIBS
214
215         CRYPTO_STATIC_LIBS=$CRYPTO_LIBS
216         use_internal_pbkdf2=0
217         NO_FIPS([])
218 ])
219
220 dnl ==========================================================================
221 saved_LIBS=$LIBS
222
223 AC_ARG_ENABLE([static-cryptsetup],
224         AS_HELP_STRING([--enable-static-cryptsetup],
225         [enable build of static cryptsetup binary]))
226 if test x$enable_static_cryptsetup = xyes; then
227         if test x$enable_static = xno; then
228                 AC_MSG_WARN([Requested static cryptsetup build, enabling static library.])
229                 enable_static=yes
230         fi
231 fi
232 AM_CONDITIONAL(STATIC_TOOLS, test x$enable_static_cryptsetup = xyes)
233
234 AC_ARG_ENABLE(veritysetup,
235         AS_HELP_STRING([--disable-veritysetup],
236         [disable veritysetup support]),[], [enable_veritysetup=yes])
237 AM_CONDITIONAL(VERITYSETUP, test x$enable_veritysetup = xyes)
238
239 AC_ARG_ENABLE([cryptsetup-reencrypt],
240         AS_HELP_STRING([--enable-cryptsetup-reencrypt],
241         [enable cryptsetup-reencrypt tool]))
242 AM_CONDITIONAL(REENCRYPT, test x$enable_cryptsetup_reencrypt = xyes)
243
244 AC_ARG_ENABLE(selinux,
245         AS_HELP_STRING([--disable-selinux],
246         [disable selinux support [default=auto]]),[], [])
247
248 AC_ARG_ENABLE([udev],
249         AS_HELP_STRING([--disable-udev],
250         [disable udev support]),[], enable_udev=yes)
251
252 dnl Try to use pkg-config for devmapper, but fallback to old detection
253 PKG_CHECK_MODULES([DEVMAPPER], [devmapper >= 1.02.03],, [
254         AC_CHECK_LIB(devmapper, dm_task_set_name,,
255                 [AC_MSG_ERROR([You need the device-mapper library.])])
256         AC_CHECK_LIB(devmapper, dm_task_set_message,,
257                 [AC_MSG_ERROR([The device-mapper library on your system is too old.])])
258         DEVMAPPER_LIBS=$LIBS
259 ])
260 LIBS=$saved_LIBS
261
262 LIBS="$LIBS $DEVMAPPER_LIBS"
263 AC_CHECK_DECLS([dm_task_secure_data], [], [], [#include <libdevmapper.h>])
264 AC_CHECK_DECLS([dm_task_retry_remove], [], [], [#include <libdevmapper.h>])
265 AC_CHECK_DECLS([DM_UDEV_DISABLE_DISK_RULES_FLAG], [have_cookie=yes], [have_cookie=no], [#include <libdevmapper.h>])
266 if test "x$enable_udev" = xyes; then
267         if test "x$have_cookie" = xno; then
268                 AC_MSG_WARN([The device-mapper library on your system has no udev support, udev support disabled.])
269         else
270                 AC_DEFINE(USE_UDEV, 1, [Try to use udev synchronisation?])
271         fi
272 fi
273 LIBS=$saved_LIBS
274
275 dnl Crypto backend configuration.
276 AC_ARG_WITH([crypto_backend],
277         AS_HELP_STRING([--with-crypto_backend=BACKEND], [crypto backend (gcrypt/openssl/nss/kernel/nettle) [gcrypt]]),
278         [], with_crypto_backend=gcrypt
279 )
280
281 dnl Kernel crypto API backend needed for benchmark and tcrypt
282 AC_ARG_ENABLE([kernel_crypto], AS_HELP_STRING([--disable-kernel_crypto],
283         [disable kernel userspace crypto (no benchmark and tcrypt)]),
284         [with_kernel_crypto=$enableval],
285         [with_kernel_crypto=yes])
286
287 if test "x$with_kernel_crypto" = "xyes"; then
288         AC_CHECK_HEADERS(linux/if_alg.h,,
289                 [AC_MSG_ERROR([You need Linux kernel headers with userspace crypto interface. (Or use --disable-kernel_crypto.)])])
290         AC_DEFINE(ENABLE_AF_ALG, 1, [Enable using of kernel userspace crypto])
291 fi
292
293 case $with_crypto_backend in
294         gcrypt)  CONFIGURE_GCRYPT([]) ;;
295         openssl) CONFIGURE_OPENSSL([]) ;;
296         nss)     CONFIGURE_NSS([]) ;;
297         kernel)  CONFIGURE_KERNEL([]) ;;
298         nettle)  CONFIGURE_NETTLE([]) ;;
299         *) AC_MSG_ERROR([Unknown crypto backend.]) ;;
300 esac
301 AM_CONDITIONAL(CRYPTO_BACKEND_GCRYPT,  test $with_crypto_backend = gcrypt)
302 AM_CONDITIONAL(CRYPTO_BACKEND_OPENSSL, test $with_crypto_backend = openssl)
303 AM_CONDITIONAL(CRYPTO_BACKEND_NSS,     test $with_crypto_backend = nss)
304 AM_CONDITIONAL(CRYPTO_BACKEND_KERNEL,  test $with_crypto_backend = kernel)
305 AM_CONDITIONAL(CRYPTO_BACKEND_NETTLE,  test $with_crypto_backend = nettle)
306
307 AM_CONDITIONAL(CRYPTO_INTERNAL_PBKDF2, test $use_internal_pbkdf2 = 1)
308 AC_DEFINE_UNQUOTED(USE_INTERNAL_PBKDF2, [$use_internal_pbkdf2], [Use internal PBKDF2])
309
310 dnl Magic for cryptsetup.static build.
311 if test x$enable_static_cryptsetup = xyes; then
312         saved_PKG_CONFIG=$PKG_CONFIG
313         PKG_CONFIG="$PKG_CONFIG --static"
314
315         LIBS="$saved_LIBS -static"
316         AC_CHECK_LIB(popt, poptGetContext,,
317                 AC_MSG_ERROR([Cannot find static popt library.]))
318
319         dnl Try to detect needed device-mapper static libraries, try pkg-config first.
320         LIBS="$saved_LIBS -static"
321         PKG_CHECK_MODULES([DEVMAPPER_STATIC], [devmapper >= 1.02.27],,[
322                 DEVMAPPER_STATIC_LIBS=$DEVMAPPER_LIBS
323                 if test "x$enable_selinux" != xno; then
324                         AC_CHECK_LIB(sepol, sepol_bool_set)
325                         AC_CHECK_LIB(selinux, is_selinux_enabled)
326                         DEVMAPPER_STATIC_LIBS="$DEVMAPPER_STATIC_LIBS $LIBS"
327                 fi
328         ])
329         LIBS="$saved_LIBS $DEVMAPPER_STATIC_LIBS"
330         AC_CHECK_LIB(devmapper, dm_task_set_uuid,,
331                 AC_MSG_ERROR([Cannot link with static device-mapper library.]))
332
333         dnl Try to detect uuid static library.
334         LIBS="$saved_LIBS -static"
335         AC_CHECK_LIB(uuid, uuid_generate,,
336                 AC_MSG_ERROR([Cannot find static uuid library.]))
337
338         LIBS=$saved_LIBS
339         PKG_CONFIG=$saved_PKG_CONFIG
340 fi
341
342 AC_SUBST([DEVMAPPER_LIBS])
343 AC_SUBST([DEVMAPPER_STATIC_LIBS])
344
345 AC_SUBST([PWQUALITY_LIBS])
346 AC_SUBST([PWQUALITY_STATIC_LIBS])
347
348 AC_SUBST([CRYPTO_CFLAGS])
349 AC_SUBST([CRYPTO_LIBS])
350 AC_SUBST([CRYPTO_STATIC_LIBS])
351
352 AC_SUBST([LIBCRYPTSETUP_VERSION])
353 AC_SUBST([LIBCRYPTSETUP_VERSION_INFO])
354
355 dnl ==========================================================================
356 AC_ARG_ENABLE([dev-random], AS_HELP_STRING([--enable-dev-random],
357 [use blocking /dev/random by default for key generator (otherwise use /dev/urandom)]),
358 [default_rng=/dev/random], [default_rng=/dev/urandom])
359 AC_DEFINE_UNQUOTED(DEFAULT_RNG, ["$default_rng"], [default RNG type for key generator])
360
361 dnl ==========================================================================
362 AC_DEFUN([CS_DEFINE],
363         [AC_DEFINE_UNQUOTED(DEFAULT_[]m4_translit([$1], [-a-z], [_A-Z]), [$2], [$3])
364 ])
365
366 AC_DEFUN([CS_STR_WITH], [AC_ARG_WITH([$1],
367         [AS_HELP_STRING(--with-[$1], [default $2 [$3]])],
368         [CS_DEFINE([$1], ["$withval"], [$2])],
369         [CS_DEFINE([$1], ["$3"], [$2])]
370 )])
371
372 AC_DEFUN([CS_NUM_WITH], [AC_ARG_WITH([$1],
373         [AS_HELP_STRING(--with-[$1], [default $2 [$3]])],
374         [CS_DEFINE([$1], [$withval], [$2])],
375         [CS_DEFINE([$1], [$3], [$2])]
376 )])
377
378 dnl ==========================================================================
379 dnl Python bindings
380 AC_ARG_ENABLE([python], AS_HELP_STRING([--enable-python],[enable Python bindings]),
381 [with_python=$enableval],
382 [with_python=no])
383
384 AC_ARG_WITH([python_version],
385         AS_HELP_STRING([--with-python_version=VERSION], [required Python version [2.6]]),
386         [PYTHON_VERSION=$withval], [PYTHON_VERSION=2.6])
387
388 if test "x$with_python" = "xyes"; then
389         AM_PATH_PYTHON([$PYTHON_VERSION])
390
391         if ! test -x "$PYTHON-config" ; then
392             AC_MSG_ERROR([Cannot find python development packages to build bindings])
393         fi
394
395         PYTHON_INCLUDES=$($PYTHON-config --includes)
396         AC_SUBST(PYTHON_INCLUDES)
397
398         PYTHON_LIBS=$($PYTHON-config --libs)
399         AC_SUBST(PYTHON_LIBS)
400 fi
401 AM_CONDITIONAL([PYTHON_CRYPTSETUP], [test "x$with_python" = "xyes"])
402
403 dnl ==========================================================================
404 CS_STR_WITH([plain-hash],   [password hashing function for plain mode], [ripemd160])
405 CS_STR_WITH([plain-cipher], [cipher for plain mode], [aes])
406 CS_STR_WITH([plain-mode],   [cipher mode for plain mode], [cbc-essiv:sha256])
407 CS_NUM_WITH([plain-keybits],[key length in bits for plain mode], [256])
408
409 CS_STR_WITH([luks1-hash],   [hash function for LUKS1 header], [sha1])
410 CS_STR_WITH([luks1-cipher], [cipher for LUKS1], [aes])
411 CS_STR_WITH([luks1-mode],   [cipher mode for LUKS1], [xts-plain64])
412 CS_NUM_WITH([luks1-keybits],[key length in bits for LUKS1], [256])
413 CS_NUM_WITH([luks1-iter-time],[PBKDF2 iteration time for LUKS1 (in ms)], [1000])
414
415 CS_STR_WITH([loopaes-cipher], [cipher for loop-AES mode], [aes])
416 CS_NUM_WITH([loopaes-keybits],[key length in bits for loop-AES mode], [256])
417
418 CS_NUM_WITH([keyfile-size-maxkb],[maximum keyfile size (in KiB)], [8192])
419 CS_NUM_WITH([passphrase-size-max],[maximum keyfile size (in characters)], [512])
420
421 CS_STR_WITH([verity-hash],       [hash function for verity mode], [sha256])
422 CS_NUM_WITH([verity-data-block], [data block size for verity mode], [4096])
423 CS_NUM_WITH([verity-hash-block], [hash block size for verity mode], [4096])
424 CS_NUM_WITH([verity-salt-size],  [salt size for verity mode], [32])
425
426 dnl ==========================================================================
427
428 AC_CONFIG_FILES([ Makefile
429 lib/Makefile
430 lib/libcryptsetup.pc
431 lib/crypto_backend/Makefile
432 lib/luks1/Makefile
433 lib/loopaes/Makefile
434 lib/verity/Makefile
435 lib/tcrypt/Makefile
436 src/Makefile
437 po/Makefile.in
438 man/Makefile
439 tests/Makefile
440 python/Makefile
441 ])
442 AC_OUTPUT