blob: 28044b2e4b15bb52fec81f16a2c9c9a95f9c5c93 [file] [edit]
dnl # SPDX-License-Identifier: CDDL-1.0
dnl #
dnl # Check for the in-kernel crypto API (AEAD and shash).
dnl #
dnl # This can only succeed when the kernel exports these symbols with a
dnl # license compatible with the module license. As of Linux 7.1.5 they
dnl # are exported GPL-only, so with the standard CDDL module license this
dnl # only has an effect when built against a patched kernel that exports
dnl # them non-GPL (or when the module license is overridden).
dnl #
dnl # The link test exercises every interface used by the kernel crypto API
dnl # backend (zio_crypt_os_kcapi.c), so that a future API change makes
dnl # this check fail and the ICP backend be used, rather than breaking
dnl # the module build.
dnl #
dnl # However, the link test cannot by itself tell whether this kernel has
dnl # the crypto API at all: configure does not link when configuring for
dnl # builtin, and otherwise only warns about undefined symbols. So, we
dnl # separately check that CRYPTO_AEAD2 and CRYPTO_HASH2 are enabled (and
dnl # for a builtin build, that they are builtin).
dnl #
dnl # A failure of only the license test is the expected case and is quiet.
dnl # If the probe does not compile at all, configure warns, since that
dnl # means the kernel API changed and the backend needs updating.
dnl #
AC_DEFUN([ZFS_AC_KERNEL_SRC_CRYPTO], [
ZFS_LINUX_TEST_SRC([kernel_crypto], [
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/scatterlist.h>
#include <crypto/aead.h>
#include <crypto/hash.h>
], [
static struct shash_desc desc_storage;
struct crypto_aead *aead;
struct aead_request *req;
struct crypto_shash *shash;
struct shash_desc *desc = &desc_storage;
struct scatterlist sg[2];
u8 buf[16] = {0};
int err;
DECLARE_CRYPTO_WAIT(wait);
aead = crypto_alloc_aead("gcm(aes)", 0, 0);
(void) crypto_aead_setkey(aead, buf, sizeof (buf));
(void) crypto_aead_setauthsize(aead, sizeof (buf));
(void) crypto_aead_ivsize(aead);
req = kmalloc(sizeof (*req) + crypto_aead_reqsize(aead),
GFP_KERNEL);
aead_request_set_tfm(req, aead);
aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG |
CRYPTO_TFM_REQ_MAY_SLEEP, crypto_req_done, &wait);
sg_init_table(sg, 2);
sg_set_buf(&sg[0], buf, sizeof (buf));
sg_set_page(&sg[1], vmalloc_to_page(buf), sizeof (buf),
offset_in_page(buf));
(void) sg_next(sg);
(void) is_vmalloc_addr(buf);
aead_request_set_ad(req, 0);
aead_request_set_crypt(req, sg, sg, sizeof (buf), buf);
err = crypto_wait_req(crypto_aead_encrypt(req), &wait);
err = crypto_wait_req(crypto_aead_decrypt(req), &wait);
(void) err;
kfree(req);
crypto_free_aead(aead);
shash = crypto_alloc_shash("hmac(sha512)", 0, 0);
(void) crypto_shash_setkey(shash, buf, sizeof (buf));
(void) crypto_shash_descsize(shash);
{
SHASH_DESC_ON_STACK(sdesc, shash);
sdesc->tfm = shash;
(void) crypto_shash_digest(sdesc, buf, sizeof (buf), buf);
shash_desc_zero(sdesc);
}
desc->tfm = shash;
(void) crypto_shash_init(desc);
(void) crypto_shash_update(desc, buf, sizeof (buf));
(void) crypto_shash_final(desc, buf);
crypto_free_shash(shash);
], [], [ZFS_META_LICENSE])
ZFS_LINUX_TEST_SRC([kernel_crypto_enabled], [
#if !IS_ENABLED(CONFIG_CRYPTO_AEAD2) || \
!IS_ENABLED(CONFIG_CRYPTO_HASH2)
#error "kernel crypto AEAD or hash API not enabled"
#endif
], [])
ZFS_LINUX_TEST_SRC([kernel_crypto_builtin], [
#if !IS_BUILTIN(CONFIG_CRYPTO_AEAD2) || \
!IS_BUILTIN(CONFIG_CRYPTO_HASH2)
#error "kernel crypto AEAD or hash API not builtin"
#endif
], [])
])
AC_DEFUN([ZFS_AC_KERNEL_CRYPTO], [
AC_MSG_CHECKING([whether kernel crypto API is available])
ZFS_LINUX_TEST_RESULT([kernel_crypto_license], [
AS_IF([test "x$enable_linux_builtin" = xyes], [
ZFS_LINUX_TEST_RESULT([kernel_crypto_builtin],
[kernel_crypto=yes], [kernel_crypto=no])
], [
ZFS_LINUX_TEST_RESULT([kernel_crypto_enabled],
[kernel_crypto=yes], [kernel_crypto=no])
])
], [
kernel_crypto=no
ZFS_LINUX_TEST_RESULT([kernel_crypto], [], [kernel_crypto=stale])
])
AS_IF([test "x$kernel_crypto" = xyes], [
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_KERNEL_CRYPTO, 1,
[kernel crypto API is available])
], [
AC_MSG_RESULT(no)
AS_IF([test "x$kernel_crypto" = xstale], [
AC_MSG_WARN([the kernel crypto API probe does not compile
*** against this kernel, so the ICP will be used for encryption;
*** zio_crypt_os_kcapi.c may need updating for this kernel.])
])
])
])