This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit b89932d913330217aa2bd0438dd72db1c9b451c6 Author: makejian <[email protected]> AuthorDate: Thu Aug 13 14:04:27 2026 +0800 crypto: split backend registration from the /dev/crypto interface devcrypto_register() created the /dev/crypto character device and also registered the software and hardware crypto backends into the driver table. The two serve different users: the driver table is what in-kernel callers of crypto_newsession() / crypto_invoke() use, while /dev/crypto is the BSD compatible ioctl interface for user space. With both in one function a build could not have the backends without the character device. Move the backend registration (swcr_init(), swkey_init(), hwcr_init()) into a new crypto_backends_init() in crypto/backends.c, so that a build without the character device does not need to compile cryptodev.c. devcrypto_register() now only registers /dev/crypto, and drivers_initialize() calls the two independently. Add CRYPTO_BACKENDS for the registration. It has no prompt and is selected by CRYPTO_CRYPTODEV, because a /dev/crypto with no backend behind it can only fail, so existing configurations are unchanged. An in-kernel crypto user can select CRYPTO_BACKENDS without CRYPTO_CRYPTODEV. The software cipher, software key management and hardware options describe backends, so they now depend on CRYPTO_BACKENDS instead of CRYPTO_CRYPTODEV. Signed-off-by: makejian <[email protected]> --- crypto/CMakeLists.txt | 8 ++++-- crypto/Kconfig | 23 +++++++++++++-- crypto/Makefile | 4 +++ crypto/backends.c | 63 +++++++++++++++++++++++++++++++++++++++++ crypto/cryptodev.c | 12 -------- drivers/drivers_initialize.c | 4 +++ include/nuttx/drivers/drivers.h | 13 +++++++++ 7 files changed, 110 insertions(+), 17 deletions(-) diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt index 1f63bf18de8..251b3ea54f8 100644 --- a/crypto/CMakeLists.txt +++ b/crypto/CMakeLists.txt @@ -26,8 +26,8 @@ if(CONFIG_CRYPTO) # cryptodev support - if(CONFIG_CRYPTO_CRYPTODEV) - list(APPEND SRCS cryptodev.c) + if(CONFIG_CRYPTO_BACKENDS) + list(APPEND SRCS backends.c) if(CONFIG_CRYPTO_CRYPTODEV_SOFTWARE_CRYPTO OR CONFIG_CRYPTO_CRYPTODEV_SOFTWARE_KEYMGMT) list(APPEND SRCS cryptosoft.c) @@ -35,6 +35,10 @@ if(CONFIG_CRYPTO) endif() endif() + if(CONFIG_CRYPTO_CRYPTODEV) + list(APPEND SRCS cryptodev.c) + endif() + # Software crypto library if(CONFIG_CRYPTO_SW_AES) diff --git a/crypto/Kconfig b/crypto/Kconfig index 568bbec34cb..e8b8d23c255 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -56,20 +56,37 @@ config CRYPTO_AES256_DISABLE endif # CRYPTO_ALGTEST +config CRYPTO_BACKENDS + bool + default n + ---help--- + Register the software and hardware crypto backends into the + driver table, so in-kernel users can reach them through + crypto_newsession() and crypto_invoke(). This is independent of + the /dev/crypto interface: a build that only has in-kernel users + needs this option and not the character device. + config CRYPTO_CRYPTODEV bool "cryptodev support" depends on ALLOW_BSD_COMPONENTS + select CRYPTO_BACKENDS default n + ---help--- + The BSD compatible /dev/crypto character device, which lets + user-space libraries such as OpenSSL and GnuTLS reach the crypto + backends. In-kernel users call the crypto API directly and do + not need it, so a core that has no user-space crypto client can + enable CRYPTO_BACKENDS alone and leave the device out. config CRYPTO_CRYPTODEV_SOFTWARE_CRYPTO bool "cryptodev software cipher support" - depends on CRYPTO_CRYPTODEV && CRYPTO_SW_AES + depends on CRYPTO_BACKENDS && CRYPTO_SW_AES select CRYPTO_CURVE25519 default n config CRYPTO_CRYPTODEV_SOFTWARE_KEYMGMT bool "cryptodev software key management support" - depends on CRYPTO_CRYPTODEV && !MTD_CONFIG_NONE + depends on CRYPTO_BACKENDS && !MTD_CONFIG_NONE select CRYPTO_CURVE25519 default n @@ -95,7 +112,7 @@ endif # CRYPTO_CRYPTODEV_SOFTWARE_KEYMGMT config CRYPTO_CRYPTODEV_HARDWARE bool "cryptodev hardware support" - depends on CRYPTO_CRYPTODEV + depends on CRYPTO_BACKENDS default n config CRYPTO_SW_AES diff --git a/crypto/Makefile b/crypto/Makefile index 31ec601fe00..9a2d392261a 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -32,6 +32,10 @@ CRYPTO_CSRCS += crypto.c testmngr.c ifeq ($(CONFIG_CRYPTO_CRYPTODEV),y) CRYPTO_CSRCS += cryptodev.c +endif + +ifeq ($(CONFIG_CRYPTO_BACKENDS),y) + CRYPTO_CSRCS += backends.c ifneq ($(CONFIG_CRYPTO_CRYPTODEV_SOFTWARE_CRYPTO)$(CONFIG_CRYPTO_CRYPTODEV_SOFTWARE_KEYMGMT),) CRYPTO_CSRCS += cryptosoft.c CRYPTO_CSRCS += xform.c diff --git a/crypto/backends.c b/crypto/backends.c new file mode 100644 index 00000000000..db5e88aee64 --- /dev/null +++ b/crypto/backends.c @@ -0,0 +1,63 @@ +/**************************************************************************** + * crypto/backends.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <crypto/cryptodev.h> +#include <crypto/cryptosoft.h> +#include <nuttx/drivers/drivers.h> + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: crypto_backends_init + * + * Description: + * Put the crypto backends into the driver table, making them reachable + * through crypto_newsession() / crypto_invoke(). The /dev/crypto interface + * is one user of those backends rather than a prerequisite for them, so it + * is registered separately by devcrypto_register(): a build whose only + * crypto users are in the kernel needs this function and not the character + * device. + * + ****************************************************************************/ + +void crypto_backends_init(void) +{ +#ifdef CONFIG_CRYPTO_CRYPTODEV_SOFTWARE_CRYPTO + swcr_init(); +#endif + +#ifdef CONFIG_CRYPTO_CRYPTODEV_SOFTWARE_KEYMGMT + swkey_init(); +#endif + +#ifdef CONFIG_CRYPTO_CRYPTODEV_HARDWARE + hwcr_init(); +#endif +} diff --git a/crypto/cryptodev.c b/crypto/cryptodev.c index 4bff8d6c486..fda2faf172a 100644 --- a/crypto/cryptodev.c +++ b/crypto/cryptodev.c @@ -1176,16 +1176,4 @@ static int csefree(FAR struct csession *cse) void devcrypto_register(void) { register_driver("/dev/crypto", &g_cryptoops, 0660, NULL); - -#ifdef CONFIG_CRYPTO_CRYPTODEV_SOFTWARE_CRYPTO - swcr_init(); -#endif - -#ifdef CONFIG_CRYPTO_CRYPTODEV_SOFTWARE_KEYMGMT - swkey_init(); -#endif - -#ifdef CONFIG_CRYPTO_CRYPTODEV_HARDWARE - hwcr_init(); -#endif } diff --git a/drivers/drivers_initialize.c b/drivers/drivers_initialize.c index c4e831a38e9..5be91008817 100644 --- a/drivers/drivers_initialize.c +++ b/drivers/drivers_initialize.c @@ -223,6 +223,10 @@ void drivers_initialize(void) up_cryptoinitialize(); #endif +#ifdef CONFIG_CRYPTO_BACKENDS + crypto_backends_init(); +#endif + #ifdef CONFIG_CRYPTO_CRYPTODEV devcrypto_register(); #endif diff --git a/include/nuttx/drivers/drivers.h b/include/nuttx/drivers/drivers.h index edae37c3ffd..a95a9740032 100644 --- a/include/nuttx/drivers/drivers.h +++ b/include/nuttx/drivers/drivers.h @@ -142,6 +142,19 @@ void devurandom_register(void); void devcrypto_register(void); +/**************************************************************************** + * Name: crypto_backends_init + * + * Description: + * Register the software and hardware crypto backends into the driver + * table, making them reachable through the in-kernel crypto API. + * Independent of devcrypto_register(), which only creates the + * /dev/crypto interface. + * + ****************************************************************************/ + +void crypto_backends_init(void); + /**************************************************************************** * Name: devmem_register *
