Use CRYPTO_API() etc. from include/crypto/api.h in preparation for compilation as part of support for FIPS 140 standalone modules. Generated using: ./fipsify.py --config CONFIG_CRYPTO_CRYPTD --source crypto/cryptd.c --header include/crypto/cryptd.h Signed-off-by: Vegard Nossum <vegard.nossum@xxxxxxxxxx> --- crypto/cryptd.c | 58 ++++++++++++++++++++--------------------- crypto/fips140-api.c | 23 ++++++++++++++++ include/crypto/cryptd.h | 56 +++++++++++++++++++++++++++------------ 3 files changed, 92 insertions(+), 45 deletions(-) diff --git a/crypto/cryptd.c b/crypto/cryptd.c index efff54e707cb..36aa07af29b2 100644 --- a/crypto/cryptd.c +++ b/crypto/cryptd.c @@ -646,7 +646,7 @@ static int cryptd_hash_import(struct ahash_request *req, const void *in) { struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); struct cryptd_hash_ctx *ctx = crypto_ahash_ctx(tfm); - struct shash_desc *desc = cryptd_shash_desc(req); + struct shash_desc *desc = CRYPTO_API(cryptd_shash_desc)(req); desc->tfm = ctx->child; @@ -952,7 +952,7 @@ static struct crypto_template cryptd_tmpl = { .module = THIS_MODULE, }; -struct cryptd_skcipher *cryptd_alloc_skcipher(const char *alg_name, +struct cryptd_skcipher *CRYPTO_API(cryptd_alloc_skcipher)(const char *alg_name, u32 type, u32 mask) { char cryptd_alg_name[CRYPTO_MAX_ALG_NAME]; @@ -977,34 +977,34 @@ struct cryptd_skcipher *cryptd_alloc_skcipher(const char *alg_name, return container_of(tfm, struct cryptd_skcipher, base); } -EXPORT_SYMBOL_GPL(cryptd_alloc_skcipher); +DEFINE_CRYPTO_API(cryptd_alloc_skcipher); -struct crypto_skcipher *cryptd_skcipher_child(struct cryptd_skcipher *tfm) +struct crypto_skcipher *CRYPTO_API(cryptd_skcipher_child)(struct cryptd_skcipher *tfm) { struct cryptd_skcipher_ctx *ctx = crypto_skcipher_ctx(&tfm->base); return ctx->child; } -EXPORT_SYMBOL_GPL(cryptd_skcipher_child); +DEFINE_CRYPTO_API(cryptd_skcipher_child); -bool cryptd_skcipher_queued(struct cryptd_skcipher *tfm) +bool CRYPTO_API(cryptd_skcipher_queued)(struct cryptd_skcipher *tfm) { struct cryptd_skcipher_ctx *ctx = crypto_skcipher_ctx(&tfm->base); return refcount_read(&ctx->refcnt) - 1; } -EXPORT_SYMBOL_GPL(cryptd_skcipher_queued); +DEFINE_CRYPTO_API(cryptd_skcipher_queued); -void cryptd_free_skcipher(struct cryptd_skcipher *tfm) +void CRYPTO_API(cryptd_free_skcipher)(struct cryptd_skcipher *tfm) { struct cryptd_skcipher_ctx *ctx = crypto_skcipher_ctx(&tfm->base); if (refcount_dec_and_test(&ctx->refcnt)) crypto_free_skcipher(&tfm->base); } -EXPORT_SYMBOL_GPL(cryptd_free_skcipher); +DEFINE_CRYPTO_API(cryptd_free_skcipher); -struct cryptd_ahash *cryptd_alloc_ahash(const char *alg_name, +struct cryptd_ahash *CRYPTO_API(cryptd_alloc_ahash)(const char *alg_name, u32 type, u32 mask) { char cryptd_alg_name[CRYPTO_MAX_ALG_NAME]; @@ -1027,41 +1027,41 @@ struct cryptd_ahash *cryptd_alloc_ahash(const char *alg_name, return __cryptd_ahash_cast(tfm); } -EXPORT_SYMBOL_GPL(cryptd_alloc_ahash); +DEFINE_CRYPTO_API(cryptd_alloc_ahash); -struct crypto_shash *cryptd_ahash_child(struct cryptd_ahash *tfm) +struct crypto_shash *CRYPTO_API(cryptd_ahash_child)(struct cryptd_ahash *tfm) { struct cryptd_hash_ctx *ctx = crypto_ahash_ctx(&tfm->base); return ctx->child; } -EXPORT_SYMBOL_GPL(cryptd_ahash_child); +DEFINE_CRYPTO_API(cryptd_ahash_child); -struct shash_desc *cryptd_shash_desc(struct ahash_request *req) +struct shash_desc *CRYPTO_API(cryptd_shash_desc)(struct ahash_request *req) { struct cryptd_hash_request_ctx *rctx = ahash_request_ctx(req); return &rctx->desc; } -EXPORT_SYMBOL_GPL(cryptd_shash_desc); +DEFINE_CRYPTO_API(cryptd_shash_desc); -bool cryptd_ahash_queued(struct cryptd_ahash *tfm) +bool CRYPTO_API(cryptd_ahash_queued)(struct cryptd_ahash *tfm) { struct cryptd_hash_ctx *ctx = crypto_ahash_ctx(&tfm->base); return refcount_read(&ctx->refcnt) - 1; } -EXPORT_SYMBOL_GPL(cryptd_ahash_queued); +DEFINE_CRYPTO_API(cryptd_ahash_queued); -void cryptd_free_ahash(struct cryptd_ahash *tfm) +void CRYPTO_API(cryptd_free_ahash)(struct cryptd_ahash *tfm) { struct cryptd_hash_ctx *ctx = crypto_ahash_ctx(&tfm->base); if (refcount_dec_and_test(&ctx->refcnt)) crypto_free_ahash(&tfm->base); } -EXPORT_SYMBOL_GPL(cryptd_free_ahash); +DEFINE_CRYPTO_API(cryptd_free_ahash); -struct cryptd_aead *cryptd_alloc_aead(const char *alg_name, +struct cryptd_aead *CRYPTO_API(cryptd_alloc_aead)(const char *alg_name, u32 type, u32 mask) { char cryptd_alg_name[CRYPTO_MAX_ALG_NAME]; @@ -1084,32 +1084,32 @@ struct cryptd_aead *cryptd_alloc_aead(const char *alg_name, return __cryptd_aead_cast(tfm); } -EXPORT_SYMBOL_GPL(cryptd_alloc_aead); +DEFINE_CRYPTO_API(cryptd_alloc_aead); -struct crypto_aead *cryptd_aead_child(struct cryptd_aead *tfm) +struct crypto_aead *CRYPTO_API(cryptd_aead_child)(struct cryptd_aead *tfm) { struct cryptd_aead_ctx *ctx; ctx = crypto_aead_ctx(&tfm->base); return ctx->child; } -EXPORT_SYMBOL_GPL(cryptd_aead_child); +DEFINE_CRYPTO_API(cryptd_aead_child); -bool cryptd_aead_queued(struct cryptd_aead *tfm) +bool CRYPTO_API(cryptd_aead_queued)(struct cryptd_aead *tfm) { struct cryptd_aead_ctx *ctx = crypto_aead_ctx(&tfm->base); return refcount_read(&ctx->refcnt) - 1; } -EXPORT_SYMBOL_GPL(cryptd_aead_queued); +DEFINE_CRYPTO_API(cryptd_aead_queued); -void cryptd_free_aead(struct cryptd_aead *tfm) +void CRYPTO_API(cryptd_free_aead)(struct cryptd_aead *tfm) { struct cryptd_aead_ctx *ctx = crypto_aead_ctx(&tfm->base); if (refcount_dec_and_test(&ctx->refcnt)) crypto_free_aead(&tfm->base); } -EXPORT_SYMBOL_GPL(cryptd_free_aead); +DEFINE_CRYPTO_API(cryptd_free_aead); static int __init cryptd_init(void) { @@ -1144,8 +1144,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-api.c b/crypto/fips140-api.c index c05fc645a5b6..816a55809f4a 100644 --- a/crypto/fips140-api.c +++ b/crypto/fips140-api.c @@ -327,3 +327,26 @@ DEFINE_CRYPTO_API_STUB(crypto_clone_cipher); #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..42de15e2cd52 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(cryptd_alloc_skcipher, struct cryptd_skcipher *, + (const char *alg_name, u32 type, u32 mask), + (alg_name, type, mask)); +DECLARE_CRYPTO_API(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(cryptd_skcipher_queued, bool, + (struct cryptd_skcipher *tfm), + (tfm)); +DECLARE_CRYPTO_API(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(cryptd_alloc_ahash, struct cryptd_ahash *, + (const char *alg_name, u32 type, u32 mask), + (alg_name, type, mask)); +DECLARE_CRYPTO_API(cryptd_ahash_child, struct crypto_shash *, + (struct cryptd_ahash *tfm), + (tfm)); +DECLARE_CRYPTO_API(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(cryptd_ahash_queued, bool, + (struct cryptd_ahash *tfm), + (tfm)); +DECLARE_CRYPTO_API(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(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(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(cryptd_aead_queued, bool, + (struct cryptd_aead *tfm), + (tfm)); -void cryptd_free_aead(struct cryptd_aead *tfm); +DECLARE_CRYPTO_API(cryptd_free_aead, void, + (struct cryptd_aead *tfm), + (tfm)); #endif -- 2.39.3