remove patches
[platform/upstream/libgcrypt.git] / configure.ac
1 # Configure.ac script for Libgcrypt
2 # Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006,
3 #               2007, 2008, 2009, 2011 Free Software Foundation, Inc.
4 # Copyright (C) 2012-2021  g10 Code GmbH
5 #
6 # This file is part of Libgcrypt.
7 #
8 # Libgcrypt is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU Lesser General Public License as
10 # published by the Free Software Foundation; either version 2.1 of
11 # the License, or (at your option) any later version.
12 #
13 # Libgcrypt is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this program; if not, see <http://www.gnu.org/licenses/>.
20
21 # (Process this file with autoconf to produce a configure script.)
22 AC_REVISION($Revision$)
23 AC_PREREQ([2.69])
24 min_automake_version="1.14"
25
26 # To build a release you need to create a tag with the version number
27 # (git tag -s libgcrypt-n.m.k) and run "./autogen.sh --force".  Please
28 # bump the version number immediately after the release and do another
29 # commit and push so that the git magic is able to work.  See below
30 # for the LT versions.
31 m4_define([mym4_package],[libgcrypt])
32 m4_define([mym4_major], [1])
33 m4_define([mym4_minor], [10])
34 m4_define([mym4_micro], [1])
35
36 # Below is m4 magic to extract and compute the git revision number,
37 # the decimalized short revision number, a beta version string and a
38 # flag indicating a development version (mym4_isbeta).  Note that the
39 # m4 processing is done by autoconf and not during the configure run.
40 m4_define([mym4_verslist], m4_split(m4_esyscmd([./autogen.sh --find-version] \
41                            mym4_package mym4_major mym4_minor mym4_micro),[:]))
42 m4_define([mym4_isbeta],       m4_argn(2, mym4_verslist))
43 m4_define([mym4_version],      m4_argn(4, mym4_verslist))
44 m4_define([mym4_revision],     m4_argn(7, mym4_verslist))
45 m4_define([mym4_revision_dec], m4_argn(8, mym4_verslist))
46 m4_esyscmd([echo ]mym4_version[>VERSION])
47 AC_INIT([mym4_package],[mym4_version],[https://bugs.gnupg.org])
48
49 # LT Version numbers, remember to change them just *before* a release.
50 #   (Code changed:                      REVISION++)
51 #   (Interfaces added/removed/changed:  CURRENT++, REVISION=0)
52 #   (Interfaces added:                  AGE++)
53 #   (Interfaces removed:                AGE=0)
54 #
55 #   (Interfaces removed:    CURRENT++, AGE=0, REVISION=0)
56 #   (Interfaces added:      CURRENT++, AGE++, REVISION=0)
57 #   (No interfaces changed:                   REVISION++)
58 LIBGCRYPT_LT_CURRENT=24
59 LIBGCRYPT_LT_AGE=4
60 LIBGCRYPT_LT_REVISION=1
61 ################################################
62
63 AC_SUBST(LIBGCRYPT_LT_CURRENT)
64 AC_SUBST(LIBGCRYPT_LT_AGE)
65 AC_SUBST(LIBGCRYPT_LT_REVISION)
66
67 # If the API is changed in an incompatible way: increment the next counter.
68 #
69 # 1.6: ABI and API change but the change is to most users irrelevant
70 #      and thus the API version number has not been incremented.
71 LIBGCRYPT_CONFIG_API_VERSION=1
72
73 # If you change the required gpg-error version, please remove
74 # unnecessary error code defines in src/gcrypt-int.h.
75 NEED_GPG_ERROR_VERSION=1.27
76
77 AC_CONFIG_AUX_DIR([build-aux])
78 AC_CONFIG_SRCDIR([src/libgcrypt.vers])
79 AM_INIT_AUTOMAKE([serial-tests dist-bzip2])
80 AC_CONFIG_HEADERS([config.h])
81 AC_CONFIG_MACRO_DIR([m4])
82 AC_CONFIG_LIBOBJ_DIR([compat])
83 AC_CANONICAL_HOST
84 AM_MAINTAINER_MODE
85 AM_SILENT_RULES
86
87 AC_ARG_VAR(SYSROOT,[locate config scripts also below that directory])
88
89 AH_TOP([
90 #ifndef _GCRYPT_CONFIG_H_INCLUDED
91 #define _GCRYPT_CONFIG_H_INCLUDED
92
93 /* Enable gpg-error's strerror macro for W32CE.  */
94 #define GPG_ERR_ENABLE_ERRNO_MACROS 1
95 ])
96
97 AH_BOTTOM([
98 #define _GCRYPT_IN_LIBGCRYPT 1
99
100 /* Add .note.gnu.property section for Intel CET in assembler sources
101    when CET is enabled.  */
102 #if defined(__ASSEMBLER__) && defined(__CET__)
103 # include <cet.h>
104 #endif
105
106 /* If the configure check for endianness has been disabled, get it from
107    OS macros.  This is intended for making fat binary builds on OS X.  */
108 #ifdef DISABLED_ENDIAN_CHECK
109 # if defined(__BIG_ENDIAN__)
110 #  define WORDS_BIGENDIAN 1
111 # elif defined(__LITTLE_ENDIAN__)
112 #  undef WORDS_BIGENDIAN
113 # else
114 #  error "No endianness found"
115 # endif
116 #endif /*DISABLED_ENDIAN_CHECK*/
117
118 /* We basically use the original Camellia source.  Make sure the symbols
119    properly prefixed.  */
120 #define CAMELLIA_EXT_SYM_PREFIX _gcry_
121
122 #endif /*_GCRYPT_CONFIG_H_INCLUDED*/
123 ])
124
125 AH_VERBATIM([_REENTRANT],
126 [/* To allow the use of Libgcrypt in multithreaded programs we have to use
127     special features from the library. */
128 #ifndef _REENTRANT
129 # define _REENTRANT 1
130 #endif
131 ])
132
133
134 ######################
135 ##  Basic checks.  ### (we need some results later on (e.g. $GCC)
136 ######################
137
138 AC_PROG_MAKE_SET
139 missing_dir=`cd $ac_aux_dir && pwd`
140 AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
141 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
142 AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir)
143 AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
144 # AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)
145 AC_PROG_CC
146 AC_PROG_CPP
147 AM_PROG_CC_C_O
148 AM_PROG_AS
149 AC_SEARCH_LIBS([strerror],[cposix])
150 AC_PROG_INSTALL
151 AC_PROG_AWK
152
153 AC_USE_SYSTEM_EXTENSIONS
154
155 # Taken from mpfr-4.0.1, then modified for LDADD_FOR_TESTS_KLUDGE
156 dnl Under Linux, make sure that the old dtags are used if LD_LIBRARY_PATH
157 dnl is defined. The issue is that with the new dtags, LD_LIBRARY_PATH has
158 dnl the precedence over the run path, so that if a compatible MPFR library
159 dnl is installed in some directory from $LD_LIBRARY_PATH, then the tested
160 dnl MPFR library will be this library instead of the MPFR library from the
161 dnl build tree. Other OS with the same issue might be added later.
162 dnl
163 dnl References:
164 dnl   https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=859732
165 dnl   http://lists.gnu.org/archive/html/libtool/2017-05/msg00000.html
166 dnl
167 dnl We need to check whether --disable-new-dtags is supported as alternate
168 dnl linkers may be used (e.g., with tcc: CC=tcc LD=tcc).
169 dnl
170 case $host in
171   *-*-linux*)
172     if test -n "$LD_LIBRARY_PATH"; then
173       saved_LDFLAGS="$LDFLAGS"
174       LDADD_FOR_TESTS_KLUDGE="-Wl,--disable-new-dtags"
175       LDFLAGS="$LDFLAGS $LDADD_FOR_TESTS_KLUDGE"
176       AC_MSG_CHECKING(whether --disable-new-dtags is supported by the linker)
177       AC_LINK_IFELSE([AC_LANG_SOURCE([[
178 int main (void) { return 0; }
179       ]])],
180       [AC_MSG_RESULT(yes (use it since LD_LIBRARY_PATH is set))],
181       [AC_MSG_RESULT(no)
182        LDADD_FOR_TESTS_KLUDGE=""
183       ])
184       LDFLAGS="$saved_LDFLAGS"
185     fi
186     ;;
187 esac
188 AC_SUBST([LDADD_FOR_TESTS_KLUDGE])
189
190 VERSION_NUMBER=m4_esyscmd(printf "0x%02x%02x%02x" mym4_major \
191                           mym4_minor mym4_micro)
192 AC_SUBST(VERSION_NUMBER)
193
194 # We need to compile and run a program on the build machine.
195 AX_CC_FOR_BUILD
196
197
198 LT_PREREQ([2.2.6])
199 LT_INIT([win32-dll disable-static])
200 LT_LANG([Windows Resource])
201
202
203 ##########################
204 ## General definitions. ##
205 ##########################
206
207 # Used by libgcrypt-config
208 LIBGCRYPT_CONFIG_LIBS="-lgcrypt"
209 LIBGCRYPT_CONFIG_CFLAGS=""
210 LIBGCRYPT_CONFIG_HOST="$host"
211
212 # Definitions for symmetric ciphers.
213 available_ciphers="arcfour blowfish cast5 des aes twofish serpent rfc2268 seed"
214 available_ciphers="$available_ciphers camellia idea salsa20 gost28147 chacha20"
215 available_ciphers="$available_ciphers sm4"
216 enabled_ciphers=""
217
218 # Definitions for public-key ciphers.
219 available_pubkey_ciphers="dsa elgamal rsa ecc"
220 enabled_pubkey_ciphers=""
221
222 # Definitions for message digests.
223 available_digests="crc gostr3411-94 md2 md4 md5 rmd160 sha1 sha256 sha512"
224 available_digests="$available_digests sha3 tiger whirlpool stribog blake2"
225 available_digests="$available_digests sm3"
226 enabled_digests=""
227
228 # Definitions for kdfs (optional ones)
229 available_kdfs="s2k pkdf2 scrypt"
230 enabled_kdfs=""
231
232 # Definitions for random modules.
233 available_random_modules="getentropy linux egd unix"
234 auto_random_modules="$available_random_modules"
235
236 # Supported thread backends.
237 LIBGCRYPT_THREAD_MODULES=""
238
239 # Other definitions.
240 have_w32_system=no
241 have_w32ce_system=no
242 have_pthread=no
243
244
245 # Setup some stuff depending on host.
246 case "${host}" in
247     *-*-mingw32*)
248       ac_cv_have_dev_random=no
249       have_w32_system=yes
250       case "${host}" in
251         *-mingw32ce*)
252             have_w32ce_system=yes
253             available_random_modules="w32ce"
254             ;;
255         *)
256             available_random_modules="w32"
257             ;;
258       esac
259       AC_DEFINE(USE_ONLY_8DOT3,1,
260                 [set this to limit filenames to the 8.3 format])
261       AC_DEFINE(HAVE_DRIVE_LETTERS,1,
262                 [defined if we must run on a stupid file system])
263       AC_DEFINE(HAVE_DOSISH_SYSTEM,1,
264                 [defined if we run on some of the PCDOS like systems
265                  (DOS, Windoze. OS/2) with special properties like
266                   no file modes])
267       ;;
268
269     i?86-emx-os2 | i?86-*-os2*emx)
270         # OS/2 with the EMX environment
271         ac_cv_have_dev_random=no
272         AC_DEFINE(HAVE_DRIVE_LETTERS)
273         AC_DEFINE(HAVE_DOSISH_SYSTEM)
274         ;;
275
276     i?86-*-msdosdjgpp*)
277         # DOS with the DJGPP environment
278         ac_cv_have_dev_random=no
279         AC_DEFINE(HAVE_DRIVE_LETTERS)
280         AC_DEFINE(HAVE_DOSISH_SYSTEM)
281         ;;
282
283     *-*-hpux*)
284         if test -z "$GCC" ; then
285             CFLAGS="$CFLAGS -Ae -D_HPUX_SOURCE"
286         fi
287         ;;
288     *-dec-osf4*)
289         if test -z "$GCC" ; then
290             # Suppress all warnings
291             # to get rid of the unsigned/signed char mismatch warnings.
292             CFLAGS="$CFLAGS -w"
293         fi
294         ;;
295     m68k-atari-mint)
296         ;;
297     *-apple-darwin*)
298         AC_DEFINE(_DARWIN_C_SOURCE, 1,
299                   Expose all libc features (__DARWIN_C_FULL).)
300         AC_DEFINE(USE_POSIX_SPAWN_FOR_TESTS, 1,
301                   [defined if we use posix_spawn in test program])
302         AC_CHECK_HEADERS(spawn.h)
303         ;;
304     *)
305       ;;
306 esac
307
308 if test "$have_w32_system" = yes; then
309    AC_DEFINE(HAVE_W32_SYSTEM,1, [Defined if we run on a W32 API based system])
310    if test "$have_w32ce_system" = yes; then
311      AC_DEFINE(HAVE_W32CE_SYSTEM,1,[Defined if we run on WindowsCE])
312    fi
313 fi
314 AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
315 AM_CONDITIONAL(HAVE_W32CE_SYSTEM, test "$have_w32ce_system" = yes)
316
317
318
319 # A printable OS Name is sometimes useful.
320 case "${host}" in
321     *-*-mingw32ce*)
322         PRINTABLE_OS_NAME="W32CE"
323         ;;
324
325     *-*-mingw32*)
326         PRINTABLE_OS_NAME="W32"
327         ;;
328
329     i?86-emx-os2 | i?86-*-os2*emx )
330         PRINTABLE_OS_NAME="OS/2"
331         ;;
332
333     i?86-*-msdosdjgpp*)
334         PRINTABLE_OS_NAME="MSDOS/DJGPP"
335         ;;
336
337     *-linux*)
338         PRINTABLE_OS_NAME="GNU/Linux"
339         ;;
340
341     *)
342         PRINTABLE_OS_NAME=`uname -s || echo "Unknown"`
343         ;;
344 esac
345
346 NAME_OF_DEV_RANDOM="/dev/random"
347 NAME_OF_DEV_URANDOM="/dev/urandom"
348
349 AC_ARG_ENABLE(endian-check,
350               AS_HELP_STRING([--disable-endian-check],
351               [disable the endian check and trust the OS provided macros]),
352               endiancheck=$enableval,endiancheck=yes)
353 if test x"$endiancheck" = xyes ; then
354   AC_C_BIGENDIAN
355 else
356   AC_DEFINE(DISABLED_ENDIAN_CHECK,1,[configure did not test for endianness])
357 fi
358
359 AC_CHECK_SIZEOF(unsigned short, 2)
360 AC_CHECK_SIZEOF(unsigned int, 4)
361 AC_CHECK_SIZEOF(unsigned long, 4)
362 AC_CHECK_SIZEOF(unsigned long long, 0)
363 AC_CHECK_SIZEOF(void *, 0)
364
365 AC_TYPE_UINTPTR_T
366
367 if test "$ac_cv_sizeof_unsigned_short" = "0" \
368    || test "$ac_cv_sizeof_unsigned_int" = "0" \
369    || test "$ac_cv_sizeof_unsigned_long" = "0"; then
370     AC_MSG_WARN([Hmmm, something is wrong with the sizes - using defaults]);
371 fi
372
373 # Ensure that we have UINT64_C before we bother to check for uint64_t
374 AC_CACHE_CHECK([for UINT64_C],[gnupg_cv_uint64_c_works],
375    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <inttypes.h>]],
376        [[uint64_t foo=UINT64_C(42);]])],
377      gnupg_cv_uint64_c_works=yes,gnupg_cv_uint64_c_works=no))
378 if test "$gnupg_cv_uint64_c_works" = "yes" ; then
379    AC_CHECK_SIZEOF(uint64_t)
380 fi
381
382 # Do we have any 64-bit data types?
383 if test "$ac_cv_sizeof_unsigned_int" != "8" \
384    && test "$ac_cv_sizeof_unsigned_long" != "8" \
385    && test "$ac_cv_sizeof_unsigned_long_long" != "8" \
386    && test "$ac_cv_sizeof_uint64_t" != "8"; then
387     AC_MSG_ERROR([[
388 ***
389 *** No 64-bit integer type available.
390 *** It is not possible to build Libgcrypt on this platform.
391 ***]])
392 fi
393
394
395 # If not specified otherwise, all available algorithms will be
396 # included.
397 default_ciphers="$available_ciphers"
398 default_pubkey_ciphers="$available_pubkey_ciphers"
399 default_digests="$available_digests"
400 default_kdfs="$available_kdfs"
401 # Blacklist MD2 by default
402 default_digests=`echo $default_digests | sed -e 's/md2//g'`
403
404 # Substitutions to set generated files in a Emacs buffer to read-only.
405 AC_SUBST(emacs_local_vars_begin, ['Local Variables:'])
406 AC_SUBST(emacs_local_vars_read_only, ['buffer-read-only: t'])
407 AC_SUBST(emacs_local_vars_end, ['End:'])
408
409 ############################
410 ## Command line switches. ##
411 ############################
412
413 # Implementation of the --enable-ciphers switch.
414 AC_ARG_ENABLE(ciphers,
415               AS_HELP_STRING([--enable-ciphers=ciphers],
416                              [select the symmetric ciphers to include]),
417               [enabled_ciphers=`echo $enableval | tr ',:' '  ' | tr '[A-Z]' '[a-z]'`],
418               [enabled_ciphers=""])
419 if test "x$enabled_ciphers" = "x" \
420    -o "$enabled_ciphers" = "yes"  \
421    -o "$enabled_ciphers" = "no"; then
422    enabled_ciphers=$default_ciphers
423 fi
424 AC_MSG_CHECKING([which symmetric ciphers to include])
425 for cipher in $enabled_ciphers; do
426     LIST_MEMBER($cipher, $available_ciphers)
427     if test "$found" = "0"; then
428        AC_MSG_ERROR([unsupported cipher "$cipher" specified])
429     fi
430 done
431 AC_MSG_RESULT([$enabled_ciphers])
432
433 # Implementation of the --enable-pubkey-ciphers switch.
434 AC_ARG_ENABLE(pubkey-ciphers,
435               AS_HELP_STRING([--enable-pubkey-ciphers=ciphers],
436                              [select the public-key ciphers to include]),
437               [enabled_pubkey_ciphers=`echo $enableval | tr ',:' '  ' | tr '[A-Z]' '[a-z]'`],
438               [enabled_pubkey_ciphers=""])
439 if test "x$enabled_pubkey_ciphers" = "x" \
440    -o "$enabled_pubkey_ciphers" = "yes"  \
441    -o "$enabled_pubkey_ciphers" = "no"; then
442    enabled_pubkey_ciphers=$default_pubkey_ciphers
443 fi
444 AC_MSG_CHECKING([which public-key ciphers to include])
445 for cipher in $enabled_pubkey_ciphers; do
446     LIST_MEMBER($cipher, $available_pubkey_ciphers)
447     if test "$found" = "0"; then
448        AC_MSG_ERROR([unsupported public-key cipher specified])
449     fi
450 done
451 AC_MSG_RESULT([$enabled_pubkey_ciphers])
452
453 # Implementation of the --enable-digests switch.
454 AC_ARG_ENABLE(digests,
455               AS_HELP_STRING([--enable-digests=digests],
456                              [select the message digests to include]),
457               [enabled_digests=`echo $enableval | tr ',:' '  ' | tr '[A-Z]' '[a-z]'`],
458               [enabled_digests=""])
459 if test "x$enabled_digests" = "x" \
460    -o "$enabled_digests" = "yes"  \
461    -o "$enabled_digests" = "no"; then
462    enabled_digests=$default_digests
463 fi
464 AC_MSG_CHECKING([which message digests to include])
465 for digest in $enabled_digests; do
466     LIST_MEMBER($digest, $available_digests)
467     if test "$found" = "0"; then
468        AC_MSG_ERROR([unsupported message digest specified])
469     fi
470 done
471 AC_MSG_RESULT([$enabled_digests])
472
473 # Implementation of the --enable-kdfs switch.
474 AC_ARG_ENABLE(kdfs,
475       AS_HELP_STRING([--enable-kfds=kdfs],
476                      [select the KDFs to include]),
477       [enabled_kdfs=`echo $enableval | tr ',:' '  ' | tr '[A-Z]' '[a-z]'`],
478       [enabled_kdfs=""])
479 if test "x$enabled_kdfs" = "x" \
480    -o "$enabled_kdfs" = "yes"  \
481    -o "$enabled_kdfs" = "no"; then
482    enabled_kdfs=$default_kdfs
483 fi
484 AC_MSG_CHECKING([which key derivation functions to include])
485 for kdf in $enabled_kdfs; do
486     LIST_MEMBER($kdf, $available_kdfs)
487     if test "$found" = "0"; then
488        AC_MSG_ERROR([unsupported key derivation function specified])
489     fi
490 done
491 AC_MSG_RESULT([$enabled_kdfs])
492
493 # Implementation of the --enable-random switch.
494 AC_ARG_ENABLE(random,
495               AS_HELP_STRING([--enable-random=name],
496                              [select which random number generator to use]),
497               [random=`echo $enableval | tr '[A-Z]' '[a-z]'`],
498               [])
499 if test "x$random" = "x" -o "$random" = "yes" -o "$random" = "no"; then
500     random=default
501 fi
502 AC_MSG_CHECKING([which random module to use])
503 if test "$random" != "default" -a "$random" != "auto"; then
504     LIST_MEMBER($random, $available_random_modules)
505     if test "$found" = "0"; then
506        AC_MSG_ERROR([unsupported random module specified])
507     fi
508 fi
509 AC_MSG_RESULT($random)
510
511 # Implementation of the --disable-dev-random switch.
512 AC_MSG_CHECKING([whether use of /dev/random is requested])
513 AC_ARG_ENABLE(dev-random,
514 [  --disable-dev-random    disable the use of dev random],
515     try_dev_random=$enableval, try_dev_random=yes)
516 AC_MSG_RESULT($try_dev_random)
517
518 # Implementation of the --with-egd-socket switch.
519 AC_ARG_WITH(egd-socket,
520     [  --with-egd-socket=NAME  Use NAME for the EGD socket)],
521             egd_socket_name="$withval", egd_socket_name="" )
522 AC_DEFINE_UNQUOTED(EGD_SOCKET_NAME, "$egd_socket_name",
523                    [Define if you don't want the default EGD socket name.
524                     For details see cipher/rndegd.c])
525
526 # Implementation of the --enable-random-daemon
527 AC_MSG_CHECKING([whether the experimental random daemon is requested])
528 AC_ARG_ENABLE([random-daemon],
529               AS_HELP_STRING([--enable-random-daemon],
530                              [Build the experimental gcryptrnd]),
531               [enable_random_daemon=$enableval],
532               [enable_random_daemon=no])
533 AC_MSG_RESULT($enable_random_daemon)
534 AM_CONDITIONAL(ENABLE_RANDOM_DAEMON, test x$enable_random_daemon = xyes)
535
536
537 # Implementation of --disable-asm.
538 AC_MSG_CHECKING([whether MPI and cipher assembler modules are requested])
539 AC_ARG_ENABLE([asm],
540               AS_HELP_STRING([--disable-asm],
541                              [Disable MPI and cipher assembler modules]),
542               [try_asm_modules=$enableval],
543               [try_asm_modules=yes])
544 AC_MSG_RESULT($try_asm_modules)
545 if test "$try_asm_modules" != yes ; then
546     AC_DEFINE(ASM_DISABLED,1,[Defined if --disable-asm was used to configure])
547 fi
548
549 # Implementation of the --enable-m-guard switch.
550 AC_MSG_CHECKING([whether memory guard is requested])
551 AC_ARG_ENABLE(m-guard,
552               AS_HELP_STRING([--enable-m-guard],
553                              [Enable memory guard facility]),
554               [use_m_guard=$enableval], [use_m_guard=no])
555 AC_MSG_RESULT($use_m_guard)
556 if test "$use_m_guard" = yes ; then
557     AC_DEFINE(M_GUARD,1,[Define to use the (obsolete) malloc guarding feature])
558 fi
559
560 # Implementation of the --enable-large-data-tests switch.
561 AC_MSG_CHECKING([whether to run large data tests])
562 AC_ARG_ENABLE(large-data-tests,
563               AS_HELP_STRING([--enable-large-data-tests],
564                  [Enable the real long ruinning large data tests]),
565               large_data_tests=$enableval,large_data_tests=no)
566 AC_MSG_RESULT($large_data_tests)
567 AC_SUBST(RUN_LARGE_DATA_TESTS, $large_data_tests)
568
569 # Implementation of --enable-force-soft-hwfeatures
570 AC_MSG_CHECKING([whether 'soft' HW feature bits are forced on])
571 AC_ARG_ENABLE([force-soft-hwfeatures],
572               AS_HELP_STRING([--enable-force-soft-hwfeatures],
573                              [Enable forcing 'soft' HW feature bits on]),
574               [force_soft_hwfeatures=$enableval],
575               [force_soft_hwfeatures=no])
576 AC_MSG_RESULT($force_soft_hwfeatures)
577
578
579 # Implementation of the --with-capabilities switch.
580 # Check whether we want to use Linux capabilities
581 AC_MSG_CHECKING([whether use of capabilities is requested])
582 AC_ARG_WITH(capabilities,
583             AS_HELP_STRING([--with-capabilities],
584                            [Use linux capabilities [default=no]]),
585             [use_capabilities="$withval"],[use_capabilities=no])
586 AC_MSG_RESULT($use_capabilities)
587
588 # Implementation of the --enable-hmac-binary-check.
589 AC_MSG_CHECKING([whether a HMAC binary check is requested])
590 AC_ARG_ENABLE(hmac-binary-check,
591               AS_HELP_STRING([--enable-hmac-binary-check],
592                              [Enable library integrity check]),
593               [use_hmac_binary_check="$enableval"],
594               [use_hmac_binary_check=no])
595 AC_MSG_RESULT($use_hmac_binary_check)
596 if test "$use_hmac_binary_check" = no ; then
597     DEF_HMAC_BINARY_CHECK=''
598 else
599     AC_DEFINE(ENABLE_HMAC_BINARY_CHECK,1,
600               [Define to support an HMAC based integrity check])
601     AC_CHECK_TOOL(OBJCOPY, [objcopy])
602     AC_CHECK_TOOL(READELF, [readelf])
603     if test "$use_hmac_binary_check" != yes ; then
604         DEF_HMAC_BINARY_CHECK=-DKEY_FOR_BINARY_CHECK="'\"$use_hmac_binary_check\"'"
605     fi
606 fi
607 AM_CONDITIONAL(USE_HMAC_BINARY_CHECK, test "x$use_hmac_binary_check" != xno)
608 AC_SUBST(DEF_HMAC_BINARY_CHECK)
609
610 # Implementation of the --with-fips-module-version.
611 AC_ARG_WITH(fips-module-version,
612             AS_HELP_STRING([--with-fips-module-version=VERSION],
613                            [Specify the FIPS module version for the build]),
614             fips_module_version="$withval", fips_module_version="" )
615 AC_DEFINE_UNQUOTED(FIPS_MODULE_VERSION, "$fips_module_version",
616                    [Define FIPS module version for certification])
617
618 # Implementation of the --disable-jent-support switch.
619 AC_MSG_CHECKING([whether jitter entropy support is requested])
620 AC_ARG_ENABLE(jent-support,
621               AS_HELP_STRING([--disable-jent-support],
622                         [Disable support for the Jitter entropy collector]),
623               jentsupport=$enableval,jentsupport=yes)
624 AC_MSG_RESULT($jentsupport)
625
626 # Implementation of the --disable-padlock-support switch.
627 AC_MSG_CHECKING([whether padlock support is requested])
628 AC_ARG_ENABLE(padlock-support,
629               AS_HELP_STRING([--disable-padlock-support],
630                         [Disable support for the PadLock Engine of VIA processors]),
631               padlocksupport=$enableval,padlocksupport=yes)
632 AC_MSG_RESULT($padlocksupport)
633
634 # Implementation of the --disable-aesni-support switch.
635 AC_MSG_CHECKING([whether AESNI support is requested])
636 AC_ARG_ENABLE(aesni-support,
637               AS_HELP_STRING([--disable-aesni-support],
638                  [Disable support for the Intel AES-NI instructions]),
639               aesnisupport=$enableval,aesnisupport=yes)
640 AC_MSG_RESULT($aesnisupport)
641
642 # Implementation of the --disable-shaext-support switch.
643 AC_MSG_CHECKING([whether SHAEXT support is requested])
644 AC_ARG_ENABLE(shaext-support,
645               AS_HELP_STRING([--disable-shaext-support],
646                  [Disable support for the Intel SHAEXT instructions]),
647               shaextsupport=$enableval,shaextsupport=yes)
648 AC_MSG_RESULT($shaextsupport)
649
650 # Implementation of the --disable-pclmul-support switch.
651 AC_MSG_CHECKING([whether PCLMUL support is requested])
652 AC_ARG_ENABLE(pclmul-support,
653               AS_HELP_STRING([--disable-pclmul-support],
654                  [Disable support for the Intel PCLMUL instructions]),
655               pclmulsupport=$enableval,pclmulsupport=yes)
656 AC_MSG_RESULT($pclmulsupport)
657
658 # Implementation of the --disable-sse41-support switch.
659 AC_MSG_CHECKING([whether SSE4.1 support is requested])
660 AC_ARG_ENABLE(sse41-support,
661               AS_HELP_STRING([--disable-sse41-support],
662                  [Disable support for the Intel SSE4.1 instructions]),
663               sse41support=$enableval,sse41support=yes)
664 AC_MSG_RESULT($sse41support)
665
666 # Implementation of the --disable-drng-support switch.
667 AC_MSG_CHECKING([whether DRNG support is requested])
668 AC_ARG_ENABLE(drng-support,
669               AS_HELP_STRING([--disable-drng-support],
670                  [Disable support for the Intel DRNG (RDRAND instruction)]),
671               drngsupport=$enableval,drngsupport=yes)
672 AC_MSG_RESULT($drngsupport)
673
674 # Implementation of the --disable-avx-support switch.
675 AC_MSG_CHECKING([whether AVX support is requested])
676 AC_ARG_ENABLE(avx-support,
677               AS_HELP_STRING([--disable-avx-support],
678                  [Disable support for the Intel AVX instructions]),
679               avxsupport=$enableval,avxsupport=yes)
680 AC_MSG_RESULT($avxsupport)
681
682 # Implementation of the --disable-avx2-support switch.
683 AC_MSG_CHECKING([whether AVX2 support is requested])
684 AC_ARG_ENABLE(avx2-support,
685               AS_HELP_STRING([--disable-avx2-support],
686                  [Disable support for the Intel AVX2 instructions]),
687               avx2support=$enableval,avx2support=yes)
688 AC_MSG_RESULT($avx2support)
689
690 # Implementation of the --disable-neon-support switch.
691 AC_MSG_CHECKING([whether NEON support is requested])
692 AC_ARG_ENABLE(neon-support,
693               AS_HELP_STRING([--disable-neon-support],
694                  [Disable support for the ARM NEON instructions]),
695               neonsupport=$enableval,neonsupport=yes)
696 AC_MSG_RESULT($neonsupport)
697
698 # Implementation of the --disable-arm-crypto-support switch.
699 AC_MSG_CHECKING([whether ARMv8 Crypto Extension support is requested])
700 AC_ARG_ENABLE(arm-crypto-support,
701               AS_HELP_STRING([--disable-arm-crypto-support],
702                  [Disable support for the ARMv8 Crypto Extension instructions]),
703               armcryptosupport=$enableval,armcryptosupport=yes)
704 AC_MSG_RESULT($armcryptosupport)
705
706 # Implementation of the --disable-ppc-crypto-support switch.
707 AC_MSG_CHECKING([whether PPC crypto support is requested])
708 AC_ARG_ENABLE(ppc-crypto-support,
709               AS_HELP_STRING([--disable-ppc-crypto-support],
710                  [Disable support for the PPC crypto instructions introduced in POWER 8 (PowerISA 2.07)]),
711               ppccryptosupport=$enableval,ppccryptosupport=yes)
712 AC_MSG_RESULT($ppccryptosupport)
713
714 # Implementation of the --disable-O-flag-munging switch.
715 AC_MSG_CHECKING([whether a -O flag munging is requested])
716 AC_ARG_ENABLE([O-flag-munging],
717               AS_HELP_STRING([--disable-O-flag-munging],
718                  [Disable modification of the cc -O flag]),
719               [enable_o_flag_munging=$enableval],
720               [enable_o_flag_munging=yes])
721 AC_MSG_RESULT($enable_o_flag_munging)
722 AM_CONDITIONAL(ENABLE_O_FLAG_MUNGING, test "$enable_o_flag_munging" = "yes")
723
724 # Implementation of the --disable-instrumentation-munging switch.
725 AC_MSG_CHECKING([whether a instrumentation (-fprofile, -fsanitize) munging is requested])
726 AC_ARG_ENABLE([instrumentation-munging],
727               AS_HELP_STRING([--disable-instrumentation-munging],
728                  [Disable modification of the cc instrumentation options]),
729               [enable_instrumentation_munging=$enableval],
730               [enable_instrumentation_munging=yes])
731 AC_MSG_RESULT($enable_instrumentation_munging)
732 AM_CONDITIONAL(ENABLE_INSTRUMENTATION_MUNGING,
733                test "$enable_instrumentation_munging" = "yes")
734
735 # Implementation of the --disable-amd64-as-feature-detection switch.
736 AC_MSG_CHECKING([whether to enable AMD64 as(1) feature detection])
737 AC_ARG_ENABLE(amd64-as-feature-detection,
738               AS_HELP_STRING([--disable-amd64-as-feature-detection],
739                  [Disable the auto-detection of AMD64 as(1) features]),
740               amd64_as_feature_detection=$enableval,
741               amd64_as_feature_detection=yes)
742 AC_MSG_RESULT($amd64_as_feature_detection)
743
744
745 AC_DEFINE_UNQUOTED(PRINTABLE_OS_NAME, "$PRINTABLE_OS_NAME",
746                    [A human readable text with the name of the OS])
747
748 # For some systems we know that we have ld_version scripts.
749 # Use it then as default.
750 have_ld_version_script=no
751 case "${host}" in
752     *-*-linux*)
753         have_ld_version_script=yes
754         ;;
755     *-*-gnu*)
756         have_ld_version_script=yes
757         ;;
758 esac
759 AC_ARG_ENABLE([ld-version-script],
760               AS_HELP_STRING([--enable-ld-version-script],
761                              [enable/disable use of linker version script.
762                               (default is system dependent)]),
763               [have_ld_version_script=$enableval],
764               [ : ] )
765 AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
766
767 AC_DEFINE_UNQUOTED(NAME_OF_DEV_RANDOM, "$NAME_OF_DEV_RANDOM",
768                    [defined to the name of the strong random device])
769 AC_DEFINE_UNQUOTED(NAME_OF_DEV_URANDOM, "$NAME_OF_DEV_URANDOM",
770                    [defined to the name of the weaker random device])
771
772
773 ###############################
774 #### Checks for libraries. ####
775 ###############################
776
777 #
778 # gpg-error is required.
779 #
780 AM_PATH_GPG_ERROR("$NEED_GPG_ERROR_VERSION")
781 if test "x$GPG_ERROR_LIBS" = "x"; then
782   AC_MSG_ERROR([libgpg-error is needed.
783                 See ftp://ftp.gnupg.org/gcrypt/libgpg-error/ .])
784 fi
785
786 AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_GCRYPT,
787           [The default error source for libgcrypt.])
788
789 #
790 # Check whether the GNU Pth library is available.  We require this
791 # to build the optional gcryptrnd program.
792 #
793 AC_ARG_WITH(pth-prefix,
794             AS_HELP_STRING([--with-pth-prefix=PFX],
795                            [prefix where GNU Pth is installed (optional)]),
796      pth_config_prefix="$withval", pth_config_prefix="")
797 if test x$pth_config_prefix != x ; then
798    PTH_CONFIG="$pth_config_prefix/bin/pth-config"
799 fi
800 if test "$enable_random_daemon" = "yes"; then
801   AC_PATH_PROG(PTH_CONFIG, pth-config, no)
802   if test "$PTH_CONFIG" = "no"; then
803     AC_MSG_WARN([[
804 ***
805 *** To build the Libgcrypt's random number daemon
806 *** we need the support of the GNU Portable Threads Library.
807 *** Download it from ftp://ftp.gnu.org/gnu/pth/
808 *** On a Debian GNU/Linux system you might want to try
809 ***   apt-get install libpth-dev
810 ***]])
811   else
812     GNUPG_PTH_VERSION_CHECK([1.3.7])
813     if test $have_pth = yes; then
814        PTH_CFLAGS=`$PTH_CONFIG --cflags`
815        PTH_LIBS=`$PTH_CONFIG --ldflags`
816        PTH_LIBS="$PTH_LIBS `$PTH_CONFIG --libs --all`"
817        AC_DEFINE(USE_GNU_PTH, 1,
818                 [Defined if the GNU Portable Thread Library should be used])
819        AC_DEFINE(HAVE_PTH, 1,
820                 [Defined if the GNU Pth is available])
821     fi
822   fi
823 fi
824 AC_SUBST(PTH_CFLAGS)
825 AC_SUBST(PTH_LIBS)
826
827 #
828 # Check whether pthreads is available
829 #
830 if test "$have_w32_system" != yes; then
831   AC_CHECK_LIB(pthread,pthread_create,have_pthread=yes)
832   if test "$have_pthread" = yes; then
833     AC_DEFINE(HAVE_PTHREAD, 1 ,[Define if we have pthread.])
834   fi
835 fi
836
837
838 # Solaris needs -lsocket and -lnsl. Unisys system includes
839 # gethostbyname in libsocket but needs libnsl for socket.
840 AC_SEARCH_LIBS(setsockopt, [socket], ,
841         [AC_SEARCH_LIBS(setsockopt, [socket], , , [-lnsl])])
842 AC_SEARCH_LIBS(setsockopt, [nsl])
843
844 ##################################
845 #### Checks for header files. ####
846 ##################################
847
848 AC_CHECK_HEADERS(unistd.h sys/auxv.h sys/random.h)
849
850
851 ##########################################
852 #### Checks for typedefs, structures, ####
853 ####  and compiler characteristics.   ####
854 ##########################################
855
856 AC_C_CONST
857 AC_C_INLINE
858 AC_TYPE_SIZE_T
859 AC_TYPE_PID_T
860
861 AC_CHECK_TYPES([byte, ushort, u16, u32, u64])
862
863 gl_TYPE_SOCKLEN_T
864
865 #
866 # Check for __builtin_bswap32 intrinsic.
867 #
868 AC_CACHE_CHECK(for __builtin_bswap32,
869        [gcry_cv_have_builtin_bswap32],
870        [gcry_cv_have_builtin_bswap32=no
871         AC_LINK_IFELSE([AC_LANG_PROGRAM([],
872           [int x = 0; int y = __builtin_bswap32(x); return y;])],
873           [gcry_cv_have_builtin_bswap32=yes])])
874 if test "$gcry_cv_have_builtin_bswap32" = "yes" ; then
875    AC_DEFINE(HAVE_BUILTIN_BSWAP32,1,
876              [Defined if compiler has '__builtin_bswap32' intrinsic])
877 fi
878
879
880 #
881 # Check for __builtin_bswap64 intrinsic.
882 #
883 AC_CACHE_CHECK(for __builtin_bswap64,
884        [gcry_cv_have_builtin_bswap64],
885        [gcry_cv_have_builtin_bswap64=no
886         AC_LINK_IFELSE([AC_LANG_PROGRAM([],
887           [long long x = 0; long long y = __builtin_bswap64(x); return y;])],
888           [gcry_cv_have_builtin_bswap64=yes])])
889 if test "$gcry_cv_have_builtin_bswap64" = "yes" ; then
890    AC_DEFINE(HAVE_BUILTIN_BSWAP64,1,
891              [Defined if compiler has '__builtin_bswap64' intrinsic])
892 fi
893
894
895 #
896 # Check for __builtin_ctz intrinsic.
897 #
898 AC_CACHE_CHECK(for __builtin_ctz,
899        [gcry_cv_have_builtin_ctz],
900        [gcry_cv_have_builtin_ctz=no
901         AC_LINK_IFELSE([AC_LANG_PROGRAM([],
902           [unsigned int x = 0; int y = __builtin_ctz(x); return y;])],
903           [gcry_cv_have_builtin_ctz=yes])])
904 if test "$gcry_cv_have_builtin_ctz" = "yes" ; then
905    AC_DEFINE(HAVE_BUILTIN_CTZ, 1,
906              [Defined if compiler has '__builtin_ctz' intrinsic])
907 fi
908
909
910 #
911 # Check for __builtin_ctzl intrinsic.
912 #
913 AC_CACHE_CHECK(for __builtin_ctzl,
914        [gcry_cv_have_builtin_ctzl],
915        [gcry_cv_have_builtin_ctzl=no
916         AC_LINK_IFELSE([AC_LANG_PROGRAM([],
917           [unsigned long x = 0; long y = __builtin_ctzl(x); return y;])],
918           [gcry_cv_have_builtin_ctzl=yes])])
919 if test "$gcry_cv_have_builtin_ctzl" = "yes" ; then
920    AC_DEFINE(HAVE_BUILTIN_CTZL, 1,
921              [Defined if compiler has '__builtin_ctzl' intrinsic])
922 fi
923
924
925 #
926 # Check for __builtin_clz intrinsic.
927 #
928 AC_CACHE_CHECK(for __builtin_clz,
929        [gcry_cv_have_builtin_clz],
930        [gcry_cv_have_builtin_clz=no
931         AC_LINK_IFELSE([AC_LANG_PROGRAM([],
932           [unsigned int x = 0; int y = __builtin_clz(x); return y;])],
933           [gcry_cv_have_builtin_clz=yes])])
934 if test "$gcry_cv_have_builtin_clz" = "yes" ; then
935    AC_DEFINE(HAVE_BUILTIN_CLZ, 1,
936              [Defined if compiler has '__builtin_clz' intrinsic])
937 fi
938
939
940 #
941 # Check for __builtin_clzl intrinsic.
942 #
943 AC_CACHE_CHECK(for __builtin_clzl,
944        [gcry_cv_have_builtin_clzl],
945        [gcry_cv_have_builtin_clzl=no
946         AC_LINK_IFELSE([AC_LANG_PROGRAM([],
947           [unsigned long x = 0; long y = __builtin_clzl(x); return y;])],
948           [gcry_cv_have_builtin_clzl=yes])])
949 if test "$gcry_cv_have_builtin_clzl" = "yes" ; then
950    AC_DEFINE(HAVE_BUILTIN_CLZL, 1,
951              [Defined if compiler has '__builtin_clzl' intrinsic])
952 fi
953
954
955 #
956 # Check for __sync_synchronize intrinsic.
957 #
958 AC_CACHE_CHECK(for __sync_synchronize,
959        [gcry_cv_have_sync_synchronize],
960        [gcry_cv_have_sync_synchronize=no
961         AC_LINK_IFELSE([AC_LANG_PROGRAM([],
962           [__sync_synchronize(); return 0;])],
963           [gcry_cv_have_sync_synchronize=yes])])
964 if test "$gcry_cv_have_sync_synchronize" = "yes" ; then
965    AC_DEFINE(HAVE_SYNC_SYNCHRONIZE, 1,
966              [Defined if compiler has '__sync_synchronize' intrinsic])
967 fi
968
969
970 #
971 # Check for VLA support (variable length arrays).
972 #
973 AC_CACHE_CHECK(whether the variable length arrays are supported,
974        [gcry_cv_have_vla],
975        [gcry_cv_have_vla=no
976         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
977           [[void f1(char *, int);
978             char foo(int i) {
979               char b[(i < 0 ? 0 : i) + 1];
980               f1(b, sizeof b); return b[0];}]])],
981           [gcry_cv_have_vla=yes])])
982 if test "$gcry_cv_have_vla" = "yes" ; then
983    AC_DEFINE(HAVE_VLA,1, [Defined if variable length arrays are supported])
984 fi
985
986
987 #
988 # Check for ELF visibility support.
989 #
990 AC_CACHE_CHECK(whether the visibility attribute is supported,
991        gcry_cv_visibility_attribute,
992        [gcry_cv_visibility_attribute=no
993         AC_LANG_CONFTEST([AC_LANG_SOURCE(
994           [[int foo __attribute__ ((visibility ("hidden"))) = 1;
995             int bar __attribute__ ((visibility ("protected"))) = 1;
996           ]])])
997
998         if ${CC-cc} -Werror -S conftest.c -o conftest.s \
999                   1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
1000             if grep '\.hidden.*foo' conftest.s >/dev/null 2>&1 ; then
1001                 if grep '\.protected.*bar' conftest.s >/dev/null 2>&1; then
1002                     gcry_cv_visibility_attribute=yes
1003                 fi
1004             fi
1005         fi
1006        ])
1007 if test "$gcry_cv_visibility_attribute" = "yes"; then
1008     AC_CACHE_CHECK(for broken visibility attribute,
1009        gcry_cv_broken_visibility_attribute,
1010        [gcry_cv_broken_visibility_attribute=yes
1011         AC_LANG_CONFTEST([AC_LANG_SOURCE(
1012           [[int foo (int x);
1013             int bar (int x) __asm__ ("foo")
1014                             __attribute__ ((visibility ("hidden")));
1015             int bar (int x) { return x; }
1016           ]])])
1017
1018         if ${CC-cc} -Werror -S conftest.c -o conftest.s \
1019                   1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
1020            if grep '\.hidden@<:@        _@:>@foo' conftest.s >/dev/null 2>&1;
1021             then
1022                gcry_cv_broken_visibility_attribute=no
1023            fi
1024         fi
1025        ])
1026 fi
1027 if test "$gcry_cv_visibility_attribute" = "yes"; then
1028     AC_CACHE_CHECK(for broken alias attribute,
1029        gcry_cv_broken_alias_attribute,
1030        [gcry_cv_broken_alias_attribute=yes
1031         AC_LANG_CONFTEST([AC_LANG_SOURCE(
1032           [[extern int foo (int x) __asm ("xyzzy");
1033             int bar (int x) { return x; }
1034             extern __typeof (bar) foo __attribute ((weak, alias ("bar")));
1035             extern int dfoo;
1036             extern __typeof (dfoo) dfoo __asm ("abccb");
1037             int dfoo = 1;
1038           ]])])
1039
1040         if ${CC-cc} -Werror -S conftest.c -o conftest.s \
1041                   1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
1042            if grep 'xyzzy' conftest.s >/dev/null 2>&1 && \
1043               grep 'abccb' conftest.s >/dev/null 2>&1; then
1044               gcry_cv_broken_alias_attribute=no
1045            fi
1046         fi
1047         ])
1048 fi
1049 if test "$gcry_cv_visibility_attribute" = "yes"; then
1050     AC_CACHE_CHECK(if gcc supports -fvisibility=hidden,
1051        gcry_cv_gcc_has_f_visibility,
1052        [gcry_cv_gcc_has_f_visibility=no
1053         _gcc_cflags_save=$CFLAGS
1054         CFLAGS="-fvisibility=hidden"
1055         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
1056                           gcry_cv_gcc_has_f_visibility=yes)
1057         CFLAGS=$_gcc_cflags_save;
1058        ])
1059 fi
1060 if test "$gcry_cv_visibility_attribute" = "yes" \
1061    && test "$gcry_cv_broken_visibility_attribute" != "yes" \
1062    && test "$gcry_cv_broken_alias_attribute" != "yes" \
1063    && test "$gcry_cv_gcc_has_f_visibility" = "yes"
1064  then
1065    AC_DEFINE(GCRY_USE_VISIBILITY, 1,
1066                [Define to use the GNU C visibility attribute.])
1067    CFLAGS="$CFLAGS -fvisibility=hidden"
1068 fi
1069
1070
1071 # Following attribute tests depend on warnings to cause compile to fail,
1072 # so set -Werror temporarily.
1073 _gcc_cflags_save=$CFLAGS
1074 CFLAGS="$CFLAGS -Werror"
1075
1076
1077 #
1078 # Check whether the compiler supports the GCC style aligned attribute
1079 #
1080 AC_CACHE_CHECK([whether the GCC style aligned attribute is supported],
1081        [gcry_cv_gcc_attribute_aligned],
1082        [gcry_cv_gcc_attribute_aligned=no
1083         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1084           [[struct { int a; } foo __attribute__ ((aligned (16)));]])],
1085           [gcry_cv_gcc_attribute_aligned=yes])])
1086 if test "$gcry_cv_gcc_attribute_aligned" = "yes" ; then
1087    AC_DEFINE(HAVE_GCC_ATTRIBUTE_ALIGNED,1,
1088      [Defined if a GCC style "__attribute__ ((aligned (n))" is supported])
1089 fi
1090
1091
1092 #
1093 # Check whether the compiler supports the GCC style packed attribute
1094 #
1095 AC_CACHE_CHECK([whether the GCC style packed attribute is supported],
1096        [gcry_cv_gcc_attribute_packed],
1097        [gcry_cv_gcc_attribute_packed=no
1098         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1099           [[struct foolong_s { long b; } __attribute__ ((packed));
1100             struct foo_s { char a; struct foolong_s b; }
1101               __attribute__ ((packed));
1102             enum bar {
1103               FOO = 1 / (sizeof(struct foo_s) == (sizeof(char) + sizeof(long))),
1104             };]])],
1105           [gcry_cv_gcc_attribute_packed=yes])])
1106 if test "$gcry_cv_gcc_attribute_packed" = "yes" ; then
1107    AC_DEFINE(HAVE_GCC_ATTRIBUTE_PACKED,1,
1108      [Defined if a GCC style "__attribute__ ((packed))" is supported])
1109 fi
1110
1111
1112 #
1113 # Check whether the compiler supports the GCC style may_alias attribute
1114 #
1115 AC_CACHE_CHECK([whether the GCC style may_alias attribute is supported],
1116        [gcry_cv_gcc_attribute_may_alias],
1117        [gcry_cv_gcc_attribute_may_alias=no
1118         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1119           [[typedef struct foo_s { int a; }
1120             __attribute__ ((may_alias)) foo_t;]])],
1121           [gcry_cv_gcc_attribute_may_alias=yes])])
1122 if test "$gcry_cv_gcc_attribute_may_alias" = "yes" ; then
1123    AC_DEFINE(HAVE_GCC_ATTRIBUTE_MAY_ALIAS,1,
1124      [Defined if a GCC style "__attribute__ ((may_alias))" is supported])
1125 fi
1126
1127
1128 # Restore flags.
1129 CFLAGS=$_gcc_cflags_save;
1130
1131
1132 #
1133 # Check whether the compiler supports 'asm' or '__asm__' keyword for
1134 # assembler blocks.
1135 #
1136 AC_CACHE_CHECK([whether 'asm' assembler keyword is supported],
1137        [gcry_cv_have_asm],
1138        [gcry_cv_have_asm=no
1139         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1140           [[void a(void) { asm("":::"memory"); }]])],
1141           [gcry_cv_have_asm=yes])])
1142 AC_CACHE_CHECK([whether '__asm__' assembler keyword is supported],
1143        [gcry_cv_have___asm__],
1144        [gcry_cv_have___asm__=no
1145         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1146           [[void a(void) { __asm__("":::"memory"); }]])],
1147           [gcry_cv_have___asm__=yes])])
1148 if test "$gcry_cv_have_asm" = "no" ; then
1149    if test "$gcry_cv_have___asm__" = "yes" ; then
1150       AC_DEFINE(asm,__asm__,
1151         [Define to supported assembler block keyword, if plain 'asm' was not
1152          supported])
1153    fi
1154 fi
1155
1156
1157 #
1158 # Check whether the compiler supports inline assembly memory barrier.
1159 #
1160 if test "$gcry_cv_have_asm" = "no" ; then
1161    if test "$gcry_cv_have___asm__" = "yes" ; then
1162       AC_CACHE_CHECK([whether inline assembly memory barrier is supported],
1163           [gcry_cv_have_asm_volatile_memory],
1164           [gcry_cv_have_asm_volatile_memory=no
1165            AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1166              [[void a(int x)
1167                {
1168                  __asm__ volatile("":::"memory");
1169                  __asm__ volatile("":"+r"(x)::"memory");
1170                }]])],
1171              [gcry_cv_have_asm_volatile_memory=yes])])
1172    fi
1173 else
1174    AC_CACHE_CHECK([whether inline assembly memory barrier is supported],
1175        [gcry_cv_have_asm_volatile_memory],
1176        [gcry_cv_have_asm_volatile_memory=no
1177         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1178           [[void a(int x)
1179             {
1180               asm volatile("":::"memory");
1181               asm volatile("":"+r"(x)::"memory"); }]])],
1182           [gcry_cv_have_asm_volatile_memory=yes])])
1183 fi
1184 if test "$gcry_cv_have_asm_volatile_memory" = "yes" ; then
1185    AC_DEFINE(HAVE_GCC_ASM_VOLATILE_MEMORY,1,
1186      [Define if inline asm memory barrier is supported])
1187 fi
1188
1189
1190 #
1191 # Check whether GCC assembler supports features needed for our ARM
1192 # implementations.  This needs to be done before setting up the
1193 # assembler stuff.
1194 #
1195 AC_CACHE_CHECK([whether GCC assembler is compatible for ARM assembly implementations],
1196        [gcry_cv_gcc_arm_platform_as_ok],
1197        [if test "$try_asm_modules" != "yes" ; then
1198           gcry_cv_gcc_arm_platform_as_ok="n/a"
1199         else
1200           gcry_cv_gcc_arm_platform_as_ok=no
1201           AC_LINK_IFELSE([AC_LANG_PROGRAM(
1202             [[__asm__(
1203                 /* Test if assembler supports UAL syntax.  */
1204                 ".syntax unified\n\t"
1205                 ".arm\n\t" /* our assembly code is in ARM mode  */
1206                 ".text\n\t"
1207                 /* Following causes error if assembler ignored '.syntax unified'.  */
1208                 "asmfunc:\n\t"
1209                 "add %r0, %r0, %r4, ror #12;\n\t"
1210
1211                 /* Test if '.type' and '.size' are supported.  */
1212                 ".size asmfunc,.-asmfunc;\n\t"
1213                 ".type asmfunc,%function;\n\t"
1214               );]], [ asmfunc(); ] )],
1215             [gcry_cv_gcc_arm_platform_as_ok=yes])
1216         fi])
1217 if test "$gcry_cv_gcc_arm_platform_as_ok" = "yes" ; then
1218    AC_DEFINE(HAVE_COMPATIBLE_GCC_ARM_PLATFORM_AS,1,
1219      [Defined if underlying assembler is compatible with ARM assembly implementations])
1220 fi
1221
1222
1223 #
1224 # Check whether GCC assembler supports features needed for our ARMv8/Aarch64
1225 # implementations.  This needs to be done before setting up the
1226 # assembler stuff.
1227 #
1228 AC_CACHE_CHECK([whether GCC assembler is compatible for ARMv8/Aarch64 assembly implementations],
1229        [gcry_cv_gcc_aarch64_platform_as_ok],
1230        [if test "$try_asm_modules" != "yes" ; then
1231           gcry_cv_gcc_aarch64_platform_as_ok="n/a"
1232         else
1233           gcry_cv_gcc_aarch64_platform_as_ok=no
1234           AC_LINK_IFELSE([AC_LANG_PROGRAM(
1235             [[__asm__(
1236                 ".text\n\t"
1237                 "asmfunc:\n\t"
1238                 "eor x0, x0, x30, ror #12;\n\t"
1239                 "add x0, x0, x30, asr #12;\n\t"
1240                 "eor v0.16b, v0.16b, v31.16b;\n\t"
1241               );]], [ asmfunc(); ] )],
1242             [gcry_cv_gcc_aarch64_platform_as_ok=yes])
1243         fi])
1244 if test "$gcry_cv_gcc_aarch64_platform_as_ok" = "yes" ; then
1245    AC_DEFINE(HAVE_COMPATIBLE_GCC_AARCH64_PLATFORM_AS,1,
1246      [Defined if underlying assembler is compatible with ARMv8/Aarch64 assembly implementations])
1247 fi
1248
1249 #
1250 # Check whether GCC assembler supports for CFI directives.
1251 #
1252 AC_CACHE_CHECK([whether GCC assembler supports for CFI directives],
1253        [gcry_cv_gcc_asm_cfi_directives],
1254        [gcry_cv_gcc_asm_cfi_directives=no
1255         AC_LINK_IFELSE([AC_LANG_PROGRAM(
1256           [[__asm__(
1257                 ".text\n\t"
1258                 "ac_test:\n\t"
1259                 ".cfi_startproc\n\t"
1260                 ".cfi_remember_state\n\t"
1261                 ".cfi_adjust_cfa_offset 8\n\t"
1262                 ".cfi_rel_offset 0, 8\n\t"
1263                 ".cfi_def_cfa_register 1\n\t"
1264                 ".cfi_register 2, 3\n\t"
1265                 ".cfi_restore 2\n\t"
1266                 ".cfi_escape 0x0f, 0x02, 0x11, 0x00\n\t"
1267                 ".cfi_restore_state\n\t"
1268                 ".long 0\n\t"
1269                 ".cfi_endproc\n\t"
1270             );]])],
1271           [gcry_cv_gcc_asm_cfi_directives=yes])])
1272 if test "$gcry_cv_gcc_asm_cfi_directives" = "yes" ; then
1273    AC_DEFINE(HAVE_GCC_ASM_CFI_DIRECTIVES,1,
1274              [Defined if underlying assembler supports for CFI directives])
1275 fi
1276
1277
1278 #
1279 # Check whether GCC assembler supports for ELF directives.
1280 #
1281 AC_CACHE_CHECK([whether GCC assembler supports for ELF directives],
1282        [gcry_cv_gcc_asm_elf_directives],
1283        [gcry_cv_gcc_asm_elf_directives=no
1284         AC_LINK_IFELSE([AC_LANG_PROGRAM(
1285           [[__asm__(
1286                 /* Test if ELF directives '.type' and '.size' are supported. */
1287                 ".text\n\t"
1288                 "asmfunc:\n\t"
1289                 ".size asmfunc,.-asmfunc;\n\t"
1290                 ".type asmfunc,STT_FUNC;\n\t"
1291             );]])],
1292           [gcry_cv_gcc_asm_elf_directives=yes])])
1293 if test "$gcry_cv_gcc_asm_elf_directives" = "yes" ; then
1294    AC_DEFINE(HAVE_GCC_ASM_ELF_DIRECTIVES,1,
1295              [Defined if underlying assembler supports for ELF directives])
1296 fi
1297
1298
1299 #
1300 # Check whether underscores in symbols are required.  This needs to be
1301 # done before setting up the assembler stuff.
1302 #
1303 GNUPG_SYS_SYMBOL_UNDERSCORE()
1304
1305
1306 #################################
1307 ####                         ####
1308 #### Setup assembler stuff.  ####
1309 #### Define mpi_cpu_arch.    ####
1310 ####                         ####
1311 #################################
1312 AC_ARG_ENABLE(mpi-path,
1313               AS_HELP_STRING([--enable-mpi-path=EXTRA_PATH],
1314               [prepend EXTRA_PATH to list of CPU specific optimizations]),
1315               mpi_extra_path="$enableval",mpi_extra_path="")
1316 AC_MSG_CHECKING(architecture and mpi assembler functions)
1317 if test -f $srcdir/mpi/config.links ; then
1318     . $srcdir/mpi/config.links
1319     AC_CONFIG_LINKS("$mpi_ln_list")
1320     ac_cv_mpi_sflags="$mpi_sflags"
1321     AC_MSG_RESULT($mpi_cpu_arch)
1322 else
1323     AC_MSG_RESULT(failed)
1324     AC_MSG_ERROR([mpi/config.links missing!])
1325 fi
1326 MPI_SFLAGS="$ac_cv_mpi_sflags"
1327 AC_SUBST(MPI_SFLAGS)
1328
1329 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_ADD1, test "$mpi_mod_asm_mpih_add1" = yes)
1330 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_SUB1, test "$mpi_mod_asm_mpih_sub1" = yes)
1331 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_MUL1, test "$mpi_mod_asm_mpih_mul1" = yes)
1332 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_MUL2, test "$mpi_mod_asm_mpih_mul2" = yes)
1333 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_MUL3, test "$mpi_mod_asm_mpih_mul3" = yes)
1334 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_LSHIFT, test "$mpi_mod_asm_mpih_lshift" = yes)
1335 AM_CONDITIONAL(MPI_MOD_ASM_MPIH_RSHIFT, test "$mpi_mod_asm_mpih_rshift" = yes)
1336 AM_CONDITIONAL(MPI_MOD_ASM_UDIV, test "$mpi_mod_asm_udiv" = yes)
1337 AM_CONDITIONAL(MPI_MOD_ASM_UDIV_QRNND, test "$mpi_mod_asm_udiv_qrnnd" = yes)
1338 AM_CONDITIONAL(MPI_MOD_C_MPIH_ADD1, test "$mpi_mod_c_mpih_add1" = yes)
1339 AM_CONDITIONAL(MPI_MOD_C_MPIH_SUB1, test "$mpi_mod_c_mpih_sub1" = yes)
1340 AM_CONDITIONAL(MPI_MOD_C_MPIH_MUL1, test "$mpi_mod_c_mpih_mul1" = yes)
1341 AM_CONDITIONAL(MPI_MOD_C_MPIH_MUL2, test "$mpi_mod_c_mpih_mul2" = yes)
1342 AM_CONDITIONAL(MPI_MOD_C_MPIH_MUL3, test "$mpi_mod_c_mpih_mul3" = yes)
1343 AM_CONDITIONAL(MPI_MOD_C_MPIH_LSHIFT, test "$mpi_mod_c_mpih_lshift" = yes)
1344 AM_CONDITIONAL(MPI_MOD_C_MPIH_RSHIFT, test "$mpi_mod_c_mpih_rshift" = yes)
1345 AM_CONDITIONAL(MPI_MOD_C_UDIV, test "$mpi_mod_c_udiv" = yes)
1346 AM_CONDITIONAL(MPI_MOD_C_UDIV_QRNND, test "$mpi_mod_c_udiv_qrnnd" = yes)
1347
1348 # Reset non applicable feature flags.
1349 if test "$mpi_cpu_arch" != "x86" ; then
1350    aesnisupport="n/a"
1351    shaextsupport="n/a"
1352    pclmulsupport="n/a"
1353    sse41support="n/a"
1354    avxsupport="n/a"
1355    avx2support="n/a"
1356    padlocksupport="n/a"
1357    drngsupport="n/a"
1358 fi
1359
1360 if test "$mpi_cpu_arch" != "arm" ; then
1361    if test "$mpi_cpu_arch" != "aarch64" ; then
1362      neonsupport="n/a"
1363      armcryptosupport="n/a"
1364    fi
1365 fi
1366
1367 if test "$mpi_cpu_arch" != "ppc"; then
1368    ppccryptosupport="n/a"
1369 fi
1370
1371 #############################################
1372 ####                                     ####
1373 #### Platform specific compiler checks.  ####
1374 ####                                     ####
1375 #############################################
1376
1377
1378 # Following tests depend on warnings to cause compile to fail, so set -Werror
1379 # temporarily.
1380 _gcc_cflags_save=$CFLAGS
1381 CFLAGS="$CFLAGS -Werror"
1382
1383
1384 #
1385 # Check whether compiler supports 'ms_abi' function attribute.
1386 #
1387 AC_CACHE_CHECK([whether compiler supports 'ms_abi' function attribute],
1388        [gcry_cv_gcc_attribute_ms_abi],
1389        [gcry_cv_gcc_attribute_ms_abi=no
1390         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1391           [[int __attribute__ ((ms_abi)) proto(int);]])],
1392           [gcry_cv_gcc_attribute_ms_abi=yes])])
1393 if test "$gcry_cv_gcc_attribute_ms_abi" = "yes" ; then
1394    AC_DEFINE(HAVE_GCC_ATTRIBUTE_MS_ABI,1,
1395      [Defined if compiler supports "__attribute__ ((ms_abi))" function attribute])
1396 fi
1397
1398
1399 #
1400 # Check whether compiler supports 'sysv_abi' function attribute.
1401 #
1402 AC_CACHE_CHECK([whether compiler supports 'sysv_abi' function attribute],
1403        [gcry_cv_gcc_attribute_sysv_abi],
1404        [gcry_cv_gcc_attribute_sysv_abi=no
1405         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1406           [[int __attribute__ ((sysv_abi)) proto(int);]])],
1407           [gcry_cv_gcc_attribute_sysv_abi=yes])])
1408 if test "$gcry_cv_gcc_attribute_sysv_abi" = "yes" ; then
1409    AC_DEFINE(HAVE_GCC_ATTRIBUTE_SYSV_ABI,1,
1410      [Defined if compiler supports "__attribute__ ((sysv_abi))" function attribute])
1411 fi
1412
1413
1414 #
1415 # Check whether default calling convention is 'ms_abi'.
1416 #
1417 if test "$gcry_cv_gcc_attribute_ms_abi" = "yes" ; then
1418    AC_CACHE_CHECK([whether default calling convention is 'ms_abi'],
1419           [gcry_cv_gcc_default_abi_is_ms_abi],
1420           [gcry_cv_gcc_default_abi_is_ms_abi=no
1421            AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1422              [[void *test(void) {
1423                  void *(*def_func)(void) = test;
1424                  void *__attribute__((ms_abi))(*msabi_func)(void);
1425                  /* warning on SysV abi targets, passes on Windows based targets */
1426                  msabi_func = def_func;
1427                  return msabi_func;
1428              }]])],
1429              [gcry_cv_gcc_default_abi_is_ms_abi=yes])])
1430    if test "$gcry_cv_gcc_default_abi_is_ms_abi" = "yes" ; then
1431       AC_DEFINE(HAVE_GCC_DEFAULT_ABI_IS_MS_ABI,1,
1432         [Defined if default calling convention is 'ms_abi'])
1433    fi
1434 fi
1435
1436
1437 #
1438 # Check whether default calling convention is 'sysv_abi'.
1439 #
1440 if test "$gcry_cv_gcc_attribute_sysv_abi" = "yes" ; then
1441    AC_CACHE_CHECK([whether default calling convention is 'sysv_abi'],
1442           [gcry_cv_gcc_default_abi_is_sysv_abi],
1443           [gcry_cv_gcc_default_abi_is_sysv_abi=no
1444            AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1445              [[void *test(void) {
1446                  void *(*def_func)(void) = test;
1447                  void *__attribute__((sysv_abi))(*sysvabi_func)(void);
1448                  /* warning on MS ABI targets, passes on SysV ABI targets */
1449                  sysvabi_func = def_func;
1450                  return sysvabi_func;
1451              }]])],
1452              [gcry_cv_gcc_default_abi_is_sysv_abi=yes])])
1453    if test "$gcry_cv_gcc_default_abi_is_sysv_abi" = "yes" ; then
1454       AC_DEFINE(HAVE_GCC_DEFAULT_ABI_IS_SYSV_ABI,1,
1455         [Defined if default calling convention is 'sysv_abi'])
1456    fi
1457 fi
1458
1459
1460 # Restore flags.
1461 CFLAGS=$_gcc_cflags_save;
1462
1463
1464 #
1465 # Check whether GCC inline assembler supports SSSE3 instructions
1466 # This is required for the AES-NI instructions.
1467 #
1468 AC_CACHE_CHECK([whether GCC inline assembler supports SSSE3 instructions],
1469        [gcry_cv_gcc_inline_asm_ssse3],
1470        [if test "$mpi_cpu_arch" != "x86" ||
1471            test "$try_asm_modules" != "yes" ; then
1472           gcry_cv_gcc_inline_asm_ssse3="n/a"
1473         else
1474           gcry_cv_gcc_inline_asm_ssse3=no
1475           AC_LINK_IFELSE([AC_LANG_PROGRAM(
1476           [[static unsigned char be_mask[16] __attribute__ ((aligned (16))) =
1477               { 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
1478             void a(void) {
1479               __asm__("pshufb %[mask], %%xmm2\n\t"::[mask]"m"(*be_mask):);
1480             }]], [ a(); ] )],
1481           [gcry_cv_gcc_inline_asm_ssse3=yes])
1482         fi])
1483 if test "$gcry_cv_gcc_inline_asm_ssse3" = "yes" ; then
1484    AC_DEFINE(HAVE_GCC_INLINE_ASM_SSSE3,1,
1485      [Defined if inline assembler supports SSSE3 instructions])
1486 fi
1487
1488
1489 #
1490 # Check whether GCC inline assembler supports PCLMUL instructions.
1491 #
1492 AC_CACHE_CHECK([whether GCC inline assembler supports PCLMUL instructions],
1493        [gcry_cv_gcc_inline_asm_pclmul],
1494        [if test "$mpi_cpu_arch" != "x86" ||
1495            test "$try_asm_modules" != "yes" ; then
1496           gcry_cv_gcc_inline_asm_pclmul="n/a"
1497         else
1498           gcry_cv_gcc_inline_asm_pclmul=no
1499           AC_LINK_IFELSE([AC_LANG_PROGRAM(
1500           [[void a(void) {
1501               __asm__("pclmulqdq \$0, %%xmm1, %%xmm3\n\t":::"cc");
1502             }]], [ a(); ] )],
1503           [gcry_cv_gcc_inline_asm_pclmul=yes])
1504         fi])
1505 if test "$gcry_cv_gcc_inline_asm_pclmul" = "yes" ; then
1506    AC_DEFINE(HAVE_GCC_INLINE_ASM_PCLMUL,1,
1507      [Defined if inline assembler supports PCLMUL instructions])
1508 fi
1509
1510
1511 #
1512 # Check whether GCC inline assembler supports SHA Extensions instructions.
1513 #
1514 AC_CACHE_CHECK([whether GCC inline assembler supports SHA Extensions instructions],
1515        [gcry_cv_gcc_inline_asm_shaext],
1516        [if test "$mpi_cpu_arch" != "x86" ||
1517            test "$try_asm_modules" != "yes" ; then
1518           gcry_cv_gcc_inline_asm_shaext="n/a"
1519         else
1520           gcry_cv_gcc_inline_asm_shaext=no
1521           AC_LINK_IFELSE([AC_LANG_PROGRAM(
1522           [[void a(void) {
1523               __asm__("sha1rnds4 \$0, %%xmm1, %%xmm3\n\t":::"cc");
1524               __asm__("sha1nexte %%xmm1, %%xmm3\n\t":::"cc");
1525               __asm__("sha1msg1 %%xmm1, %%xmm3\n\t":::"cc");
1526               __asm__("sha1msg2 %%xmm1, %%xmm3\n\t":::"cc");
1527               __asm__("sha256rnds2 %%xmm0, %%xmm1, %%xmm3\n\t":::"cc");
1528               __asm__("sha256msg1 %%xmm1, %%xmm3\n\t":::"cc");
1529               __asm__("sha256msg2 %%xmm1, %%xmm3\n\t":::"cc");
1530             }]], [ a(); ] )],
1531           [gcry_cv_gcc_inline_asm_shaext=yes])
1532         fi])
1533 if test "$gcry_cv_gcc_inline_asm_shaext" = "yes" ; then
1534    AC_DEFINE(HAVE_GCC_INLINE_ASM_SHAEXT,1,
1535      [Defined if inline assembler supports SHA Extensions instructions])
1536 fi
1537
1538
1539 #
1540 # Check whether GCC inline assembler supports SSE4.1 instructions.
1541 #
1542 AC_CACHE_CHECK([whether GCC inline assembler supports SSE4.1 instructions],
1543        [gcry_cv_gcc_inline_asm_sse41],
1544        [if test "$mpi_cpu_arch" != "x86" ||
1545            test "$try_asm_modules" != "yes" ; then
1546           gcry_cv_gcc_inline_asm_sse41="n/a"
1547         else
1548           gcry_cv_gcc_inline_asm_sse41=no
1549           AC_LINK_IFELSE([AC_LANG_PROGRAM(
1550           [[void a(void) {
1551               int i;
1552               __asm__("pextrd \$2, %%xmm0, %[out]\n\t" : [out] "=m" (i));
1553             }]], [ a(); ] )],
1554           [gcry_cv_gcc_inline_asm_sse41=yes])
1555         fi])
1556 if test "$gcry_cv_gcc_inline_asm_sse41" = "yes" ; then
1557    AC_DEFINE(HAVE_GCC_INLINE_ASM_SSE41,1,
1558      [Defined if inline assembler supports SSE4.1 instructions])
1559 fi
1560
1561
1562 #
1563 # Check whether GCC inline assembler supports AVX instructions
1564 #
1565 AC_CACHE_CHECK([whether GCC inline assembler supports AVX instructions],
1566        [gcry_cv_gcc_inline_asm_avx],
1567        [if test "$mpi_cpu_arch" != "x86" ||
1568            test "$try_asm_modules" != "yes" ; then
1569           gcry_cv_gcc_inline_asm_avx="n/a"
1570         else
1571           gcry_cv_gcc_inline_asm_avx=no
1572           AC_LINK_IFELSE([AC_LANG_PROGRAM(
1573           [[void a(void) {
1574               __asm__("xgetbv; vaesdeclast (%[mem]),%%xmm0,%%xmm7\n\t"::[mem]"r"(0):);
1575             }]], [ a(); ] )],
1576           [gcry_cv_gcc_inline_asm_avx=yes])
1577         fi])
1578 if test "$gcry_cv_gcc_inline_asm_avx" = "yes" ; then
1579    AC_DEFINE(HAVE_GCC_INLINE_ASM_AVX,1,
1580      [Defined if inline assembler supports AVX instructions])
1581 fi
1582
1583
1584 #
1585 # Check whether GCC inline assembler supports AVX2 instructions
1586 #
1587 AC_CACHE_CHECK([whether GCC inline assembler supports AVX2 instructions],
1588        [gcry_cv_gcc_inline_asm_avx2],
1589        [if test "$mpi_cpu_arch" != "x86" ||
1590            test "$try_asm_modules" != "yes" ; then
1591           gcry_cv_gcc_inline_asm_avx2="n/a"
1592         else
1593           gcry_cv_gcc_inline_asm_avx2=no
1594           AC_LINK_IFELSE([AC_LANG_PROGRAM(
1595           [[void a(void) {
1596               __asm__("xgetbv; vpbroadcastb %%xmm7,%%ymm1\n\t":::"cc");
1597             }]], [ a(); ] )],
1598           [gcry_cv_gcc_inline_asm_avx2=yes])
1599         fi])
1600 if test "$gcry_cv_gcc_inline_asm_avx2" = "yes" ; then
1601    AC_DEFINE(HAVE_GCC_INLINE_ASM_AVX2,1,
1602      [Defined if inline assembler supports AVX2 instructions])
1603 fi
1604
1605
1606 #
1607 # Check whether GCC inline assembler supports VAES and VPCLMUL instructions
1608 #
1609 AC_CACHE_CHECK([whether GCC inline assembler supports VAES and VPCLMUL instructions],
1610        [gcry_cv_gcc_inline_asm_vaes_vpclmul],
1611        [if test "$mpi_cpu_arch" != "x86" ||
1612            test "$try_asm_modules" != "yes" ; then
1613           gcry_cv_gcc_inline_asm_vaes_vpclmul="n/a"
1614         else
1615           gcry_cv_gcc_inline_asm_vaes_vpclmul=no
1616           AC_LINK_IFELSE([AC_LANG_PROGRAM(
1617           [[void a(void) {
1618               __asm__("vaesenclast %%ymm7,%%ymm7,%%ymm1\n\t":::"cc");/*256-bit*/
1619               __asm__("vaesenclast %%zmm7,%%zmm7,%%zmm1\n\t":::"cc");/*512-bit*/
1620               __asm__("vpclmulqdq \$0,%%ymm7,%%ymm7,%%ymm1\n\t":::"cc");/*256-bit*/
1621               __asm__("vpclmulqdq \$0,%%zmm7,%%zmm7,%%zmm1\n\t":::"cc");/*512-bit*/
1622             }]], [ a(); ] )],
1623           [gcry_cv_gcc_inline_asm_vaes_vpclmul=yes])
1624         fi])
1625 if test "$gcry_cv_gcc_inline_asm_vaes_vpclmul" = "yes" ; then
1626    AC_DEFINE(HAVE_GCC_INLINE_ASM_VAES_VPCLMUL,1,
1627      [Defined if inline assembler supports VAES and VPCLMUL instructions])
1628 fi
1629
1630
1631 #
1632 # Check whether GCC inline assembler supports BMI2 instructions
1633 #
1634 AC_CACHE_CHECK([whether GCC inline assembler supports BMI2 instructions],
1635        [gcry_cv_gcc_inline_asm_bmi2],
1636        [if test "$mpi_cpu_arch" != "x86" ||
1637            test "$try_asm_modules" != "yes" ; then
1638           gcry_cv_gcc_inline_asm_bmi2="n/a"
1639         else
1640           gcry_cv_gcc_inline_asm_bmi2=no
1641           AC_LINK_IFELSE([AC_LANG_PROGRAM(
1642           [[unsigned int a(unsigned int x, unsigned int y) {
1643               unsigned int tmp1, tmp2;
1644               asm ("rorxl %2, %1, %0"
1645                    : "=r" (tmp1)
1646                    : "rm0" (x), "J" (32 - ((23) & 31)));
1647               asm ("andnl %2, %1, %0"
1648                    : "=r" (tmp2)
1649                    : "r0" (x), "rm" (y));
1650               return tmp1 + tmp2;
1651             }]], [ a(1, 2); ] )],
1652           [gcry_cv_gcc_inline_asm_bmi2=yes])
1653         fi])
1654 if test "$gcry_cv_gcc_inline_asm_bmi2" = "yes" ; then
1655    AC_DEFINE(HAVE_GCC_INLINE_ASM_BMI2,1,
1656      [Defined if inline assembler supports BMI2 instructions])
1657 fi
1658
1659
1660 #
1661 # Check whether GCC assembler needs "-Wa,--divide" to correctly handle
1662 # constant division
1663 #
1664 if test $amd64_as_feature_detection = yes; then
1665   AC_CACHE_CHECK([whether GCC assembler handles division correctly],
1666        [gcry_cv_gcc_as_const_division_ok],
1667        [gcry_cv_gcc_as_const_division_ok=no
1668         AC_LINK_IFELSE([AC_LANG_PROGRAM(
1669           [[__asm__(".text\n\tfn:\n\t xorl \$(123456789/12345678), %ebp;\n\t");]],
1670             [fn();])],
1671           [gcry_cv_gcc_as_const_division_ok=yes])])
1672   if test "$gcry_cv_gcc_as_const_division_ok" = "no" ; then
1673     #
1674     # Add '-Wa,--divide' to CPPFLAGS and try check again.
1675     #
1676     _gcc_cppflags_save="$CPPFLAGS"
1677     CPPFLAGS="$CPPFLAGS -Wa,--divide"
1678     AC_CACHE_CHECK([whether GCC assembler handles division correctly with "-Wa,--divide"],
1679          [gcry_cv_gcc_as_const_division_with_wadivide_ok],
1680          [gcry_cv_gcc_as_const_division_with_wadivide_ok=no
1681           AC_LINK_IFELSE([AC_LANG_PROGRAM(
1682             [[__asm__(".text\n\tfn:\n\t xorl \$(123456789/12345678), %ebp;\n\t");]],
1683               [fn();])],
1684             [gcry_cv_gcc_as_const_division_with_wadivide_ok=yes])])
1685     if test "$gcry_cv_gcc_as_const_division_with_wadivide_ok" = "no" ; then
1686       # '-Wa,--divide' did not work, restore old flags.
1687       CPPFLAGS="$_gcc_cppflags_save"
1688     fi
1689   fi
1690 fi
1691
1692
1693 #
1694 # Check whether GCC assembler supports features needed for our amd64
1695 # implementations
1696 #
1697 if test $amd64_as_feature_detection = yes; then
1698   AC_CACHE_CHECK([whether GCC assembler is compatible for amd64 assembly implementations],
1699        [gcry_cv_gcc_amd64_platform_as_ok],
1700        [if test "$mpi_cpu_arch" != "x86" ||
1701            test "$try_asm_modules" != "yes" ; then
1702           gcry_cv_gcc_amd64_platform_as_ok="n/a"
1703         else
1704           gcry_cv_gcc_amd64_platform_as_ok=no
1705           AC_LINK_IFELSE([AC_LANG_PROGRAM(
1706           [[__asm__(
1707                 /* Test if '.type' and '.size' are supported.  */
1708                 /* These work only on ELF targets. */
1709                 ".text\n\t"
1710                 "asmfunc:\n\t"
1711                 ".size asmfunc,.-asmfunc;\n\t"
1712                 ".type asmfunc,@function;\n\t"
1713                 /* Test if assembler allows use of '/' for constant division
1714                  * (Solaris/x86 issue). If previous constant division check
1715                  * and "-Wa,--divide" workaround failed, this causes assembly
1716                  * to be disable on this machine. */
1717                 "xorl \$(123456789/12345678), %ebp;\n\t"
1718             );]], [ asmfunc(); ])],
1719           [gcry_cv_gcc_amd64_platform_as_ok=yes])
1720         fi])
1721   if test "$gcry_cv_gcc_amd64_platform_as_ok" = "yes" ; then
1722      AC_DEFINE(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS,1,
1723               [Defined if underlying assembler is compatible with amd64 assembly implementations])
1724   fi
1725   if test "$gcry_cv_gcc_amd64_platform_as_ok" = "no" &&
1726      test "$gcry_cv_gcc_attribute_sysv_abi" = "yes" &&
1727      test "$gcry_cv_gcc_default_abi_is_ms_abi" = "yes"; then
1728     AC_CACHE_CHECK([whether GCC assembler is compatible for WIN64 assembly implementations],
1729       [gcry_cv_gcc_win64_platform_as_ok],
1730       [gcry_cv_gcc_win64_platform_as_ok=no
1731       AC_LINK_IFELSE([AC_LANG_PROGRAM(
1732         [[__asm__(
1733               ".text\n\t"
1734               ".globl asmfunc\n\t"
1735               "asmfunc:\n\t"
1736               "xorq \$(1234), %rbp;\n\t"
1737           );]], [ asmfunc(); ])],
1738         [gcry_cv_gcc_win64_platform_as_ok=yes])])
1739     if test "$gcry_cv_gcc_win64_platform_as_ok" = "yes" ; then
1740       AC_DEFINE(HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS,1,
1741                 [Defined if underlying assembler is compatible with WIN64 assembly implementations])
1742     fi
1743   fi
1744 fi
1745
1746
1747 #
1748 # Check whether GCC assembler supports features needed for assembly
1749 # implementations that use Intel syntax
1750 #
1751 AC_CACHE_CHECK([whether GCC assembler is compatible for Intel syntax assembly implementations],
1752        [gcry_cv_gcc_platform_as_ok_for_intel_syntax],
1753        [if test "$mpi_cpu_arch" != "x86" ||
1754            test "$try_asm_modules" != "yes" ; then
1755           gcry_cv_gcc_platform_as_ok_for_intel_syntax="n/a"
1756         else
1757           gcry_cv_gcc_platform_as_ok_for_intel_syntax=no
1758           AC_LINK_IFELSE([AC_LANG_PROGRAM(
1759           [[__asm__(
1760                 ".intel_syntax noprefix\n\t"
1761                 ".text\n\t"
1762                 "actest:\n\t"
1763                 "pxor xmm1, xmm7;\n\t"
1764                 "vperm2i128 ymm2, ymm3, ymm0, 1;\n\t"
1765                 "add eax, ebp;\n\t"
1766                 "rorx eax, ebp, 1;\n\t"
1767                 "sub eax, [esp + 4];\n\t"
1768                 "add dword ptr [esp + eax], 0b10101;\n\t"
1769                 ".att_syntax prefix\n\t"
1770             );]], [ actest(); ])],
1771           [gcry_cv_gcc_platform_as_ok_for_intel_syntax=yes])
1772         fi])
1773 if test "$gcry_cv_gcc_platform_as_ok_for_intel_syntax" = "yes" ; then
1774   AC_DEFINE(HAVE_INTEL_SYNTAX_PLATFORM_AS,1,
1775             [Defined if underlying assembler is compatible with Intel syntax assembly implementations])
1776 fi
1777
1778
1779 #
1780 # Check whether compiler is configured for ARMv6 or newer architecture
1781 #
1782 AC_CACHE_CHECK([whether compiler is configured for ARMv6 or newer architecture],
1783        [gcry_cv_cc_arm_arch_is_v6],
1784        [if test "$mpi_cpu_arch" != "arm" ||
1785            test "$try_asm_modules" != "yes" ; then
1786           gcry_cv_cc_arm_arch_is_v6="n/a"
1787         else
1788           gcry_cv_cc_arm_arch_is_v6=no
1789           AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1790           [[
1791            #if defined(__arm__) && \
1792              ((defined(__ARM_ARCH) && __ARM_ARCH >= 6) \
1793              || defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \
1794              || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) \
1795              || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6T2__) \
1796              || defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \
1797              || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \
1798              || defined(__ARM_ARCH_7EM__))
1799              /* empty */
1800            #else
1801              /* fail compile if not ARMv6. */
1802              not_armv6 not_armv6 = (not_armv6)not_armv6;
1803            #endif
1804           ]])],
1805           [gcry_cv_cc_arm_arch_is_v6=yes])
1806         fi])
1807 if test "$gcry_cv_cc_arm_arch_is_v6" = "yes" ; then
1808    AC_DEFINE(HAVE_ARM_ARCH_V6,1,
1809      [Defined if ARM architecture is v6 or newer])
1810 fi
1811
1812
1813 #
1814 # Check whether GCC inline assembler supports NEON instructions
1815 #
1816 AC_CACHE_CHECK([whether GCC inline assembler supports NEON instructions],
1817        [gcry_cv_gcc_inline_asm_neon],
1818        [if test "$mpi_cpu_arch" != "arm" ||
1819            test "$try_asm_modules" != "yes" ; then
1820           gcry_cv_gcc_inline_asm_neon="n/a"
1821         else
1822           gcry_cv_gcc_inline_asm_neon=no
1823           AC_LINK_IFELSE([AC_LANG_PROGRAM(
1824           [[__asm__(
1825                 ".syntax unified\n\t"
1826                 ".arm\n\t"
1827                 ".fpu neon\n\t"
1828                 ".text\n\t"
1829                 "testfn:\n\t"
1830                 "vld1.64 {%q0-%q1}, [%r0]!;\n\t"
1831                 "vrev64.8 %q0, %q3;\n\t"
1832                 "vadd.u64 %q0, %q1;\n\t"
1833                 "vadd.s64 %d3, %d2, %d3;\n\t"
1834                 );
1835             ]], [ testfn(); ])],
1836           [gcry_cv_gcc_inline_asm_neon=yes])
1837         fi])
1838 if test "$gcry_cv_gcc_inline_asm_neon" = "yes" ; then
1839    AC_DEFINE(HAVE_GCC_INLINE_ASM_NEON,1,
1840      [Defined if inline assembler supports NEON instructions])
1841 fi
1842
1843
1844 #
1845 # Check whether GCC inline assembler supports AArch32 Crypto Extension instructions
1846 #
1847 AC_CACHE_CHECK([whether GCC inline assembler supports AArch32 Crypto Extension instructions],
1848        [gcry_cv_gcc_inline_asm_aarch32_crypto],
1849        [if test "$mpi_cpu_arch" != "arm" ||
1850            test "$try_asm_modules" != "yes" ; then
1851           gcry_cv_gcc_inline_asm_aarch32_crypto="n/a"
1852         else
1853           gcry_cv_gcc_inline_asm_aarch32_crypto=no
1854           AC_LINK_IFELSE([AC_LANG_PROGRAM(
1855           [[__asm__(
1856                 ".syntax unified\n\t"
1857                 ".arch armv8-a\n\t"
1858                 ".arm\n\t"
1859                 ".fpu crypto-neon-fp-armv8\n\t"
1860                 ".text\n\t"
1861
1862                 "testfn:\n\t"
1863                 "sha1h.32 q0, q0;\n\t"
1864                 "sha1c.32 q0, q0, q0;\n\t"
1865                 "sha1p.32 q0, q0, q0;\n\t"
1866                 "sha1su0.32 q0, q0, q0;\n\t"
1867                 "sha1su1.32 q0, q0;\n\t"
1868
1869                 "sha256h.32 q0, q0, q0;\n\t"
1870                 "sha256h2.32 q0, q0, q0;\n\t"
1871                 "sha1p.32 q0, q0, q0;\n\t"
1872                 "sha256su0.32 q0, q0;\n\t"
1873                 "sha256su1.32 q0, q0, q15;\n\t"
1874
1875                 "aese.8 q0, q0;\n\t"
1876                 "aesd.8 q0, q0;\n\t"
1877                 "aesmc.8 q0, q0;\n\t"
1878                 "aesimc.8 q0, q0;\n\t"
1879
1880                 "vmull.p64 q0, d0, d0;\n\t"
1881                 );
1882             ]], [ testfn(); ])],
1883           [gcry_cv_gcc_inline_asm_aarch32_crypto=yes])
1884         fi])
1885 if test "$gcry_cv_gcc_inline_asm_aarch32_crypto" = "yes" ; then
1886    AC_DEFINE(HAVE_GCC_INLINE_ASM_AARCH32_CRYPTO,1,
1887      [Defined if inline assembler supports AArch32 Crypto Extension instructions])
1888 fi
1889
1890
1891 #
1892 # Check whether GCC inline assembler supports AArch64 NEON instructions
1893 #
1894 AC_CACHE_CHECK([whether GCC inline assembler supports AArch64 NEON instructions],
1895        [gcry_cv_gcc_inline_asm_aarch64_neon],
1896        [if test "$mpi_cpu_arch" != "aarch64" ||
1897            test "$try_asm_modules" != "yes" ; then
1898           gcry_cv_gcc_inline_asm_aarch64_neon="n/a"
1899         else
1900           gcry_cv_gcc_inline_asm_aarch64_neon=no
1901           AC_LINK_IFELSE([AC_LANG_PROGRAM(
1902           [[__asm__(
1903                 ".cpu generic+simd\n\t"
1904                 ".text\n\t"
1905                 "testfn:\n\t"
1906                 "mov w0, \#42;\n\t"
1907                 "dup v0.8b, w0;\n\t"
1908                 "ld4 {v0.8b,v1.8b,v2.8b,v3.8b},[x0],\#32;\n\t"
1909                 );
1910             ]], [ testfn(); ])],
1911           [gcry_cv_gcc_inline_asm_aarch64_neon=yes])
1912         fi])
1913 if test "$gcry_cv_gcc_inline_asm_aarch64_neon" = "yes" ; then
1914    AC_DEFINE(HAVE_GCC_INLINE_ASM_AARCH64_NEON,1,
1915      [Defined if inline assembler supports AArch64 NEON instructions])
1916 fi
1917
1918
1919 #
1920 # Check whether GCC inline assembler supports AArch64 Crypto Extension instructions
1921 #
1922 AC_CACHE_CHECK([whether GCC inline assembler supports AArch64 Crypto Extension instructions],
1923        [gcry_cv_gcc_inline_asm_aarch64_crypto],
1924        [if test "$mpi_cpu_arch" != "aarch64" ||
1925            test "$try_asm_modules" != "yes" ; then
1926           gcry_cv_gcc_inline_asm_aarch64_crypto="n/a"
1927         else
1928           gcry_cv_gcc_inline_asm_aarch64_crypto=no
1929           AC_LINK_IFELSE([AC_LANG_PROGRAM(
1930           [[__asm__(
1931                 ".cpu generic+simd+crypto\n\t"
1932                 ".text\n\t"
1933                 "testfn:\n\t"
1934                 "mov w0, \#42;\n\t"
1935                 "dup v0.8b, w0;\n\t"
1936                 "ld4 {v0.8b,v1.8b,v2.8b,v3.8b},[x0],\#32;\n\t"
1937
1938                 "sha1h s0, s0;\n\t"
1939                 "sha1c q0, s0, v0.4s;\n\t"
1940                 "sha1p q0, s0, v0.4s;\n\t"
1941                 "sha1su0 v0.4s, v0.4s, v0.4s;\n\t"
1942                 "sha1su1 v0.4s, v0.4s;\n\t"
1943
1944                 "sha256h q0, q0, v0.4s;\n\t"
1945                 "sha256h2 q0, q0, v0.4s;\n\t"
1946                 "sha1p q0, s0, v0.4s;\n\t"
1947                 "sha256su0 v0.4s, v0.4s;\n\t"
1948                 "sha256su1 v0.4s, v0.4s, v31.4s;\n\t"
1949
1950                 "aese v0.16b, v0.16b;\n\t"
1951                 "aesd v0.16b, v0.16b;\n\t"
1952                 "aesmc v0.16b, v0.16b;\n\t"
1953                 "aesimc v0.16b, v0.16b;\n\t"
1954
1955                 "pmull v0.1q, v0.1d, v31.1d;\n\t"
1956                 "pmull2 v0.1q, v0.2d, v31.2d;\n\t"
1957                 );
1958             ]], [ testfn(); ])],
1959           [gcry_cv_gcc_inline_asm_aarch64_crypto=yes])
1960         fi])
1961 if test "$gcry_cv_gcc_inline_asm_aarch64_crypto" = "yes" ; then
1962    AC_DEFINE(HAVE_GCC_INLINE_ASM_AARCH64_CRYPTO,1,
1963      [Defined if inline assembler supports AArch64 Crypto Extension instructions])
1964 fi
1965
1966
1967 #
1968 # Check whether PowerPC AltiVec/VSX intrinsics
1969 #
1970 AC_CACHE_CHECK([whether compiler supports PowerPC AltiVec/VSX intrinsics],
1971       [gcry_cv_cc_ppc_altivec],
1972       [if test "$mpi_cpu_arch" != "ppc" ||
1973           test "$try_asm_modules" != "yes" ; then
1974         gcry_cv_cc_ppc_altivec="n/a"
1975       else
1976         gcry_cv_cc_ppc_altivec=no
1977         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1978         [[#include <altivec.h>
1979           typedef vector unsigned char block;
1980           typedef vector unsigned int vecu32;
1981           block fn(block in)
1982           {
1983             block t = vec_perm (in, in, vec_vsx_ld (0, (unsigned char*)0));
1984             vecu32 y = vec_vsx_ld (0, (unsigned int*)0);
1985             return vec_cipher_be (t, in) ^ (block)y;
1986           }
1987           ]])],
1988         [gcry_cv_cc_ppc_altivec=yes])
1989       fi])
1990 if test "$gcry_cv_cc_ppc_altivec" = "yes" ; then
1991     AC_DEFINE(HAVE_COMPATIBLE_CC_PPC_ALTIVEC,1,
1992             [Defined if underlying compiler supports PowerPC AltiVec/VSX/crypto intrinsics])
1993 fi
1994
1995 _gcc_cflags_save=$CFLAGS
1996 CFLAGS="$CFLAGS -maltivec -mvsx -mcrypto"
1997
1998 if test "$gcry_cv_cc_ppc_altivec" = "no" &&
1999     test "$mpi_cpu_arch" = "ppc" &&
2000     test "$try_asm_modules" == "yes" ; then
2001   AC_CACHE_CHECK([whether compiler supports PowerPC AltiVec/VSX/crypto intrinsics with extra GCC flags],
2002     [gcry_cv_cc_ppc_altivec_cflags],
2003     [gcry_cv_cc_ppc_altivec_cflags=no
2004     AC_COMPILE_IFELSE([AC_LANG_SOURCE(
2005       [[#include <altivec.h>
2006         typedef vector unsigned char block;
2007         typedef vector unsigned int vecu32;
2008         block fn(block in)
2009         {
2010           block t = vec_perm (in, in, vec_vsx_ld (0, (unsigned char*)0));
2011           vecu32 y = vec_vsx_ld (0, (unsigned int*)0);
2012           return vec_cipher_be (t, in) ^ (block)y;
2013         }]])],
2014       [gcry_cv_cc_ppc_altivec_cflags=yes])])
2015   if test "$gcry_cv_cc_ppc_altivec_cflags" = "yes" ; then
2016     AC_DEFINE(HAVE_COMPATIBLE_CC_PPC_ALTIVEC,1,
2017               [Defined if underlying compiler supports PowerPC AltiVec/VSX/crypto intrinsics])
2018     AC_DEFINE(HAVE_COMPATIBLE_CC_PPC_ALTIVEC_WITH_CFLAGS,1,
2019               [Defined if underlying compiler supports PowerPC AltiVec/VSX/crypto intrinsics with extra GCC flags])
2020   fi
2021 fi
2022
2023 AM_CONDITIONAL(ENABLE_PPC_VCRYPTO_EXTRA_CFLAGS,
2024                test "$gcry_cv_cc_ppc_altivec_cflags" = "yes")
2025
2026 # Restore flags.
2027 CFLAGS=$_gcc_cflags_save;
2028
2029
2030 #
2031 # Check whether GCC inline assembler supports PowerPC AltiVec/VSX/crypto instructions
2032 #
2033 AC_CACHE_CHECK([whether GCC inline assembler supports PowerPC AltiVec/VSX/crypto instructions],
2034        [gcry_cv_gcc_inline_asm_ppc_altivec],
2035        [if test "$mpi_cpu_arch" != "ppc" ||
2036            test "$try_asm_modules" != "yes" ; then
2037           gcry_cv_gcc_inline_asm_ppc_altivec="n/a"
2038         else
2039           gcry_cv_gcc_inline_asm_ppc_altivec=no
2040           AC_LINK_IFELSE([AC_LANG_PROGRAM(
2041           [[__asm__(".globl testfn;\n"
2042                     ".text\n\t"
2043                     "testfn:\n"
2044                     "stvx %v31,%r12,%r0;\n"
2045                     "lvx  %v20,%r12,%r0;\n"
2046                     "vcipher %v0, %v1, %v22;\n"
2047                     "lxvw4x %vs32, %r0, %r1;\n"
2048                     "vadduwm %v0, %v1, %v22;\n"
2049                     "vshasigmaw %v0, %v1, 0, 15;\n"
2050                     "vshasigmad %v0, %v1, 0, 15;\n"
2051                     "vpmsumd %v11, %v11, %v11;\n"
2052                   );
2053             ]], [ testfn(); ] )],
2054           [gcry_cv_gcc_inline_asm_ppc_altivec=yes])
2055         fi])
2056 if test "$gcry_cv_gcc_inline_asm_ppc_altivec" = "yes" ; then
2057    AC_DEFINE(HAVE_GCC_INLINE_ASM_PPC_ALTIVEC,1,
2058      [Defined if inline assembler supports PowerPC AltiVec/VSX/crypto instructions])
2059 fi
2060
2061
2062 #
2063 # Check whether GCC inline assembler supports PowerISA 3.00 instructions
2064 #
2065 AC_CACHE_CHECK([whether GCC inline assembler supports PowerISA 3.00 instructions],
2066        [gcry_cv_gcc_inline_asm_ppc_arch_3_00],
2067        [if test "$mpi_cpu_arch" != "ppc" ||
2068            test "$try_asm_modules" != "yes" ; then
2069           gcry_cv_gcc_inline_asm_ppc_arch_3_00="n/a"
2070         else
2071           gcry_cv_gcc_inline_asm_ppc_arch_3_00=no
2072           AC_LINK_IFELSE([AC_LANG_PROGRAM(
2073           [[__asm__(".text\n\t"
2074                     ".globl testfn;\n"
2075                     "testfn:\n"
2076                     "stxvb16x %r1,%v12,%v30;\n"
2077                   );
2078             ]], [ testfn(); ])],
2079           [gcry_cv_gcc_inline_asm_ppc_arch_3_00=yes])
2080         fi])
2081 if test "$gcry_cv_gcc_inline_asm_ppc_arch_3_00" = "yes" ; then
2082    AC_DEFINE(HAVE_GCC_INLINE_ASM_PPC_ARCH_3_00,1,
2083      [Defined if inline assembler supports PowerISA 3.00 instructions])
2084 fi
2085
2086
2087 #
2088 # Check whether GCC inline assembler supports zSeries instructions
2089 #
2090 AC_CACHE_CHECK([whether GCC inline assembler supports zSeries instructions],
2091       [gcry_cv_gcc_inline_asm_s390x],
2092       [if test "$mpi_cpu_arch" != "s390x" ||
2093           test "$try_asm_modules" != "yes" ; then
2094           gcry_cv_gcc_inline_asm_s390x="n/a"
2095         else
2096           gcry_cv_gcc_inline_asm_s390x=no
2097           AC_LINK_IFELSE([AC_LANG_PROGRAM(
2098           [[typedef unsigned int u128_t __attribute__ ((mode (TI)));
2099             unsigned int testfunc(unsigned int x, void *y, unsigned int z)
2100             {
2101               unsigned long fac[8];
2102               register unsigned long reg0 asm("0") = 0;
2103               register unsigned long reg1 asm("1") = x;
2104               u128_t r1 = ((u128_t)(unsigned long)y << 64) | (unsigned long)z;
2105               u128_t r2 = 0;
2106               u128_t r3 = 0;
2107               asm volatile (".insn rre,0xb92e << 16, %[r1], %[r2]\n\t"
2108                             : [r1] "+a" (r1), [r2] "+a" (r2)
2109                             : "r" (reg0), "r" (reg1)
2110                             : "cc", "memory");
2111               asm volatile (".insn rrf,0xb929 << 16, %[r1], %[r2], %[r3], 0\n\t"
2112                             : [r1] "+a" (r1), [r2] "+a" (r2), [r3] "+a" (r3)
2113                             : "r" (reg0), "r" (reg1)
2114                             : "cc", "memory");
2115               reg0 = 8 - 1;
2116               asm ("stfle %1\n\t"
2117                    : "+d" (reg0), "=Q" (fac[0])
2118                    :
2119                    : "cc", "memory");
2120               asm volatile ("mvc 0(16, %0), 0(%1)\n\t"
2121                             :
2122                             : "a" (y), "a" (fac)
2123                             : "memory");
2124               asm volatile ("xc 0(16, %0), 0(%0)\n\t"
2125                             :
2126                             : "a" (fac)
2127                             : "memory");
2128               asm volatile ("risbgn %%r11, %%r11, 0, 129, 0\n\t"
2129                             :
2130                             :
2131                             : "memory", "r11");
2132               asm volatile ("algrk %%r14, %%r14, %%r14\n\t"
2133                             :
2134                             :
2135                             : "memory", "r14");
2136               return (unsigned int)r1 ^ reg0;
2137             }
2138             ]] , [ testfunc(0, 0, 0); ])],
2139           [gcry_cv_gcc_inline_asm_s390x=yes])
2140         fi])
2141 if test "$gcry_cv_gcc_inline_asm_s390x" = "yes" ; then
2142    AC_DEFINE(HAVE_GCC_INLINE_ASM_S390X,1,
2143      [Defined if inline assembler supports zSeries instructions])
2144 fi
2145
2146
2147 #
2148 # Check whether GCC inline assembler supports zSeries vector instructions
2149 #
2150 AC_CACHE_CHECK([whether GCC inline assembler supports zSeries vector instructions],
2151       [gcry_cv_gcc_inline_asm_s390x_vx],
2152       [if test "$mpi_cpu_arch" != "s390x" ||
2153           test "$try_asm_modules" != "yes" ; then
2154           gcry_cv_gcc_inline_asm_s390x_vx="n/a"
2155         else
2156           gcry_cv_gcc_inline_asm_s390x_vx=no
2157           if test "$gcry_cv_gcc_inline_asm_s390x" = "yes" ; then
2158             AC_LINK_IFELSE([AC_LANG_PROGRAM(
2159             [[void testfunc(void)
2160               {
2161                 asm volatile (".machine \"z13+vx\"\n\t"
2162                               "vx %%v0, %%v1, %%v31\n\t"
2163                               "verllf %%v11, %%v11, (16)(0)\n\t"
2164                               :
2165                               :
2166                               : "memory");
2167               }
2168               ]], [ testfunc(); ])],
2169             [gcry_cv_gcc_inline_asm_s390x_vx=yes])
2170           fi
2171         fi])
2172 if test "$gcry_cv_gcc_inline_asm_s390x_vx" = "yes" ; then
2173    AC_DEFINE(HAVE_GCC_INLINE_ASM_S390X_VX,1,
2174      [Defined if inline assembler supports zSeries vector instructions])
2175 fi
2176
2177
2178 #######################################
2179 #### Checks for library functions. ####
2180 #######################################
2181
2182 AC_FUNC_VPRINTF
2183 # We have replacements for these in src/missing-string.c
2184 AC_CHECK_FUNCS(stpcpy strcasecmp)
2185 # We have replacements for these in src/g10lib.h
2186 AC_CHECK_FUNCS(strtoul memmove stricmp atexit raise)
2187 # Other checks
2188 AC_CHECK_FUNCS(strerror rand mmap getpagesize sysconf waitpid wait4)
2189 AC_CHECK_FUNCS(gettimeofday getrusage gethrtime clock_gettime syslog)
2190 AC_CHECK_FUNCS(syscall fcntl ftruncate flockfile getauxval elf_aux_info)
2191 AC_CHECK_FUNCS(explicit_bzero explicit_memset getentropy)
2192
2193 GNUPG_CHECK_MLOCK
2194
2195 #
2196 # Replacement functions.
2197 #
2198 AC_REPLACE_FUNCS([getpid clock])
2199
2200
2201 #
2202 # Check whether it is necessary to link against libdl.
2203 #
2204 DL_LIBS=""
2205 if test "$use_hmac_binary_check" != no ; then
2206   _gcry_save_libs="$LIBS"
2207   LIBS=""
2208   AC_SEARCH_LIBS(dlopen, c dl,,,)
2209   DL_LIBS=$LIBS
2210   LIBS="$_gcry_save_libs"
2211 fi
2212 AC_SUBST(DL_LIBS)
2213
2214
2215 #
2216 # Check whether we can use Linux capabilities as requested.
2217 #
2218 if test "$use_capabilities" = "yes" ; then
2219 use_capabilities=no
2220 AC_CHECK_HEADERS(sys/capability.h)
2221 if test "$ac_cv_header_sys_capability_h" = "yes" ; then
2222   AC_CHECK_LIB(cap, cap_init, ac_need_libcap=1)
2223   if test "$ac_cv_lib_cap_cap_init" = "yes"; then
2224      AC_DEFINE(USE_CAPABILITIES,1,
2225                [define if capabilities should be used])
2226      LIBS="$LIBS -lcap"
2227      use_capabilities=yes
2228   fi
2229 fi
2230 if test "$use_capabilities" = "no" ; then
2231     AC_MSG_WARN([[
2232 ***
2233 *** The use of capabilities on this system is not possible.
2234 *** You need a recent Linux kernel and some patches:
2235 ***   fcaps-2.2.9-990610.patch      (kernel patch for 2.2.9)
2236 ***   fcap-module-990613.tar.gz     (kernel module)
2237 ***   libcap-1.92.tar.gz            (user mode library and utilities)
2238 *** And you have to configure the kernel with CONFIG_VFS_CAP_PLUGIN
2239 *** set (filesystems menu). Be warned: This code is *really* ALPHA.
2240 ***]])
2241 fi
2242 fi
2243
2244 # Check whether a random device is available.
2245 if test "$try_dev_random" = yes ; then
2246     AC_CACHE_CHECK(for random device, ac_cv_have_dev_random,
2247     [if test -r "$NAME_OF_DEV_RANDOM" && test -r "$NAME_OF_DEV_URANDOM" ; then
2248       ac_cv_have_dev_random=yes; else ac_cv_have_dev_random=no; fi])
2249     if test "$ac_cv_have_dev_random" = yes; then
2250         AC_DEFINE(HAVE_DEV_RANDOM,1,
2251                  [defined if the system supports a random device] )
2252     fi
2253 else
2254     AC_MSG_CHECKING(for random device)
2255     ac_cv_have_dev_random=no
2256     AC_MSG_RESULT(has been disabled)
2257 fi
2258
2259 # Figure out the random modules for this configuration.
2260 if test "$random" = "default"; then
2261
2262     # Select default value.
2263     if test "$ac_cv_func_getentropy" = yes; then
2264         random_modules="getentropy"
2265     elif test "$ac_cv_have_dev_random" = yes; then
2266         # Try Linuxish random device.
2267         random_modules="linux"
2268     else
2269         case "${host}" in
2270         *-*-mingw32ce*)
2271           # WindowsCE random device.
2272           random_modules="w32ce"
2273           ;;
2274         *-*-mingw32*|*-*-cygwin*)
2275           # Windows random device.
2276           random_modules="w32"
2277           ;;
2278         *)
2279           # Build everything, allow to select at runtime.
2280           random_modules="$auto_random_modules"
2281           ;;
2282         esac
2283     fi
2284 else
2285     if test "$random" = "auto"; then
2286         # Build everything, allow to select at runtime.
2287         random_modules="$auto_random_modules"
2288     else
2289         random_modules="$random"
2290     fi
2291 fi
2292
2293
2294 #
2295 # Other defines
2296 #
2297 if test mym4_isgit = "yes"; then
2298     AC_DEFINE(IS_DEVELOPMENT_VERSION,1,
2299               [Defined if this is not a regular release])
2300 fi
2301
2302
2303 AM_CONDITIONAL(CROSS_COMPILING, test x$cross_compiling = xyes)
2304
2305
2306 # This is handy for debugging so the compiler doesn't rearrange
2307 # things and eliminate variables.
2308 AC_ARG_ENABLE(optimization,
2309        AS_HELP_STRING([--disable-optimization],
2310                       [disable compiler optimization]),
2311                       [if test $enableval = no ; then
2312                          CFLAGS=`echo $CFLAGS | sed 's/-O[[0-9]]//'`
2313                        fi])
2314
2315 AC_MSG_NOTICE([checking for cc features])
2316 # CFLAGS mangling when using gcc.
2317 if test "$GCC" = yes; then
2318     AC_MSG_CHECKING([if gcc supports -fno-delete-null-pointer-checks])
2319     _gcc_cflags_save=$CFLAGS
2320     CFLAGS="-fno-delete-null-pointer-checks"
2321     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_wopt=yes,_gcc_wopt=no)
2322     AC_MSG_RESULT($_gcc_wopt)
2323     CFLAGS=$_gcc_cflags_save;
2324     if test x"$_gcc_wopt" = xyes ; then
2325        CFLAGS="$CFLAGS -fno-delete-null-pointer-checks"
2326     fi
2327
2328     CFLAGS="$CFLAGS -Wall"
2329     if test "$USE_MAINTAINER_MODE" = "yes"; then
2330         CFLAGS="$CFLAGS -Wcast-align -Wshadow -Wstrict-prototypes"
2331         CFLAGS="$CFLAGS -Wformat -Wno-format-y2k -Wformat-security"
2332
2333         # If -Wno-missing-field-initializers is supported we can enable a
2334         # a bunch of really useful warnings.
2335         AC_MSG_CHECKING([if gcc supports -Wno-missing-field-initializers])
2336         _gcc_cflags_save=$CFLAGS
2337         CFLAGS="-Wno-missing-field-initializers"
2338         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_wopt=yes,_gcc_wopt=no)
2339         AC_MSG_RESULT($_gcc_wopt)
2340         CFLAGS=$_gcc_cflags_save;
2341         if test x"$_gcc_wopt" = xyes ; then
2342           CFLAGS="$CFLAGS -W -Wextra -Wbad-function-cast"
2343           CFLAGS="$CFLAGS -Wwrite-strings"
2344           CFLAGS="$CFLAGS -Wdeclaration-after-statement"
2345           CFLAGS="$CFLAGS -Wno-missing-field-initializers"
2346           CFLAGS="$CFLAGS -Wno-sign-compare"
2347         fi
2348
2349         AC_MSG_CHECKING([if gcc supports -Wpointer-arith])
2350         _gcc_cflags_save=$CFLAGS
2351         CFLAGS="-Wpointer-arith"
2352         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],_gcc_wopt=yes,_gcc_wopt=no)
2353         AC_MSG_RESULT($_gcc_wopt)
2354         CFLAGS=$_gcc_cflags_save;
2355         if test x"$_gcc_wopt" = xyes ; then
2356           CFLAGS="$CFLAGS -Wpointer-arith"
2357         fi
2358     fi
2359 fi
2360
2361 # Check whether as(1) supports a noeexecstack feature.  This test
2362 # includes an override option.
2363 CL_AS_NOEXECSTACK
2364
2365
2366 AC_SUBST(LIBGCRYPT_CONFIG_API_VERSION)
2367 AC_SUBST(LIBGCRYPT_CONFIG_LIBS)
2368 AC_SUBST(LIBGCRYPT_CONFIG_CFLAGS)
2369 AC_SUBST(LIBGCRYPT_CONFIG_HOST)
2370 AC_SUBST(LIBGCRYPT_THREAD_MODULES)
2371
2372 AC_CONFIG_COMMANDS([gcrypt-conf],[[
2373 chmod +x src/libgcrypt-config
2374 ]],[[
2375 prefix=$prefix
2376 exec_prefix=$exec_prefix
2377 libdir=$libdir
2378 datadir=$datadir
2379 DATADIRNAME=$DATADIRNAME
2380 ]])
2381
2382 #####################
2383 #### Conclusion. ####
2384 #####################
2385
2386 # Check that requested feature can actually be used and define
2387 # ENABLE_foo_SUPPORT macros.
2388
2389 if test x"$aesnisupport" = xyes ; then
2390   if test "$gcry_cv_gcc_inline_asm_ssse3" != "yes" ; then
2391     aesnisupport="no (unsupported by compiler)"
2392   fi
2393 fi
2394 if test x"$shaextsupport" = xyes ; then
2395   if test "$gcry_cv_gcc_inline_asm_shaext" != "yes" ; then
2396     shaextsupport="no (unsupported by compiler)"
2397   fi
2398 fi
2399 if test x"$pclmulsupport" = xyes ; then
2400   if test "$gcry_cv_gcc_inline_asm_pclmul" != "yes" ; then
2401     pclmulsupport="no (unsupported by compiler)"
2402   fi
2403 fi
2404 if test x"$sse41support" = xyes ; then
2405   if test "$gcry_cv_gcc_inline_asm_sse41" != "yes" ; then
2406     sse41support="no (unsupported by compiler)"
2407   fi
2408 fi
2409 if test x"$avxsupport" = xyes ; then
2410   if test "$gcry_cv_gcc_inline_asm_avx" != "yes" ; then
2411     avxsupport="no (unsupported by compiler)"
2412   fi
2413 fi
2414 if test x"$avx2support" = xyes ; then
2415   if test "$gcry_cv_gcc_inline_asm_avx2" != "yes" ; then
2416     avx2support="no (unsupported by compiler)"
2417   fi
2418 fi
2419 if test x"$neonsupport" = xyes ; then
2420   if test "$gcry_cv_gcc_inline_asm_neon" != "yes" ; then
2421     if test "$gcry_cv_gcc_inline_asm_aarch64_neon" != "yes" ; then
2422       neonsupport="no (unsupported by compiler)"
2423     fi
2424   fi
2425 fi
2426 if test x"$armcryptosupport" = xyes ; then
2427   if test "$gcry_cv_gcc_inline_asm_aarch32_crypto" != "yes" ; then
2428     if test "$gcry_cv_gcc_inline_asm_aarch64_crypto" != "yes" ; then
2429       neonsupport="no (unsupported by compiler)"
2430     fi
2431   fi
2432 fi
2433
2434 if test x"$aesnisupport" = xyes ; then
2435   AC_DEFINE(ENABLE_AESNI_SUPPORT, 1,
2436             [Enable support for Intel AES-NI instructions.])
2437 fi
2438 if test x"$shaextsupport" = xyes ; then
2439   AC_DEFINE(ENABLE_SHAEXT_SUPPORT, 1,
2440             [Enable support for Intel SHAEXT instructions.])
2441 fi
2442 if test x"$pclmulsupport" = xyes ; then
2443   AC_DEFINE(ENABLE_PCLMUL_SUPPORT, 1,
2444             [Enable support for Intel PCLMUL instructions.])
2445 fi
2446 if test x"$sse41support" = xyes ; then
2447   AC_DEFINE(ENABLE_SSE41_SUPPORT, 1,
2448             [Enable support for Intel SSE4.1 instructions.])
2449 fi
2450 if test x"$avxsupport" = xyes ; then
2451   AC_DEFINE(ENABLE_AVX_SUPPORT,1,
2452             [Enable support for Intel AVX instructions.])
2453 fi
2454 if test x"$avx2support" = xyes ; then
2455   AC_DEFINE(ENABLE_AVX2_SUPPORT,1,
2456             [Enable support for Intel AVX2 instructions.])
2457 fi
2458 if test x"$neonsupport" = xyes ; then
2459   AC_DEFINE(ENABLE_NEON_SUPPORT,1,
2460             [Enable support for ARM NEON instructions.])
2461 fi
2462 if test x"$armcryptosupport" = xyes ; then
2463   AC_DEFINE(ENABLE_ARM_CRYPTO_SUPPORT,1,
2464             [Enable support for ARMv8 Crypto Extension instructions.])
2465 fi
2466 if test x"$ppccryptosupport" = xyes ; then
2467   AC_DEFINE(ENABLE_PPC_CRYPTO_SUPPORT,1,
2468             [Enable support for POWER 8 (PowerISA 2.07) crypto extension.])
2469 fi
2470 if test x"$jentsupport" = xyes ; then
2471   AC_DEFINE(ENABLE_JENT_SUPPORT, 1,
2472             [Enable support for the jitter entropy collector.])
2473 fi
2474 if test x"$padlocksupport" = xyes ; then
2475   AC_DEFINE(ENABLE_PADLOCK_SUPPORT, 1,
2476             [Enable support for the PadLock engine.])
2477 fi
2478 if test x"$drngsupport" = xyes ; then
2479   AC_DEFINE(ENABLE_DRNG_SUPPORT, 1,
2480             [Enable support for Intel DRNG (RDRAND instruction).])
2481 fi
2482
2483
2484 if test x"$force_soft_hwfeatures" = xyes ; then
2485   AC_DEFINE(ENABLE_FORCE_SOFT_HWFEATURES, 1,
2486             [Enable forcing 'soft' HW feature bits on (for testing).])
2487 fi
2488
2489 # Define conditional sources and config.h symbols depending on the
2490 # selected ciphers, pubkey-ciphers, digests, kdfs, and random modules.
2491
2492 LIST_MEMBER(arcfour, $enabled_ciphers)
2493 if test "$found" = "1"; then
2494    GCRYPT_CIPHERS="$GCRYPT_CIPHERS arcfour.lo"
2495    AC_DEFINE(USE_ARCFOUR, 1, [Defined if this module should be included])
2496
2497    case "${host}" in
2498       x86_64-*-*)
2499          # Build with the assembly implementation
2500          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS arcfour-amd64.lo"
2501       ;;
2502    esac
2503 fi
2504
2505 LIST_MEMBER(blowfish, $enabled_ciphers)
2506 if test "$found" = "1" ; then
2507    GCRYPT_CIPHERS="$GCRYPT_CIPHERS blowfish.lo"
2508    AC_DEFINE(USE_BLOWFISH, 1, [Defined if this module should be included])
2509
2510    case "${host}" in
2511       x86_64-*-*)
2512          # Build with the assembly implementation
2513          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS blowfish-amd64.lo"
2514       ;;
2515       arm*-*-*)
2516          # Build with the assembly implementation
2517          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS blowfish-arm.lo"
2518       ;;
2519    esac
2520 fi
2521
2522 LIST_MEMBER(cast5, $enabled_ciphers)
2523 if test "$found" = "1" ; then
2524    GCRYPT_CIPHERS="$GCRYPT_CIPHERS cast5.lo"
2525    AC_DEFINE(USE_CAST5, 1, [Defined if this module should be included])
2526
2527    case "${host}" in
2528       x86_64-*-*)
2529          # Build with the assembly implementation
2530          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS cast5-amd64.lo"
2531       ;;
2532       arm*-*-*)
2533          # Build with the assembly implementation
2534          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS cast5-arm.lo"
2535       ;;
2536    esac
2537 fi
2538
2539 LIST_MEMBER(des, $enabled_ciphers)
2540 if test "$found" = "1" ; then
2541    GCRYPT_CIPHERS="$GCRYPT_CIPHERS des.lo"
2542    AC_DEFINE(USE_DES, 1, [Defined if this module should be included])
2543
2544    case "${host}" in
2545       x86_64-*-*)
2546          # Build with the assembly implementation
2547          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS des-amd64.lo"
2548       ;;
2549    esac
2550 fi
2551
2552 LIST_MEMBER(aes, $enabled_ciphers)
2553 if test "$found" = "1" ; then
2554    GCRYPT_CIPHERS="$GCRYPT_CIPHERS rijndael.lo"
2555    AC_DEFINE(USE_AES, 1, [Defined if this module should be included])
2556
2557    case "${host}" in
2558       x86_64-*-*)
2559          # Build with the assembly implementation
2560          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS rijndael-amd64.lo"
2561
2562          # Build with the SSSE3 implementation
2563          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS rijndael-ssse3-amd64.lo"
2564          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS rijndael-ssse3-amd64-asm.lo"
2565
2566          # Build with the VAES/AVX2 implementation
2567          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS rijndael-vaes.lo"
2568          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS rijndael-vaes-avx2-amd64.lo"
2569       ;;
2570       arm*-*-*)
2571          # Build with the assembly implementation
2572          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS rijndael-arm.lo"
2573
2574          # Build with the ARMv8/AArch32 CE implementation
2575          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS rijndael-armv8-ce.lo"
2576          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS rijndael-armv8-aarch32-ce.lo"
2577       ;;
2578       aarch64-*-*)
2579          # Build with the assembly implementation
2580          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS rijndael-aarch64.lo"
2581
2582          # Build with the ARMv8/AArch64 CE implementation
2583          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS rijndael-armv8-ce.lo"
2584          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS rijndael-armv8-aarch64-ce.lo"
2585       ;;
2586       powerpc64le-*-*)
2587          # Build with the crypto extension implementation
2588          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS rijndael-ppc.lo"
2589          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS rijndael-ppc9le.lo"
2590
2591          if test "$gcry_cv_gcc_inline_asm_ppc_altivec" = "yes" &&
2592             test "$gcry_cv_gcc_inline_asm_ppc_arch_3_00" = "yes" ; then
2593             # Build with AES-GCM bulk implementation for P10
2594             GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS rijndael-gcm-p10le.lo"
2595             GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS rijndael-p10le.lo"
2596          fi
2597       ;;
2598       powerpc64-*-*)
2599          # Big-Endian.
2600          # Build with the crypto extension implementation
2601          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS rijndael-ppc.lo"
2602       ;;
2603       powerpc-*-*)
2604          # Big-Endian.
2605          # Build with the crypto extension implementation
2606          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS rijndael-ppc.lo"
2607       ;;
2608       s390x-*-*)
2609          # Big-Endian.
2610          # Build with the crypto extension implementation
2611          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS rijndael-s390x.lo"
2612       ;;
2613    esac
2614
2615    case "$mpi_cpu_arch" in
2616      x86)
2617          # Build with the AES-NI implementation
2618          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS rijndael-aesni.lo"
2619
2620          # Build with the Padlock implementation
2621          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS rijndael-padlock.lo"
2622       ;;
2623    esac
2624 fi
2625
2626 LIST_MEMBER(twofish, $enabled_ciphers)
2627 if test "$found" = "1" ; then
2628    GCRYPT_CIPHERS="$GCRYPT_CIPHERS twofish.lo"
2629    AC_DEFINE(USE_TWOFISH, 1, [Defined if this module should be included])
2630
2631    case "${host}" in
2632       x86_64-*-*)
2633          # Build with the assembly implementation
2634          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS twofish-amd64.lo"
2635
2636          if test x"$avx2support" = xyes ; then
2637             # Build with the AVX2 implementation
2638             GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS twofish-avx2-amd64.lo"
2639          fi
2640       ;;
2641       arm*-*-*)
2642          # Build with the assembly implementation
2643          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS twofish-arm.lo"
2644       ;;
2645       aarch64-*-*)
2646          # Build with the assembly implementation
2647          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS twofish-aarch64.lo"
2648       ;;
2649    esac
2650 fi
2651
2652 LIST_MEMBER(serpent, $enabled_ciphers)
2653 if test "$found" = "1" ; then
2654    GCRYPT_CIPHERS="$GCRYPT_CIPHERS serpent.lo"
2655    AC_DEFINE(USE_SERPENT, 1, [Defined if this module should be included])
2656
2657    case "${host}" in
2658       x86_64-*-*)
2659          # Build with the SSE2 implementation
2660          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS serpent-sse2-amd64.lo"
2661       ;;
2662    esac
2663
2664    if test x"$avx2support" = xyes ; then
2665       # Build with the AVX2 implementation
2666       GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS serpent-avx2-amd64.lo"
2667    fi
2668
2669    if test x"$neonsupport" = xyes ; then
2670       # Build with the NEON implementation
2671       GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS serpent-armv7-neon.lo"
2672    fi
2673 fi
2674
2675 LIST_MEMBER(rfc2268, $enabled_ciphers)
2676 if test "$found" = "1" ; then
2677    GCRYPT_CIPHERS="$GCRYPT_CIPHERS rfc2268.lo"
2678    AC_DEFINE(USE_RFC2268, 1, [Defined if this module should be included])
2679 fi
2680
2681 LIST_MEMBER(seed, $enabled_ciphers)
2682 if test "$found" = "1" ; then
2683    GCRYPT_CIPHERS="$GCRYPT_CIPHERS seed.lo"
2684    AC_DEFINE(USE_SEED, 1, [Defined if this module should be included])
2685 fi
2686
2687 LIST_MEMBER(camellia, $enabled_ciphers)
2688 if test "$found" = "1" ; then
2689    GCRYPT_CIPHERS="$GCRYPT_CIPHERS camellia.lo camellia-glue.lo"
2690    AC_DEFINE(USE_CAMELLIA, 1, [Defined if this module should be included])
2691
2692    case "${host}" in
2693       arm*-*-*)
2694          # Build with the assembly implementation
2695          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS camellia-arm.lo"
2696       ;;
2697       aarch64-*-*)
2698          # Build with the assembly implementation
2699          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS camellia-aarch64.lo"
2700       ;;
2701    esac
2702
2703    if test x"$avxsupport" = xyes ; then
2704       if test x"$aesnisupport" = xyes ; then
2705         # Build with the AES-NI/AVX implementation
2706         GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS camellia-aesni-avx-amd64.lo"
2707       fi
2708    fi
2709
2710    if test x"$avx2support" = xyes ; then
2711       if test x"$aesnisupport" = xyes ; then
2712         # Build with the AES-NI/AVX2 implementation
2713         GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS camellia-aesni-avx2-amd64.lo"
2714
2715         # Build with the VAES/AVX2 implementation
2716         GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS camellia-vaes-avx2-amd64.lo"
2717       fi
2718    fi
2719 fi
2720
2721 LIST_MEMBER(idea, $enabled_ciphers)
2722 if test "$found" = "1" ; then
2723    GCRYPT_CIPHERS="$GCRYPT_CIPHERS idea.lo"
2724    AC_DEFINE(USE_IDEA, 1, [Defined if this module should be included])
2725 fi
2726
2727 LIST_MEMBER(salsa20, $enabled_ciphers)
2728 if test "$found" = "1" ; then
2729    GCRYPT_CIPHERS="$GCRYPT_CIPHERS salsa20.lo"
2730    AC_DEFINE(USE_SALSA20, 1, [Defined if this module should be included])
2731
2732    case "${host}" in
2733       x86_64-*-*)
2734          # Build with the assembly implementation
2735          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS salsa20-amd64.lo"
2736       ;;
2737    esac
2738
2739    if test x"$neonsupport" = xyes ; then
2740      # Build with the NEON implementation
2741      GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS salsa20-armv7-neon.lo"
2742    fi
2743 fi
2744
2745 LIST_MEMBER(gost28147, $enabled_ciphers)
2746 if test "$found" = "1" ; then
2747    GCRYPT_CIPHERS="$GCRYPT_CIPHERS gost28147.lo"
2748    AC_DEFINE(USE_GOST28147, 1, [Defined if this module should be included])
2749 fi
2750
2751 LIST_MEMBER(chacha20, $enabled_ciphers)
2752 if test "$found" = "1" ; then
2753    GCRYPT_CIPHERS="$GCRYPT_CIPHERS chacha20.lo"
2754    AC_DEFINE(USE_CHACHA20, 1, [Defined if this module should be included])
2755
2756    case "${host}" in
2757       x86_64-*-*)
2758          # Build with the assembly implementation
2759          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS chacha20-amd64-ssse3.lo"
2760          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS chacha20-amd64-avx2.lo"
2761       ;;
2762       aarch64-*-*)
2763          # Build with the assembly implementation
2764          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS chacha20-aarch64.lo"
2765       ;;
2766       powerpc64le-*-*)
2767          # Build with the ppc8 vector implementation
2768          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS chacha20-ppc.lo"
2769       ;;
2770       powerpc64-*-*)
2771          # Build with the ppc8 vector implementation
2772          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS chacha20-ppc.lo"
2773       ;;
2774       powerpc-*-*)
2775          # Build with the ppc8 vector implementation
2776          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS chacha20-ppc.lo"
2777       ;;
2778       s390x-*-*)
2779          # Build with the s390x/zSeries vector implementation
2780          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS chacha20-s390x.lo"
2781       ;;
2782    esac
2783
2784    if test x"$neonsupport" = xyes ; then
2785      # Build with the NEON implementation
2786      GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS chacha20-armv7-neon.lo"
2787    fi
2788 fi
2789
2790 LIST_MEMBER(sm4, $enabled_ciphers)
2791 if test "$found" = "1" ; then
2792    GCRYPT_CIPHERS="$GCRYPT_CIPHERS sm4.lo"
2793    AC_DEFINE(USE_SM4, 1, [Defined if this module should be included])
2794
2795    case "${host}" in
2796       x86_64-*-*)
2797          # Build with the assembly implementation
2798          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS sm4-aesni-avx-amd64.lo"
2799          GCRYPT_ASM_CIPHERS="$GCRYPT_ASM_CIPHERS sm4-aesni-avx2-amd64.lo"
2800       ;;
2801    esac
2802 fi
2803
2804 LIST_MEMBER(dsa, $enabled_pubkey_ciphers)
2805 if test "$found" = "1" ; then
2806    GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS dsa.lo"
2807    AC_DEFINE(USE_DSA, 1, [Defined if this module should be included])
2808 fi
2809
2810 LIST_MEMBER(rsa, $enabled_pubkey_ciphers)
2811 if test "$found" = "1" ; then
2812    GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS rsa.lo"
2813    AC_DEFINE(USE_RSA, 1, [Defined if this module should be included])
2814 fi
2815
2816 LIST_MEMBER(elgamal, $enabled_pubkey_ciphers)
2817 if test "$found" = "1" ; then
2818    GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS elgamal.lo"
2819    AC_DEFINE(USE_ELGAMAL, 1, [Defined if this module should be included])
2820 fi
2821
2822 LIST_MEMBER(ecc, $enabled_pubkey_ciphers)
2823 if test "$found" = "1" ; then
2824    GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS \
2825                           ecc.lo ecc-curves.lo ecc-misc.lo \
2826                           ecc-ecdh.lo ecc-ecdsa.lo ecc-eddsa.lo ecc-gost.lo \
2827                           ecc-sm2.lo"
2828    AC_DEFINE(USE_ECC, 1, [Defined if this module should be included])
2829 fi
2830
2831 LIST_MEMBER(crc, $enabled_digests)
2832 if test "$found" = "1" ; then
2833    GCRYPT_DIGESTS="$GCRYPT_DIGESTS crc.lo"
2834    AC_DEFINE(USE_CRC, 1, [Defined if this module should be included])
2835
2836    case "${host}" in
2837       i?86-*-* | x86_64-*-*)
2838          # Build with the assembly implementation
2839          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS crc-intel-pclmul.lo"
2840       ;;
2841       aarch64-*-*)
2842          # Build with the assembly implementation
2843          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS crc-armv8-ce.lo"
2844          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS crc-armv8-aarch64-ce.lo"
2845       ;;
2846       powerpc64le-*-*)
2847          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS crc-ppc.lo"
2848       ;;
2849       powerpc64-*-*)
2850          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS crc-ppc.lo"
2851       ;;
2852       powerpc-*-*)
2853          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS crc-ppc.lo"
2854       ;;
2855    esac
2856 fi
2857
2858 LIST_MEMBER(gostr3411-94, $enabled_digests)
2859 if test "$found" = "1" ; then
2860    # GOST R 34.11-94 internally uses GOST 28147-89
2861    LIST_MEMBER(gost28147, $enabled_ciphers)
2862    if test "$found" = "1" ; then
2863       GCRYPT_DIGESTS="$GCRYPT_DIGESTS gostr3411-94.lo"
2864       AC_DEFINE(USE_GOST_R_3411_94, 1, [Defined if this module should be included])
2865    fi
2866 fi
2867
2868 LIST_MEMBER(stribog, $enabled_digests)
2869 if test "$found" = "1" ; then
2870    GCRYPT_DIGESTS="$GCRYPT_DIGESTS stribog.lo"
2871    AC_DEFINE(USE_GOST_R_3411_12, 1, [Defined if this module should be included])
2872 fi
2873
2874 LIST_MEMBER(md2, $enabled_digests)
2875 if test "$found" = "1" ; then
2876    GCRYPT_DIGESTS="$GCRYPT_DIGESTS md2.lo"
2877    AC_DEFINE(USE_MD2, 1, [Defined if this module should be included])
2878 fi
2879
2880 LIST_MEMBER(md4, $enabled_digests)
2881 if test "$found" = "1" ; then
2882    GCRYPT_DIGESTS="$GCRYPT_DIGESTS md4.lo"
2883    AC_DEFINE(USE_MD4, 1, [Defined if this module should be included])
2884 fi
2885
2886 LIST_MEMBER(md5, $enabled_digests)
2887 if test "$found" = "1" ; then
2888    GCRYPT_DIGESTS="$GCRYPT_DIGESTS md5.lo"
2889    AC_DEFINE(USE_MD5, 1, [Defined if this module should be included])
2890 fi
2891
2892 LIST_MEMBER(rmd160, $enabled_digests)
2893 if test "$found" = "1" ; then
2894    GCRYPT_DIGESTS="$GCRYPT_DIGESTS rmd160.lo"
2895    AC_DEFINE(USE_RMD160, 1, [Defined if this module should be included])
2896 fi
2897
2898 LIST_MEMBER(sha256, $enabled_digests)
2899 if test "$found" = "1" ; then
2900    GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha256.lo"
2901    AC_DEFINE(USE_SHA256, 1, [Defined if this module should be included])
2902
2903    case "${host}" in
2904       x86_64-*-*)
2905          # Build with the assembly implementation
2906          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha256-ssse3-amd64.lo"
2907          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha256-avx-amd64.lo"
2908          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha256-avx2-bmi2-amd64.lo"
2909       ;;
2910       arm*-*-*)
2911          # Build with the assembly implementation
2912          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha256-armv8-aarch32-ce.lo"
2913       ;;
2914       aarch64-*-*)
2915          # Build with the assembly implementation
2916          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha256-armv8-aarch64-ce.lo"
2917       ;;
2918       powerpc64le-*-*)
2919          # Build with the crypto extension implementation
2920          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha256-ppc.lo"
2921       ;;
2922       powerpc64-*-*)
2923          # Big-Endian.
2924          # Build with the crypto extension implementation
2925          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha256-ppc.lo"
2926       ;;
2927       powerpc-*-*)
2928          # Big-Endian.
2929          # Build with the crypto extension implementation
2930          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha256-ppc.lo"
2931    esac
2932
2933    case "$mpi_cpu_arch" in
2934      x86)
2935        # Build with the SHAEXT implementation
2936        GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha256-intel-shaext.lo"
2937      ;;
2938    esac
2939 fi
2940
2941 LIST_MEMBER(sha512, $enabled_digests)
2942 if test "$found" = "1" ; then
2943    GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha512.lo"
2944    AC_DEFINE(USE_SHA512, 1, [Defined if this module should be included])
2945
2946    case "${host}" in
2947       x86_64-*-*)
2948          # Build with the assembly implementation
2949          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha512-ssse3-amd64.lo"
2950          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha512-avx-amd64.lo"
2951          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha512-avx2-bmi2-amd64.lo"
2952       ;;
2953       i?86-*-*)
2954          # Build with the assembly implementation
2955          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha512-ssse3-i386.lo"
2956       ;;
2957       arm*-*-*)
2958          # Build with the assembly implementation
2959          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha512-arm.lo"
2960       ;;
2961       powerpc64le-*-*)
2962          # Build with the crypto extension implementation
2963          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha512-ppc.lo"
2964       ;;
2965       powerpc64-*-*)
2966          # Big-Endian.
2967          # Build with the crypto extension implementation
2968          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha512-ppc.lo"
2969       ;;
2970       powerpc-*-*)
2971          # Big-Endian.
2972          # Build with the crypto extension implementation
2973          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha512-ppc.lo"
2974    esac
2975
2976    if test x"$neonsupport" = xyes ; then
2977      # Build with the NEON implementation
2978      GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha512-armv7-neon.lo"
2979    fi
2980 fi
2981
2982 LIST_MEMBER(sha3, $enabled_digests)
2983 if test "$found" = "1" ; then
2984    GCRYPT_DIGESTS="$GCRYPT_DIGESTS keccak.lo"
2985    AC_DEFINE(USE_SHA3, 1, [Defined if this module should be included])
2986
2987    case "${host}" in
2988       x86_64-*-*)
2989          # Build with the assembly implementation
2990          :
2991       ;;
2992    esac
2993
2994    if test x"$neonsupport" = xyes ; then
2995      # Build with the NEON implementation
2996      GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS keccak-armv7-neon.lo"
2997    fi
2998 fi
2999
3000 LIST_MEMBER(tiger, $enabled_digests)
3001 if test "$found" = "1" ; then
3002    GCRYPT_DIGESTS="$GCRYPT_DIGESTS tiger.lo"
3003    AC_DEFINE(USE_TIGER, 1, [Defined if this module should be included])
3004 fi
3005
3006 LIST_MEMBER(whirlpool, $enabled_digests)
3007 if test "$found" = "1" ; then
3008    GCRYPT_DIGESTS="$GCRYPT_DIGESTS whirlpool.lo"
3009    AC_DEFINE(USE_WHIRLPOOL, 1, [Defined if this module should be included])
3010
3011    case "${host}" in
3012       x86_64-*-*)
3013          # Build with the assembly implementation
3014          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS whirlpool-sse2-amd64.lo"
3015       ;;
3016    esac
3017 fi
3018
3019 LIST_MEMBER(blake2, $enabled_digests)
3020 if test "$found" = "1" ; then
3021    GCRYPT_DIGESTS="$GCRYPT_DIGESTS blake2.lo"
3022    AC_DEFINE(USE_BLAKE2, 1, [Defined if this module should be included])
3023
3024    case "${host}" in
3025       x86_64-*-*)
3026          # Build with the assembly implementation
3027          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS blake2b-amd64-avx2.lo"
3028          GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS blake2s-amd64-avx.lo"
3029       ;;
3030    esac
3031 fi
3032
3033 LIST_MEMBER(sm3, $enabled_digests)
3034 if test "$found" = "1" ; then
3035    GCRYPT_DIGESTS="$GCRYPT_DIGESTS sm3.lo"
3036    AC_DEFINE(USE_SM3, 1, [Defined if this module should be included])
3037
3038    case "${host}" in
3039      x86_64-*-*)
3040         # Build with the assembly implementation
3041         GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sm3-avx-bmi2-amd64.lo"
3042      ;;
3043      aarch64-*-*)
3044         # Build with the assembly implementation
3045         GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sm3-aarch64.lo"
3046      ;;
3047    esac
3048 fi
3049
3050 # SHA-1 needs to be included always for example because it is used by
3051 # random-csprng.c.
3052 GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha1.lo"
3053 AC_DEFINE(USE_SHA1, 1,   [Defined if this module should be included])
3054
3055 case "${host}" in
3056   x86_64-*-*)
3057     # Build with the assembly implementation
3058     GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha1-ssse3-amd64.lo"
3059     GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha1-avx-amd64.lo"
3060     GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha1-avx-bmi2-amd64.lo"
3061     GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha1-avx2-bmi2-amd64.lo"
3062   ;;
3063   arm*-*-*)
3064     # Build with the assembly implementation
3065     GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha1-armv7-neon.lo"
3066     GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha1-armv8-aarch32-ce.lo"
3067   ;;
3068   aarch64-*-*)
3069     # Build with the assembly implementation
3070     GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha1-armv8-aarch64-ce.lo"
3071   ;;
3072 esac
3073
3074 case "$mpi_cpu_arch" in
3075   x86)
3076     # Build with the SHAEXT implementation
3077     GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS sha1-intel-shaext.lo"
3078   ;;
3079 esac
3080
3081 # Arch specific GCM implementations
3082 case "${host}" in
3083   i?86-*-* | x86_64-*-*)
3084     GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS cipher-gcm-intel-pclmul.lo"
3085   ;;
3086   arm*-*-*)
3087     GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS cipher-gcm-armv7-neon.lo"
3088     GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS cipher-gcm-armv8-aarch32-ce.lo"
3089   ;;
3090   aarch64-*-*)
3091     GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS cipher-gcm-armv8-aarch64-ce.lo"
3092   ;;
3093   powerpc64le-*-* | powerpc64-*-* | powerpc-*-*)
3094     GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS cipher-gcm-ppc.lo"
3095   ;;
3096 esac
3097
3098 # Arch specific MAC implementations
3099 case "${host}" in
3100   s390x-*-*)
3101     GCRYPT_ASM_DIGESTS="$GCRYPT_ASM_DIGESTS poly1305-s390x.lo"
3102   ;;
3103 esac
3104
3105 LIST_MEMBER(scrypt, $enabled_kdfs)
3106 if test "$found" = "1" ; then
3107    GCRYPT_KDFS="$GCRYPT_KDFS scrypt.lo"
3108    AC_DEFINE(USE_SCRYPT, 1, [Defined if this module should be included])
3109 fi
3110
3111 LIST_MEMBER(getentropy, $random_modules)
3112 if test "$found" = "1" ; then
3113    GCRYPT_RANDOM="$GCRYPT_RANDOM rndgetentropy.lo"
3114    AC_DEFINE(USE_RNDGETENTROPY, 1, [Defined if the getentropy RNG should be used.])
3115 fi
3116
3117 LIST_MEMBER(linux, $random_modules)
3118 if test "$found" = "1" ; then
3119    GCRYPT_RANDOM="$GCRYPT_RANDOM rndoldlinux.lo"
3120    AC_DEFINE(USE_RNDOLDLINUX, 1, [Defined if the /dev/random RNG should be used.])
3121 fi
3122
3123 LIST_MEMBER(unix, $random_modules)
3124 if test "$found" = "1" ; then
3125    GCRYPT_RANDOM="$GCRYPT_RANDOM rndunix.lo"
3126    AC_DEFINE(USE_RNDUNIX, 1, [Defined if the default Unix RNG should be used.])
3127 fi
3128
3129 LIST_MEMBER(egd, $random_modules)
3130 if test "$found" = "1" ; then
3131    GCRYPT_RANDOM="$GCRYPT_RANDOM rndegd.lo"
3132    AC_DEFINE(USE_RNDEGD, 1, [Defined if the EGD based RNG should be used.])
3133 fi
3134
3135 LIST_MEMBER(w32, $random_modules)
3136 if test "$found" = "1" ; then
3137    GCRYPT_RANDOM="$GCRYPT_RANDOM rndw32.lo"
3138    AC_DEFINE(USE_RNDW32, 1,
3139              [Defined if the Windows specific RNG should be used.])
3140 fi
3141
3142 LIST_MEMBER(w32ce, $random_modules)
3143 if test "$found" = "1" ; then
3144    GCRYPT_RANDOM="$GCRYPT_RANDOM rndw32ce.lo"
3145    AC_DEFINE(USE_RNDW32CE, 1,
3146              [Defined if the WindowsCE specific RNG should be used.])
3147 fi
3148
3149 if test "$try_asm_modules" = yes ; then
3150   # Build with assembly implementations
3151   GCRYPT_CIPHERS="$GCRYPT_CIPHERS $GCRYPT_ASM_CIPHERS"
3152   GCRYPT_DIGESTS="$GCRYPT_DIGESTS $GCRYPT_ASM_DIGESTS"
3153 fi
3154
3155 AC_SUBST([GCRYPT_CIPHERS])
3156 AC_SUBST([GCRYPT_PUBKEY_CIPHERS])
3157 AC_SUBST([GCRYPT_DIGESTS])
3158 AC_SUBST([GCRYPT_KDFS])
3159 AC_SUBST([GCRYPT_RANDOM])
3160
3161 AC_SUBST(LIBGCRYPT_CIPHERS, $enabled_ciphers)
3162 AC_SUBST(LIBGCRYPT_PUBKEY_CIPHERS, $enabled_pubkey_ciphers)
3163 AC_SUBST(LIBGCRYPT_DIGESTS, $enabled_digests)
3164
3165 # For printing the configuration we need a colon separated list of
3166 # algorithm names.
3167 tmp=`echo "$enabled_ciphers" | tr ' ' : `
3168 AC_DEFINE_UNQUOTED(LIBGCRYPT_CIPHERS, "$tmp",
3169                    [List of available cipher algorithms])
3170 tmp=`echo "$enabled_pubkey_ciphers" | tr ' ' : `
3171 AC_DEFINE_UNQUOTED(LIBGCRYPT_PUBKEY_CIPHERS, "$tmp",
3172                    [List of available public key cipher algorithms])
3173 tmp=`echo "$enabled_digests" | tr ' ' : `
3174 AC_DEFINE_UNQUOTED(LIBGCRYPT_DIGESTS, "$tmp",
3175                    [List of available digest algorithms])
3176 tmp=`echo "$enabled_kdfs" | tr ' ' : `
3177 AC_DEFINE_UNQUOTED(LIBGCRYPT_KDFS, "$tmp",
3178                    [List of available KDF algorithms])
3179
3180
3181 #
3182 # Define conditional sources depending on the used hardware platform.
3183 # Note that all possible modules must also be listed in
3184 # src/Makefile.am (EXTRA_libgcrypt_la_SOURCES).
3185 #
3186 GCRYPT_HWF_MODULES=
3187 case "$mpi_cpu_arch" in
3188      x86)
3189         AC_DEFINE(HAVE_CPU_ARCH_X86, 1,   [Defined for the x86 platforms])
3190         GCRYPT_HWF_MODULES="libgcrypt_la-hwf-x86.lo"
3191         ;;
3192      alpha)
3193         AC_DEFINE(HAVE_CPU_ARCH_ALPHA, 1, [Defined for Alpha platforms])
3194         ;;
3195      sparc)
3196         AC_DEFINE(HAVE_CPU_ARCH_SPARC, 1, [Defined for SPARC platforms])
3197         ;;
3198      mips)
3199         AC_DEFINE(HAVE_CPU_ARCH_MIPS, 1,  [Defined for MIPS platforms])
3200         ;;
3201      m68k)
3202         AC_DEFINE(HAVE_CPU_ARCH_M68K, 1,  [Defined for M68k platforms])
3203         ;;
3204      ppc)
3205         AC_DEFINE(HAVE_CPU_ARCH_PPC, 1,   [Defined for PPC platforms])
3206         GCRYPT_HWF_MODULES="libgcrypt_la-hwf-ppc.lo"
3207         ;;
3208      arm)
3209         AC_DEFINE(HAVE_CPU_ARCH_ARM, 1,   [Defined for ARM platforms])
3210         GCRYPT_HWF_MODULES="libgcrypt_la-hwf-arm.lo"
3211         ;;
3212      aarch64)
3213         AC_DEFINE(HAVE_CPU_ARCH_ARM, 1,   [Defined for ARM AArch64 platforms])
3214         GCRYPT_HWF_MODULES="libgcrypt_la-hwf-arm.lo"
3215         ;;
3216      s390x)
3217         AC_DEFINE(HAVE_CPU_ARCH_S390X, 1, [Defined for s390x/zSeries platforms])
3218         GCRYPT_HWF_MODULES="libgcrypt_la-hwf-s390x.lo"
3219         ;;
3220 esac
3221 AC_SUBST([GCRYPT_HWF_MODULES])
3222
3223
3224 #
3225 # Option to disable building of doc file
3226 #
3227 build_doc=yes
3228 AC_ARG_ENABLE([doc], AS_HELP_STRING([--disable-doc],
3229                                     [do not build the documentation]),
3230                      build_doc=$enableval, build_doc=yes)
3231 AM_CONDITIONAL([BUILD_DOC], [test "x$build_doc" != xno])
3232
3233
3234 #
3235 # Provide information about the build.
3236 #
3237 BUILD_REVISION="mym4_revision"
3238 AC_SUBST(BUILD_REVISION)
3239 AC_DEFINE_UNQUOTED(BUILD_REVISION, "$BUILD_REVISION",
3240                    [GIT commit id revision used to build this package])
3241
3242 changequote(,)dnl
3243 BUILD_VERSION=`echo "$PACKAGE_VERSION" | sed 's/\([0-9.]*\).*/\1./'`
3244 changequote([,])dnl
3245 BUILD_VERSION="${BUILD_VERSION}mym4_revision_dec"
3246 BUILD_FILEVERSION=`echo "${BUILD_VERSION}" | tr . ,`
3247 AC_SUBST(BUILD_VERSION)
3248 AC_SUBST(BUILD_FILEVERSION)
3249
3250 AC_ARG_ENABLE([build-timestamp],
3251   AS_HELP_STRING([--enable-build-timestamp],
3252                  [set an explicit build timestamp for reproducibility.
3253                   (default is the current time in ISO-8601 format)]),
3254      [if test "$enableval" = "yes"; then
3255         BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M+0000 2>/dev/null || date`
3256       else
3257         BUILD_TIMESTAMP="$enableval"
3258       fi],
3259      [BUILD_TIMESTAMP="<none>"])
3260 AC_SUBST(BUILD_TIMESTAMP)
3261 AC_DEFINE_UNQUOTED(BUILD_TIMESTAMP, "$BUILD_TIMESTAMP",
3262                    [The time this package was configured for a build])
3263
3264
3265 # And create the files.
3266 AC_CONFIG_FILES([
3267 Makefile
3268 m4/Makefile
3269 compat/Makefile
3270 mpi/Makefile
3271 cipher/Makefile
3272 random/Makefile
3273 doc/Makefile
3274 src/Makefile
3275 src/gcrypt.h
3276 src/libgcrypt-config
3277 src/libgcrypt.pc
3278 src/versioninfo.rc
3279 tests/Makefile
3280 ])
3281 AC_CONFIG_FILES([tests/hashtest-256g], [chmod +x tests/hashtest-256g])
3282 AC_CONFIG_FILES([tests/basic-disable-all-hwf], [chmod +x tests/basic-disable-all-hwf])
3283 AC_OUTPUT
3284
3285
3286 detection_module="${GCRYPT_HWF_MODULES%.lo}"
3287 test -n "$detection_module" || detection_module="none"
3288
3289 # Give some feedback
3290 GCRY_MSG_SHOW([],[])
3291 GCRY_MSG_SHOW([Libgcrypt],[v${VERSION} has been configured as follows:])
3292 GCRY_MSG_SHOW([],[])
3293 GCRY_MSG_SHOW([Platform:                 ],[$PRINTABLE_OS_NAME ($host)])
3294 GCRY_MSG_SHOW([Hardware detection module:],[$detection_module])
3295 GCRY_MSG_WRAP([Enabled cipher algorithms:],[$enabled_ciphers])
3296 GCRY_MSG_WRAP([Enabled digest algorithms:],[$enabled_digests])
3297 GCRY_MSG_WRAP([Enabled kdf algorithms:   ],[$enabled_kdfs])
3298 GCRY_MSG_WRAP([Enabled pubkey algorithms:],[$enabled_pubkey_ciphers])
3299 GCRY_MSG_SHOW([Random number generator:  ],[$random])
3300 GCRY_MSG_SHOW([Try using jitter entropy: ],[$jentsupport])
3301 GCRY_MSG_SHOW([Using linux capabilities: ],[$use_capabilities])
3302 GCRY_MSG_SHOW([FIPS module version:      ],[$fips_module_version])
3303 GCRY_MSG_SHOW([Try using Padlock crypto: ],[$padlocksupport])
3304 GCRY_MSG_SHOW([Try using AES-NI crypto:  ],[$aesnisupport])
3305 GCRY_MSG_SHOW([Try using Intel SHAEXT:   ],[$shaextsupport])
3306 GCRY_MSG_SHOW([Try using Intel PCLMUL:   ],[$pclmulsupport])
3307 GCRY_MSG_SHOW([Try using Intel SSE4.1:   ],[$sse41support])
3308 GCRY_MSG_SHOW([Try using DRNG (RDRAND):  ],[$drngsupport])
3309 GCRY_MSG_SHOW([Try using Intel AVX:      ],[$avxsupport])
3310 GCRY_MSG_SHOW([Try using Intel AVX2:     ],[$avx2support])
3311 GCRY_MSG_SHOW([Try using ARM NEON:       ],[$neonsupport])
3312 GCRY_MSG_SHOW([Try using ARMv8 crypto:   ],[$armcryptosupport])
3313 GCRY_MSG_SHOW([Try using PPC crypto:     ],[$ppccryptosupport])
3314 GCRY_MSG_SHOW([],[])
3315
3316 if test "x${gpg_config_script_warn}" != x; then
3317 cat <<G10EOF
3318         Mismatches between the target platform and the to
3319         be used libraries have been been detected for:
3320          ${gpg_config_script_warn}
3321         Please check above for warning messages.
3322
3323 G10EOF
3324 fi
3325
3326 if test "$gcry_cv_gcc_attribute_aligned" != "yes" ; then
3327 cat <<G10EOF
3328    Please not that your compiler does not support the GCC style
3329    aligned attribute. Using this software may evoke bus errors.
3330
3331 G10EOF
3332 fi
3333
3334 if test -n "$gpl"; then
3335   echo "Please note that you are building a version of Libgcrypt with"
3336   echo "  $gpl"
3337   echo "included.  These parts are licensed under the GPL and thus the"
3338   echo "use of this library has to comply with the conditions of the GPL."
3339   echo ""
3340 fi