Apply Crypto API wrappers to the exported crypto symbol in CONFIG_CRYPTO_CRYPTD-related crypto to convert them into pluggable interface.
This patch is partially based on work by Vegard Nossum, with modifications. Unlike the original, we do not include DEFINE_CRYPTO_API since only one copy of the crypto symbols is kept, either in the crypto module or in the main kernel, and we ensure such wrapper do not have impact on crypto already chosen built as module. Co-developed-by: Vegard Nossum <[email protected]> Signed-off-by: Jay Wang <[email protected]> --- crypto/Makefile | 2 +- crypto/cryptd.c | 4 +-- crypto/fips140/fips140-api.c | 22 ++++++++++++++ include/crypto/cryptd.h | 56 +++++++++++++++++++++++++----------- 4 files changed, 65 insertions(+), 19 deletions(-) diff --git a/crypto/Makefile b/crypto/Makefile index b371a8788d39..f029e0decaa1 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -125,7 +125,7 @@ endif CFLAGS_aegis128-neon-inner.o += -isystem $(shell $(CC) -print-file-name=include) crypto-objs-$(CONFIG_CRYPTO_PCRYPT) += pcrypt.o -obj-$(CONFIG_CRYPTO_CRYPTD) += cryptd.o +crypto-objs-$(CONFIG_CRYPTO_CRYPTD) += cryptd.o obj-$(CONFIG_CRYPTO_DES) += des_generic.o obj-$(CONFIG_CRYPTO_FCRYPT) += fcrypt.o obj-$(CONFIG_CRYPTO_BLOWFISH) += blowfish_generic.o diff --git a/crypto/cryptd.c b/crypto/cryptd.c index cd38f4676176..8b1ba67d752c 100644 --- a/crypto/cryptd.c +++ b/crypto/cryptd.c @@ -1145,8 +1145,8 @@ static void __exit cryptd_exit(void) crypto_unregister_template(&cryptd_tmpl); } -module_init(cryptd_init); -module_exit(cryptd_exit); +crypto_module_init(cryptd_init); +crypto_module_exit(cryptd_exit); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Software async crypto daemon"); diff --git a/crypto/fips140/fips140-api.c b/crypto/fips140/fips140-api.c index 3c6dfcac5db5..1452439319cc 100644 --- a/crypto/fips140/fips140-api.c +++ b/crypto/fips140/fips140-api.c @@ -622,3 +622,25 @@ DEFINE_CRYPTO_API_STUB(ecc_point_is_zero); DEFINE_CRYPTO_API_STUB(ecc_point_mult_shamir); #endif +/* + * crypto/cryptd.c + */ +#if IS_BUILTIN(CONFIG_CRYPTO_CRYPTD) + +#include <crypto/cryptd.h> + +DEFINE_CRYPTO_API_STUB(cryptd_alloc_skcipher); +DEFINE_CRYPTO_API_STUB(cryptd_skcipher_child); +DEFINE_CRYPTO_API_STUB(cryptd_skcipher_queued); +DEFINE_CRYPTO_API_STUB(cryptd_free_skcipher); +DEFINE_CRYPTO_API_STUB(cryptd_alloc_ahash); +DEFINE_CRYPTO_API_STUB(cryptd_ahash_child); +DEFINE_CRYPTO_API_STUB(cryptd_shash_desc); +DEFINE_CRYPTO_API_STUB(cryptd_ahash_queued); +DEFINE_CRYPTO_API_STUB(cryptd_free_ahash); +DEFINE_CRYPTO_API_STUB(cryptd_alloc_aead); +DEFINE_CRYPTO_API_STUB(cryptd_aead_child); +DEFINE_CRYPTO_API_STUB(cryptd_aead_queued); +DEFINE_CRYPTO_API_STUB(cryptd_free_aead); + +#endif diff --git a/include/crypto/cryptd.h b/include/crypto/cryptd.h index 796d986e58e1..35b4d06e41f5 100644 --- a/include/crypto/cryptd.h +++ b/include/crypto/cryptd.h @@ -13,6 +13,7 @@ #ifndef _CRYPTO_CRYPT_H #define _CRYPTO_CRYPT_H +#include <crypto/api.h> #include <linux/types.h> #include <crypto/aead.h> @@ -24,12 +25,19 @@ struct cryptd_skcipher { }; /* alg_name should be algorithm to be cryptd-ed */ -struct cryptd_skcipher *cryptd_alloc_skcipher(const char *alg_name, - u32 type, u32 mask); -struct crypto_skcipher *cryptd_skcipher_child(struct cryptd_skcipher *tfm); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_CRYPTD, cryptd_alloc_skcipher, struct cryptd_skcipher *, + (const char *alg_name, u32 type, u32 mask), + (alg_name, type, mask)); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_CRYPTD, cryptd_skcipher_child, struct crypto_skcipher *, + (struct cryptd_skcipher *tfm), + (tfm)); /* Must be called without moving CPUs. */ -bool cryptd_skcipher_queued(struct cryptd_skcipher *tfm); -void cryptd_free_skcipher(struct cryptd_skcipher *tfm); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_CRYPTD, cryptd_skcipher_queued, bool, + (struct cryptd_skcipher *tfm), + (tfm)); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_CRYPTD, cryptd_free_skcipher, void, + (struct cryptd_skcipher *tfm), + (tfm)); struct cryptd_ahash { struct crypto_ahash base; @@ -42,13 +50,22 @@ static inline struct cryptd_ahash *__cryptd_ahash_cast( } /* alg_name should be algorithm to be cryptd-ed */ -struct cryptd_ahash *cryptd_alloc_ahash(const char *alg_name, - u32 type, u32 mask); -struct crypto_shash *cryptd_ahash_child(struct cryptd_ahash *tfm); -struct shash_desc *cryptd_shash_desc(struct ahash_request *req); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_CRYPTD, cryptd_alloc_ahash, struct cryptd_ahash *, + (const char *alg_name, u32 type, u32 mask), + (alg_name, type, mask)); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_CRYPTD, cryptd_ahash_child, struct crypto_shash *, + (struct cryptd_ahash *tfm), + (tfm)); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_CRYPTD, cryptd_shash_desc, struct shash_desc *, + (struct ahash_request *req), + (req)); /* Must be called without moving CPUs. */ -bool cryptd_ahash_queued(struct cryptd_ahash *tfm); -void cryptd_free_ahash(struct cryptd_ahash *tfm); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_CRYPTD, cryptd_ahash_queued, bool, + (struct cryptd_ahash *tfm), + (tfm)); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_CRYPTD, cryptd_free_ahash, void, + (struct cryptd_ahash *tfm), + (tfm)); struct cryptd_aead { struct crypto_aead base; @@ -60,13 +77,20 @@ static inline struct cryptd_aead *__cryptd_aead_cast( return (struct cryptd_aead *)tfm; } -struct cryptd_aead *cryptd_alloc_aead(const char *alg_name, - u32 type, u32 mask); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_CRYPTD, cryptd_alloc_aead, struct cryptd_aead *, + (const char *alg_name, u32 type, u32 mask), + (alg_name, type, mask)); -struct crypto_aead *cryptd_aead_child(struct cryptd_aead *tfm); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_CRYPTD, cryptd_aead_child, struct crypto_aead *, + (struct cryptd_aead *tfm), + (tfm)); /* Must be called without moving CPUs. */ -bool cryptd_aead_queued(struct cryptd_aead *tfm); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_CRYPTD, cryptd_aead_queued, bool, + (struct cryptd_aead *tfm), + (tfm)); -void cryptd_free_aead(struct cryptd_aead *tfm); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_CRYPTD, cryptd_free_aead, void, + (struct cryptd_aead *tfm), + (tfm)); #endif -- 2.47.3
