Apply Crypto API wrappers to the exported crypto symbol in CONFIG_CRYPTO_AKCIPHER2-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 | 18 ++++++++++++++++++ include/crypto/akcipher.h | 12 ++++-------- include/crypto/internal/akcipher.h | 12 +++++------- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/crypto/Makefile b/crypto/Makefile index 210e4aa3dbac..7d55be467108 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -33,7 +33,7 @@ crypto_hash-y += ahash.o crypto_hash-y += shash.o crypto-objs-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o -obj-$(CONFIG_CRYPTO_AKCIPHER2) += akcipher.o +crypto-objs-$(CONFIG_CRYPTO_AKCIPHER2) += akcipher.o obj-$(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 e1c2f709ad3b..8d4d07060d86 100644 --- a/crypto/fips140/fips140-api.c +++ b/crypto/fips140/fips140-api.c @@ -252,4 +252,22 @@ DEFINE_CRYPTO_API_STUB(crypto_unregister_shashes); DEFINE_CRYPTO_API_STUB(shash_register_instance); DEFINE_CRYPTO_API_STUB(shash_free_singlespawn_instance); +#endif + +/* + * crypto/akcipher.c + */ +#if IS_BUILTIN(CONFIG_CRYPTO_AKCIPHER2) + +#include <crypto/akcipher.h> +#include <crypto/internal/akcipher.h> + +DEFINE_CRYPTO_API_STUB(crypto_grab_akcipher); +DEFINE_CRYPTO_API_STUB(crypto_alloc_akcipher); +DEFINE_CRYPTO_API_STUB(crypto_register_akcipher); +DEFINE_CRYPTO_API_STUB(crypto_unregister_akcipher); +DEFINE_CRYPTO_API_STUB(akcipher_register_instance); +DEFINE_CRYPTO_API_STUB(crypto_akcipher_sync_encrypt); +DEFINE_CRYPTO_API_STUB(crypto_akcipher_sync_decrypt); + #endif \ No newline at end of file diff --git a/include/crypto/akcipher.h b/include/crypto/akcipher.h index cdf7da74bf2f..a48cf468521e 100644 --- a/include/crypto/akcipher.h +++ b/include/crypto/akcipher.h @@ -8,6 +8,7 @@ #ifndef _CRYPTO_AKCIPHER_H #define _CRYPTO_AKCIPHER_H +#include <crypto/api.h> #include <linux/atomic.h> #include <linux/crypto.h> @@ -116,8 +117,7 @@ struct akcipher_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_akcipher *crypto_alloc_akcipher(const char *alg_name, u32 type, - u32 mask); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_AKCIPHER2, crypto_alloc_akcipher, struct crypto_akcipher *, (const char *alg_name, u32 type, u32 mask), (alg_name, type, mask)); static inline struct crypto_tfm *crypto_akcipher_tfm( struct crypto_akcipher *tfm) @@ -310,9 +310,7 @@ static inline int crypto_akcipher_decrypt(struct akcipher_request *req) * * Return: zero on success; error code in case of error */ -int crypto_akcipher_sync_encrypt(struct crypto_akcipher *tfm, - const void *src, unsigned int slen, - void *dst, unsigned int dlen); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_AKCIPHER2, crypto_akcipher_sync_encrypt, int, (struct crypto_akcipher *tfm, const void *src, unsigned int slen, void *dst, unsigned int dlen), (tfm, src, slen, dst, dlen)); /** * crypto_akcipher_sync_decrypt() - Invoke public key decrypt operation @@ -328,9 +326,7 @@ int crypto_akcipher_sync_encrypt(struct crypto_akcipher *tfm, * * Return: Output length on success; error code in case of error */ -int crypto_akcipher_sync_decrypt(struct crypto_akcipher *tfm, - const void *src, unsigned int slen, - void *dst, unsigned int dlen); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_AKCIPHER2, crypto_akcipher_sync_decrypt, int, (struct crypto_akcipher *tfm, const void *src, unsigned int slen, void *dst, unsigned int dlen), (tfm, src, slen, dst, dlen)); /** * crypto_akcipher_set_pub_key() - Invoke set public key operation diff --git a/include/crypto/internal/akcipher.h b/include/crypto/internal/akcipher.h index 14ee62bc52b6..5b690a82d58e 100644 --- a/include/crypto/internal/akcipher.h +++ b/include/crypto/internal/akcipher.h @@ -7,6 +7,7 @@ */ #ifndef _CRYPTO_AKCIPHER_INT_H #define _CRYPTO_AKCIPHER_INT_H +#include <crypto/api.h> #include <crypto/akcipher.h> #include <crypto/algapi.h> @@ -100,9 +101,7 @@ static inline void *akcipher_instance_ctx(struct akcipher_instance *inst) return crypto_instance_ctx(akcipher_crypto_instance(inst)); } -int crypto_grab_akcipher(struct crypto_akcipher_spawn *spawn, - struct crypto_instance *inst, - const char *name, u32 type, u32 mask); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_AKCIPHER2, crypto_grab_akcipher, int, (struct crypto_akcipher_spawn *spawn, struct crypto_instance *inst, const char *name, u32 type, u32 mask), (spawn, inst, name, type, mask)); static inline struct crypto_akcipher *crypto_spawn_akcipher( struct crypto_akcipher_spawn *spawn) @@ -130,7 +129,7 @@ static inline struct akcipher_alg *crypto_spawn_akcipher_alg( * * Return: zero on success; error code in case of error */ -int crypto_register_akcipher(struct akcipher_alg *alg); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_AKCIPHER2, crypto_register_akcipher, int, (struct akcipher_alg *alg), (alg)); /** * crypto_unregister_akcipher() -- Unregister public key algorithm @@ -139,7 +138,7 @@ int crypto_register_akcipher(struct akcipher_alg *alg); * * @alg: algorithm definition */ -void crypto_unregister_akcipher(struct akcipher_alg *alg); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_AKCIPHER2, crypto_unregister_akcipher, void, (struct akcipher_alg *alg), (alg)); /** * akcipher_register_instance() -- Unregister public key template instance @@ -150,6 +149,5 @@ void crypto_unregister_akcipher(struct akcipher_alg *alg); * @tmpl: the template from which the algorithm was created * @inst: the template instance */ -int akcipher_register_instance(struct crypto_template *tmpl, - struct akcipher_instance *inst); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_AKCIPHER2, akcipher_register_instance, int, (struct crypto_template *tmpl, struct akcipher_instance *inst), (tmpl, inst)); #endif -- 2.47.3
