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