Apply Crypto API wrappers to the exported crypto symbol in CONFIG_CRYPTO_SIG2-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 | 16 ++++++++++++++++ include/crypto/internal/sig.h | 12 +++++------- include/crypto/sig.h | 3 ++- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/crypto/Makefile b/crypto/Makefile index 7d55be467108..2e722f7961d4 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -34,7 +34,7 @@ crypto_hash-y += shash.o crypto-objs-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o crypto-objs-$(CONFIG_CRYPTO_AKCIPHER2) += akcipher.o -obj-$(CONFIG_CRYPTO_SIG2) += sig.o +crypto-objs-$(CONFIG_CRYPTO_SIG2) += sig.o obj-$(CONFIG_CRYPTO_KPP2) += kpp.o obj-$(CONFIG_CRYPTO_HKDF) += hkdf.o diff --git a/crypto/fips140/fips140-api.c b/crypto/fips140/fips140-api.c index 8d4d07060d86..c97806cfdd05 100644 --- a/crypto/fips140/fips140-api.c +++ b/crypto/fips140/fips140-api.c @@ -270,4 +270,20 @@ DEFINE_CRYPTO_API_STUB(akcipher_register_instance); DEFINE_CRYPTO_API_STUB(crypto_akcipher_sync_encrypt); DEFINE_CRYPTO_API_STUB(crypto_akcipher_sync_decrypt); +#endif + +/* + * crypto/sig.c + */ +#if IS_BUILTIN(CONFIG_CRYPTO_SIG2) + +#include <crypto/sig.h> +#include <crypto/internal/sig.h> + +DEFINE_CRYPTO_API_STUB(crypto_alloc_sig); +DEFINE_CRYPTO_API_STUB(crypto_register_sig); +DEFINE_CRYPTO_API_STUB(crypto_unregister_sig); +DEFINE_CRYPTO_API_STUB(sig_register_instance); +DEFINE_CRYPTO_API_STUB(crypto_grab_sig); + #endif \ No newline at end of file diff --git a/include/crypto/internal/sig.h b/include/crypto/internal/sig.h index b16648c1a986..51d3a617c00d 100644 --- a/include/crypto/internal/sig.h +++ b/include/crypto/internal/sig.h @@ -7,6 +7,7 @@ #ifndef _CRYPTO_INTERNAL_SIG_H #define _CRYPTO_INTERNAL_SIG_H +#include <crypto/api.h> #include <crypto/algapi.h> #include <crypto/sig.h> @@ -39,7 +40,7 @@ static inline void *crypto_sig_ctx(struct crypto_sig *tfm) * * Return: zero on success; error code in case of error */ -int crypto_register_sig(struct sig_alg *alg); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_SIG2, crypto_register_sig, int, (struct sig_alg *alg), (alg)); /** * crypto_unregister_sig() -- Unregister public key signature algorithm @@ -48,10 +49,9 @@ int crypto_register_sig(struct sig_alg *alg); * * @alg: algorithm definition */ -void crypto_unregister_sig(struct sig_alg *alg); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_SIG2, crypto_unregister_sig, void, (struct sig_alg *alg), (alg)); -int sig_register_instance(struct crypto_template *tmpl, - struct sig_instance *inst); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_SIG2, sig_register_instance, int, (struct crypto_template *tmpl, struct sig_instance *inst), (tmpl, inst)); static inline struct sig_instance *sig_instance(struct crypto_instance *inst) { @@ -74,9 +74,7 @@ static inline void *sig_instance_ctx(struct sig_instance *inst) return crypto_instance_ctx(sig_crypto_instance(inst)); } -int crypto_grab_sig(struct crypto_sig_spawn *spawn, - struct crypto_instance *inst, - const char *name, u32 type, u32 mask); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_SIG2, crypto_grab_sig, int, (struct crypto_sig_spawn *spawn, struct crypto_instance *inst, const char *name, u32 type, u32 mask), (spawn, inst, name, type, mask)); static inline struct crypto_sig *crypto_spawn_sig(struct crypto_sig_spawn *spawn) diff --git a/include/crypto/sig.h b/include/crypto/sig.h index fa6dafafab3f..1b0595b3b245 100644 --- a/include/crypto/sig.h +++ b/include/crypto/sig.h @@ -7,6 +7,7 @@ #ifndef _CRYPTO_SIG_H #define _CRYPTO_SIG_H +#include <crypto/api.h> #include <linux/crypto.h> /** @@ -91,7 +92,7 @@ struct sig_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_sig *crypto_alloc_sig(const char *alg_name, u32 type, u32 mask); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_SIG2, crypto_alloc_sig, struct crypto_sig *, (const char *alg_name, u32 type, u32 mask), (alg_name, type, mask)); static inline struct crypto_tfm *crypto_sig_tfm(struct crypto_sig *tfm) { -- 2.47.3
