Apply Crypto API wrappers to the exported crypto symbol in CONFIG_CRYPTO_KPP2-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/fips140/fips140-api.c | 17 +++++++++++++++++ include/crypto/internal/kpp.h | 12 +++++------- include/crypto/kpp.h | 5 +++-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/crypto/Makefile b/crypto/Makefile index 2e722f7961d4..21197857ad7d 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -35,7 +35,7 @@ crypto-objs-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o crypto-objs-$(CONFIG_CRYPTO_AKCIPHER2) += akcipher.o crypto-objs-$(CONFIG_CRYPTO_SIG2) += sig.o -obj-$(CONFIG_CRYPTO_KPP2) += kpp.o +crypto-objs-$(CONFIG_CRYPTO_KPP2) += kpp.o obj-$(CONFIG_CRYPTO_HKDF) += hkdf.o dh_generic-y := dh.o diff --git a/crypto/fips140/fips140-api.c b/crypto/fips140/fips140-api.c index c97806cfdd05..50603e7a8bb0 100644 --- a/crypto/fips140/fips140-api.c +++ b/crypto/fips140/fips140-api.c @@ -286,4 +286,21 @@ DEFINE_CRYPTO_API_STUB(crypto_unregister_sig); DEFINE_CRYPTO_API_STUB(sig_register_instance); DEFINE_CRYPTO_API_STUB(crypto_grab_sig); +#endif + +/* + * crypto/kpp.c + */ +#if IS_BUILTIN(CONFIG_CRYPTO_KPP2) + +#include <crypto/kpp.h> +#include <crypto/internal/kpp.h> + +DEFINE_CRYPTO_API_STUB(crypto_alloc_kpp); +DEFINE_CRYPTO_API_STUB(crypto_grab_kpp); +DEFINE_CRYPTO_API_STUB(crypto_has_kpp); +DEFINE_CRYPTO_API_STUB(crypto_register_kpp); +DEFINE_CRYPTO_API_STUB(crypto_unregister_kpp); +DEFINE_CRYPTO_API_STUB(kpp_register_instance); + #endif \ No newline at end of file diff --git a/include/crypto/internal/kpp.h b/include/crypto/internal/kpp.h index 0a6db8c4a9a0..eff35727f700 100644 --- a/include/crypto/internal/kpp.h +++ b/include/crypto/internal/kpp.h @@ -7,6 +7,7 @@ */ #ifndef _CRYPTO_KPP_INT_H #define _CRYPTO_KPP_INT_H +#include <crypto/api.h> #include <crypto/kpp.h> #include <crypto/algapi.h> @@ -159,7 +160,7 @@ static inline void *kpp_instance_ctx(struct kpp_instance *inst) * * Return: zero on success; error code in case of error */ -int crypto_register_kpp(struct kpp_alg *alg); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_KPP2, crypto_register_kpp, int, (struct kpp_alg *alg), (alg)); /** * crypto_unregister_kpp() -- Unregister key-agreement protocol primitive @@ -170,7 +171,7 @@ int crypto_register_kpp(struct kpp_alg *alg); * * @alg: algorithm definition */ -void crypto_unregister_kpp(struct kpp_alg *alg); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_KPP2, crypto_unregister_kpp, void, (struct kpp_alg *alg), (alg)); /** * kpp_register_instance() - Register a KPP template instance. @@ -178,8 +179,7 @@ void crypto_unregister_kpp(struct kpp_alg *alg); * @inst: The KPP template instance to be registered. * Return: %0 on success, negative error code otherwise. */ -int kpp_register_instance(struct crypto_template *tmpl, - struct kpp_instance *inst); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_KPP2, kpp_register_instance, int, (struct crypto_template *tmpl, struct kpp_instance *inst), (tmpl, inst)); /* * KPP spawn related functions. @@ -193,9 +193,7 @@ int kpp_register_instance(struct crypto_template *tmpl, * @mask: The mask bismask to pass on to the lookup. * Return: %0 on success, a negative error code otherwise. */ -int crypto_grab_kpp(struct crypto_kpp_spawn *spawn, - struct crypto_instance *inst, - const char *name, u32 type, u32 mask); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_KPP2, crypto_grab_kpp, int, (struct crypto_kpp_spawn *spawn, struct crypto_instance *inst, const char *name, u32 type, u32 mask), (spawn, inst, name, type, mask)); /** * crypto_drop_kpp() - Release a spawn previously bound via crypto_grab_kpp(). diff --git a/include/crypto/kpp.h b/include/crypto/kpp.h index 2d9c4de57b69..068a6e218344 100644 --- a/include/crypto/kpp.h +++ b/include/crypto/kpp.h @@ -9,6 +9,7 @@ #ifndef _CRYPTO_KPP_ #define _CRYPTO_KPP_ +#include <crypto/api.h> #include <linux/atomic.h> #include <linux/container_of.h> #include <linux/crypto.h> @@ -107,9 +108,9 @@ struct kpp_alg { * Return: allocated handle in case of success; IS_ERR() is true in case of * an error, PTR_ERR() returns the error code. */ -struct crypto_kpp *crypto_alloc_kpp(const char *alg_name, u32 type, u32 mask); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_KPP2, crypto_alloc_kpp, struct crypto_kpp *, (const char *alg_name, u32 type, u32 mask), (alg_name, type, mask)); -int crypto_has_kpp(const char *alg_name, u32 type, u32 mask); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_KPP2, crypto_has_kpp, int, (const char *alg_name, u32 type, u32 mask), (alg_name, type, mask)); static inline struct crypto_tfm *crypto_kpp_tfm(struct crypto_kpp *tfm) { -- 2.47.3
