test-framework-sh: Fix side effect on dfa tests (regression 2024-06-11).
[gnulib.git] / m4 / af_alg.m4
blob33b749456409bd50b550d25908f3196c774edde9
1 # af_alg.m4
2 # serial 6
3 dnl Copyright 2018-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 dnl From Matteo Croce.
10 AC_DEFUN_ONCE([gl_AF_ALG],
12   AC_REQUIRE([gl_SYS_SOCKET_H])
13   AC_REQUIRE([AC_C_INLINE])
15   dnl Check whether linux/if_alg.h has needed features.
16   AC_CACHE_CHECK([whether linux/if_alg.h has struct sockaddr_alg.],
17     [gl_cv_header_linux_if_alg_salg],
18     [AC_COMPILE_IFELSE(
19        [AC_LANG_PROGRAM([[#include <sys/socket.h>
20                           #include <linux/if_alg.h>
21                           struct sockaddr_alg salg = {
22                             .salg_family = AF_ALG,
23                             .salg_type = "hash",
24                             .salg_name = "sha1",
25                           };]])],
26        [gl_cv_header_linux_if_alg_salg=yes],
27        [gl_cv_header_linux_if_alg_salg=no])])
28   if test "$gl_cv_header_linux_if_alg_salg" = yes; then
29     AC_DEFINE([HAVE_LINUX_IF_ALG_H], [1],
30       [Define to 1 if you have 'struct sockaddr_alg' defined.])
31   fi
33   dnl The default is to not use AF_ALG if available,
34   dnl as it's system dependent as to whether the kernel
35   dnl routines are faster than libcrypto for example.
36   use_af_alg=no
37   AC_ARG_WITH([linux-crypto],
38     [AS_HELP_STRING([[--with-linux-crypto]],
39        [use Linux kernel cryptographic API (if available) for the hash functions
40         MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512 on files])],
41     [use_af_alg=$withval],
42     [use_af_alg=no])
43   dnl We cannot use it if it is not available.
44   if test "$gl_cv_header_linux_if_alg_salg" != yes; then
45     if test "$use_af_alg" != no; then
46       AC_MSG_WARN([Linux kernel cryptographic API not found])
47     fi
48     use_af_alg=no
49   fi
51   if test "$use_af_alg" != no; then
52     USE_AF_ALG=1
53   else
54     USE_AF_ALG=0
55   fi
56   AC_DEFINE_UNQUOTED([USE_LINUX_CRYPTO_API], [$USE_AF_ALG],
57     [Define to 1 if you want to use the Linux kernel cryptographic API.])