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 --source crypto/api.c --header include/linux/crypto.h include/crypto/algapi.h crypto/internal.h Signed-off-by: Vegard Nossum <vegard.nossum@xxxxxxxxxx> --- crypto/api.c | 76 ++++++++++++++++++++--------------------- crypto/fips140-api.c | 35 +++++++++++++++++++ crypto/internal.h | 62 +++++++++++++++++++++------------ include/crypto/algapi.h | 4 ++- include/linux/crypto.h | 23 +++++++++---- 5 files changed, 133 insertions(+), 67 deletions(-) diff --git a/crypto/api.c b/crypto/api.c index 5724d62e9d07..7ddc99599590 100644 --- a/crypto/api.c +++ b/crypto/api.c @@ -40,20 +40,20 @@ static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg, static struct crypto_alg *crypto_alg_lookup(const char *name, u32 type, u32 mask); -struct crypto_alg *crypto_mod_get(struct crypto_alg *alg) +struct crypto_alg *CRYPTO_API(crypto_mod_get)(struct crypto_alg *alg) { return try_module_get(alg->cra_module) ? crypto_alg_get(alg) : NULL; } -EXPORT_SYMBOL_GPL(crypto_mod_get); +DEFINE_CRYPTO_API(crypto_mod_get); -void crypto_mod_put(struct crypto_alg *alg) +void CRYPTO_API(crypto_mod_put)(struct crypto_alg *alg) { struct module *module = alg->cra_module; crypto_alg_put(alg); module_put(module); } -EXPORT_SYMBOL_GPL(crypto_mod_put); +DEFINE_CRYPTO_API(crypto_mod_put); static struct crypto_alg *__crypto_alg_lookup(const char *name, u32 type, u32 mask) @@ -100,7 +100,7 @@ static void crypto_larval_destroy(struct crypto_alg *alg) kfree(larval); } -struct crypto_larval *crypto_larval_alloc(const char *name, u32 type, u32 mask) +struct crypto_larval *CRYPTO_API(crypto_larval_alloc)(const char *name, u32 type, u32 mask) { struct crypto_larval *larval; @@ -120,7 +120,7 @@ struct crypto_larval *crypto_larval_alloc(const char *name, u32 type, u32 mask) return larval; } -EXPORT_SYMBOL_GPL(crypto_larval_alloc); +DEFINE_CRYPTO_API(crypto_larval_alloc); static struct crypto_alg *crypto_larval_add(const char *name, u32 type, u32 mask) @@ -168,14 +168,14 @@ static void crypto_larval_kill(struct crypto_larval *larval) crypto_alg_put(&larval->alg); } -void crypto_schedule_test(struct crypto_larval *larval) +void CRYPTO_API(crypto_schedule_test)(struct crypto_larval *larval) { int err; err = crypto_probing_notify(CRYPTO_MSG_ALG_REGISTER, larval->adult); WARN_ON_ONCE(err != NOTIFY_STOP); } -EXPORT_SYMBOL_GPL(crypto_schedule_test); +DEFINE_CRYPTO_API(crypto_schedule_test); static void crypto_start_test(struct crypto_larval *larval) { @@ -320,7 +320,7 @@ static struct crypto_alg *crypto_larval_lookup(const char *name, u32 type, return alg; } -int crypto_probing_notify(unsigned long val, void *v) +int CRYPTO_API(crypto_probing_notify)(unsigned long val, void *v) { int ok; @@ -332,9 +332,9 @@ int crypto_probing_notify(unsigned long val, void *v) return ok; } -EXPORT_SYMBOL_GPL(crypto_probing_notify); +DEFINE_CRYPTO_API(crypto_probing_notify); -struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask) +struct crypto_alg *CRYPTO_API(crypto_alg_mod_lookup)(const char *name, u32 type, u32 mask) { struct crypto_alg *alg; struct crypto_alg *larval; @@ -365,7 +365,7 @@ struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask) crypto_larval_kill(container_of(larval, struct crypto_larval, alg)); return alg; } -EXPORT_SYMBOL_GPL(crypto_alg_mod_lookup); +DEFINE_CRYPTO_API(crypto_alg_mod_lookup); static void crypto_exit_ops(struct crypto_tfm *tfm) { @@ -396,15 +396,15 @@ static unsigned int crypto_ctxsize(struct crypto_alg *alg, u32 type, u32 mask) return len; } -void crypto_shoot_alg(struct crypto_alg *alg) +void CRYPTO_API(crypto_shoot_alg)(struct crypto_alg *alg) { down_write(&crypto_alg_sem); alg->cra_flags |= CRYPTO_ALG_DYING; up_write(&crypto_alg_sem); } -EXPORT_SYMBOL_GPL(crypto_shoot_alg); +DEFINE_CRYPTO_API(crypto_shoot_alg); -struct crypto_tfm *__crypto_alloc_tfmgfp(struct crypto_alg *alg, u32 type, +struct crypto_tfm *CRYPTO_API(__crypto_alloc_tfmgfp)(struct crypto_alg *alg, u32 type, u32 mask, gfp_t gfp) { struct crypto_tfm *tfm; @@ -434,14 +434,14 @@ struct crypto_tfm *__crypto_alloc_tfmgfp(struct crypto_alg *alg, u32 type, out: return tfm; } -EXPORT_SYMBOL_GPL(__crypto_alloc_tfmgfp); +DEFINE_CRYPTO_API(__crypto_alloc_tfmgfp); -struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type, +struct crypto_tfm *CRYPTO_API(__crypto_alloc_tfm)(struct crypto_alg *alg, u32 type, u32 mask) { return __crypto_alloc_tfmgfp(alg, type, mask, GFP_KERNEL); } -EXPORT_SYMBOL_GPL(__crypto_alloc_tfm); +DEFINE_CRYPTO_API(__crypto_alloc_tfm); /* * crypto_alloc_base - Locate algorithm and allocate transform @@ -465,7 +465,7 @@ EXPORT_SYMBOL_GPL(__crypto_alloc_tfm); * * In case of error the return value is an error pointer. */ -struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask) +struct crypto_tfm *CRYPTO_API(crypto_alloc_base)(const char *alg_name, u32 type, u32 mask) { struct crypto_tfm *tfm; int err; @@ -497,7 +497,7 @@ struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask) return ERR_PTR(err); } -EXPORT_SYMBOL_GPL(crypto_alloc_base); +DEFINE_CRYPTO_API(crypto_alloc_base); static void *crypto_alloc_tfmmem(struct crypto_alg *alg, const struct crypto_type *frontend, int node, @@ -523,7 +523,7 @@ static void *crypto_alloc_tfmmem(struct crypto_alg *alg, return mem; } -void *crypto_create_tfm_node(struct crypto_alg *alg, +void *CRYPTO_API(crypto_create_tfm_node)(struct crypto_alg *alg, const struct crypto_type *frontend, int node) { @@ -557,9 +557,9 @@ void *crypto_create_tfm_node(struct crypto_alg *alg, out: return mem; } -EXPORT_SYMBOL_GPL(crypto_create_tfm_node); +DEFINE_CRYPTO_API(crypto_create_tfm_node); -void *crypto_clone_tfm(const struct crypto_type *frontend, +void *CRYPTO_API(crypto_clone_tfm)(const struct crypto_type *frontend, struct crypto_tfm *otfm) { struct crypto_alg *alg = otfm->__crt_alg; @@ -583,9 +583,9 @@ void *crypto_clone_tfm(const struct crypto_type *frontend, out: return mem; } -EXPORT_SYMBOL_GPL(crypto_clone_tfm); +DEFINE_CRYPTO_API(crypto_clone_tfm); -struct crypto_alg *crypto_find_alg(const char *alg_name, +struct crypto_alg *CRYPTO_API(crypto_find_alg)(const char *alg_name, const struct crypto_type *frontend, u32 type, u32 mask) { @@ -598,7 +598,7 @@ struct crypto_alg *crypto_find_alg(const char *alg_name, return crypto_alg_mod_lookup(alg_name, type, mask); } -EXPORT_SYMBOL_GPL(crypto_find_alg); +DEFINE_CRYPTO_API(crypto_find_alg); /* * crypto_alloc_tfm_node - Locate algorithm and allocate transform @@ -623,7 +623,7 @@ EXPORT_SYMBOL_GPL(crypto_find_alg); * In case of error the return value is an error pointer. */ -void *crypto_alloc_tfm_node(const char *alg_name, +void *CRYPTO_API(crypto_alloc_tfm_node)(const char *alg_name, const struct crypto_type *frontend, u32 type, u32 mask, int node) { @@ -657,7 +657,7 @@ void *crypto_alloc_tfm_node(const char *alg_name, return ERR_PTR(err); } -EXPORT_SYMBOL_GPL(crypto_alloc_tfm_node); +DEFINE_CRYPTO_API(crypto_alloc_tfm_node); /* * crypto_destroy_tfm - Free crypto transform @@ -667,7 +667,7 @@ EXPORT_SYMBOL_GPL(crypto_alloc_tfm_node); * This function frees up the transform and any associated resources, * then drops the refcount on the associated algorithm. */ -void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm) +void CRYPTO_API(crypto_destroy_tfm)(void *mem, struct crypto_tfm *tfm) { struct crypto_alg *alg; @@ -684,9 +684,9 @@ void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm) crypto_mod_put(alg); kfree_sensitive(mem); } -EXPORT_SYMBOL_GPL(crypto_destroy_tfm); +DEFINE_CRYPTO_API(crypto_destroy_tfm); -int crypto_has_alg(const char *name, u32 type, u32 mask) +int CRYPTO_API(crypto_has_alg)(const char *name, u32 type, u32 mask) { int ret = 0; struct crypto_alg *alg = crypto_alg_mod_lookup(name, type, mask); @@ -698,9 +698,9 @@ int crypto_has_alg(const char *name, u32 type, u32 mask) return ret; } -EXPORT_SYMBOL_GPL(crypto_has_alg); +DEFINE_CRYPTO_API(crypto_has_alg); -void crypto_req_done(void *data, int err) +void CRYPTO_API(crypto_req_done)(void *data, int err) { struct crypto_wait *wait = data; @@ -710,18 +710,18 @@ void crypto_req_done(void *data, int err) wait->err = err; complete(&wait->completion); } -EXPORT_SYMBOL_GPL(crypto_req_done); +DEFINE_CRYPTO_API(crypto_req_done); -void crypto_destroy_alg(struct crypto_alg *alg) +void CRYPTO_API(crypto_destroy_alg)(struct crypto_alg *alg) { if (alg->cra_type && alg->cra_type->destroy) alg->cra_type->destroy(alg); if (alg->cra_destroy) alg->cra_destroy(alg); } -EXPORT_SYMBOL_GPL(crypto_destroy_alg); +DEFINE_CRYPTO_API(crypto_destroy_alg); -struct crypto_async_request *crypto_request_clone( +struct crypto_async_request *CRYPTO_API(crypto_request_clone)( struct crypto_async_request *req, size_t total, gfp_t gfp) { struct crypto_tfm *tfm = req->tfm; @@ -736,7 +736,7 @@ struct crypto_async_request *crypto_request_clone( nreq->flags &= ~CRYPTO_TFM_REQ_ON_STACK; return nreq; } -EXPORT_SYMBOL_GPL(crypto_request_clone); +DEFINE_CRYPTO_API(crypto_request_clone); MODULE_DESCRIPTION("Cryptographic core API"); MODULE_LICENSE("GPL"); diff --git a/crypto/fips140-api.c b/crypto/fips140-api.c index 1c7907b5e1dc..f5cf473f1f25 100644 --- a/crypto/fips140-api.c +++ b/crypto/fips140-api.c @@ -267,3 +267,38 @@ DEFINE_CRYPTO_API_STUB(crypto_type_has_alg); #endif +/* + * crypto/api.c + */ +#if !IS_BUILTIN(CONFIG_CRYPTO) + +#include <linux/crypto.h> + +DEFINE_CRYPTO_API_STUB(crypto_req_done); +DEFINE_CRYPTO_API_STUB(crypto_has_alg); +DEFINE_CRYPTO_API_STUB(crypto_alloc_base); +DEFINE_CRYPTO_API_STUB(crypto_destroy_tfm); +DEFINE_CRYPTO_API_STUB(crypto_request_clone); + +#include <crypto/algapi.h> + +DEFINE_CRYPTO_API_STUB(crypto_mod_put); + +#include <crypto/internal.h> + +DEFINE_CRYPTO_API_STUB(crypto_mod_get); +DEFINE_CRYPTO_API_STUB(crypto_alg_mod_lookup); +DEFINE_CRYPTO_API_STUB(crypto_larval_alloc); +DEFINE_CRYPTO_API_STUB(crypto_schedule_test); +DEFINE_CRYPTO_API_STUB(crypto_shoot_alg); +DEFINE_CRYPTO_API_STUB(__crypto_alloc_tfmgfp); +DEFINE_CRYPTO_API_STUB(__crypto_alloc_tfm); +DEFINE_CRYPTO_API_STUB(crypto_create_tfm_node); +DEFINE_CRYPTO_API_STUB(crypto_clone_tfm); +DEFINE_CRYPTO_API_STUB(crypto_find_alg); +DEFINE_CRYPTO_API_STUB(crypto_alloc_tfm_node); +DEFINE_CRYPTO_API_STUB(crypto_probing_notify); +DEFINE_CRYPTO_API_STUB(crypto_destroy_alg); + +#endif + diff --git a/crypto/internal.h b/crypto/internal.h index d823931fd0e2..700280457bf6 100644 --- a/crypto/internal.h +++ b/crypto/internal.h @@ -110,11 +110,19 @@ static inline unsigned int crypto_compress_ctxsize(struct crypto_alg *alg) return alg->cra_ctxsize; } -struct crypto_alg *crypto_mod_get(struct crypto_alg *alg); -struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask); - -struct crypto_larval *crypto_larval_alloc(const char *name, u32 type, u32 mask); -void crypto_schedule_test(struct crypto_larval *larval); +DECLARE_CRYPTO_API(crypto_mod_get, struct crypto_alg *, + (struct crypto_alg *alg), + (alg)); +DECLARE_CRYPTO_API(crypto_alg_mod_lookup, struct crypto_alg *, + (const char *name, u32 type, u32 mask), + (name, type, mask)); + +DECLARE_CRYPTO_API(crypto_larval_alloc, struct crypto_larval *, + (const char *name, u32 type, u32 mask), + (name, type, mask)); +DECLARE_CRYPTO_API(crypto_schedule_test, void, + (struct crypto_larval *larval), + (larval)); DECLARE_CRYPTO_API(crypto_alg_tested, void, (struct crypto_alg *alg, int err), (alg, err)); @@ -125,15 +133,21 @@ DECLARE_CRYPTO_API(crypto_remove_spawns, void, DECLARE_CRYPTO_API(crypto_remove_final, void, (struct list_head *list), (list)); -void crypto_shoot_alg(struct crypto_alg *alg); -struct crypto_tfm *__crypto_alloc_tfmgfp(struct crypto_alg *alg, u32 type, - u32 mask, gfp_t gfp); -struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type, - u32 mask); -void *crypto_create_tfm_node(struct crypto_alg *alg, - const struct crypto_type *frontend, int node); -void *crypto_clone_tfm(const struct crypto_type *frontend, - struct crypto_tfm *otfm); +DECLARE_CRYPTO_API(crypto_shoot_alg, void, + (struct crypto_alg *alg), + (alg)); +DECLARE_CRYPTO_API(__crypto_alloc_tfmgfp, struct crypto_tfm *, + (struct crypto_alg *alg, u32 type, u32 mask, gfp_t gfp), + (alg, type, mask, gfp)); +DECLARE_CRYPTO_API(__crypto_alloc_tfm, struct crypto_tfm *, + (struct crypto_alg *alg, u32 type, u32 mask), + (alg, type, mask)); +DECLARE_CRYPTO_API(crypto_create_tfm_node, void *, + (struct crypto_alg *alg, const struct crypto_type *frontend, int node), + (alg, frontend, node)); +DECLARE_CRYPTO_API(crypto_clone_tfm, void *, + (const struct crypto_type *frontend, struct crypto_tfm *otfm), + (frontend, otfm)); static inline void *crypto_create_tfm(struct crypto_alg *alg, const struct crypto_type *frontend) @@ -141,13 +155,13 @@ static inline void *crypto_create_tfm(struct crypto_alg *alg, return crypto_create_tfm_node(alg, frontend, NUMA_NO_NODE); } -struct crypto_alg *crypto_find_alg(const char *alg_name, - const struct crypto_type *frontend, - u32 type, u32 mask); +DECLARE_CRYPTO_API(crypto_find_alg, struct crypto_alg *, + (const char *alg_name, const struct crypto_type *frontend, u32 type, u32 mask), + (alg_name, frontend, type, mask)); -void *crypto_alloc_tfm_node(const char *alg_name, - const struct crypto_type *frontend, u32 type, u32 mask, - int node); +DECLARE_CRYPTO_API(crypto_alloc_tfm_node, void *, + (const char *alg_name, const struct crypto_type *frontend, u32 type, u32 mask, int node), + (alg_name, frontend, type, mask, node)); static inline void *crypto_alloc_tfm(const char *alg_name, const struct crypto_type *frontend, u32 type, u32 mask) @@ -155,7 +169,9 @@ static inline void *crypto_alloc_tfm(const char *alg_name, return crypto_alloc_tfm_node(alg_name, frontend, type, mask, NUMA_NO_NODE); } -int crypto_probing_notify(unsigned long val, void *v); +DECLARE_CRYPTO_API(crypto_probing_notify, int, + (unsigned long val, void *v), + (val, v)); DECLARE_CRYPTO_API(crypto_alg_extsize, unsigned int, (struct crypto_alg *alg), @@ -171,7 +187,9 @@ static inline struct crypto_alg *crypto_alg_get(struct crypto_alg *alg) return alg; } -void crypto_destroy_alg(struct crypto_alg *alg); +DECLARE_CRYPTO_API(crypto_destroy_alg, void, + (struct crypto_alg *alg), + (alg)); static inline void crypto_alg_put(struct crypto_alg *alg) { diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index 9d7505b7f029..9844f3b0cb0a 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h @@ -133,7 +133,9 @@ DECLARE_CRYPTO_API(crypto_unregister_algs, void, (struct crypto_alg *algs, int count), (algs, count)); -void crypto_mod_put(struct crypto_alg *alg); +DECLARE_CRYPTO_API(crypto_mod_put, void, + (struct crypto_alg *alg), + (alg)); DECLARE_CRYPTO_API(crypto_register_template, int, (struct crypto_template *tmpl), diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 737e53a642d4..e4b356a3b27d 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h @@ -12,6 +12,7 @@ #ifndef _LINUX_CRYPTO_H #define _LINUX_CRYPTO_H +#include <crypto/api.h> #include <linux/completion.h> #include <linux/errno.h> #include <linux/refcount_types.h> @@ -384,7 +385,9 @@ struct crypto_wait { /* * Async ops completion helper functioons */ -void crypto_req_done(void *req, int err); +DECLARE_CRYPTO_API(crypto_req_done, void, + (void *req, int err), + (req, err)); static inline int crypto_wait_req(int err, struct crypto_wait *wait) { @@ -408,7 +411,9 @@ static inline void crypto_init_wait(struct crypto_wait *wait) /* * Algorithm query interface. */ -int crypto_has_alg(const char *name, u32 type, u32 mask); +DECLARE_CRYPTO_API(crypto_has_alg, int, + (const char *name, u32 type, u32 mask), + (name, type, mask)); /* * Transforms: user-instantiated objects which encapsulate algorithms @@ -436,8 +441,12 @@ struct crypto_tfm { * Transform user interface. */ -struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask); -void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm); +DECLARE_CRYPTO_API(crypto_alloc_base, struct crypto_tfm *, + (const char *alg_name, u32 type, u32 mask), + (alg_name, type, mask)); +DECLARE_CRYPTO_API(crypto_destroy_tfm, void, + (void *mem, struct crypto_tfm *tfm), + (mem, tfm)); static inline void crypto_free_tfm(struct crypto_tfm *tfm) { @@ -522,8 +531,10 @@ static inline void crypto_request_set_tfm(struct crypto_async_request *req, req->flags &= ~CRYPTO_TFM_REQ_ON_STACK; } -struct crypto_async_request *crypto_request_clone( - struct crypto_async_request *req, size_t total, gfp_t gfp); +DECLARE_CRYPTO_API(crypto_request_clone, struct crypto_async_request *, + ( + struct crypto_async_request *req, size_t total, gfp_t gfp), + (req, total, gfp)); static inline void crypto_stack_request_init(struct crypto_async_request *req, struct crypto_tfm *tfm) -- 2.39.3