Apply Crypto API wrappers to the exported crypto symbol in CONFIG_CRYPTO_GENIV-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 | 13 +++++++++++++ include/crypto/internal/geniv.h | 14 ++++++++++---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/crypto/Makefile b/crypto/Makefile index 9aa52ddebb05..b05fdfacf170 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -16,7 +16,7 @@ crypto_algapi-y := algapi.o scatterwalk.o $(crypto_algapi-y) crypto-objs-$(CONFIG_CRYPTO_ALGAPI2) += crypto_algapi.o crypto-objs-$(CONFIG_CRYPTO_AEAD2) += aead.o -obj-$(CONFIG_CRYPTO_GENIV) += geniv.o +crypto-objs-$(CONFIG_CRYPTO_GENIV) += geniv.o crypto_skcipher-y += lskcipher.o crypto_skcipher-y += skcipher.o diff --git a/crypto/fips140/fips140-api.c b/crypto/fips140/fips140-api.c index eb02a56cb8b3..55129c62d813 100644 --- a/crypto/fips140/fips140-api.c +++ b/crypto/fips140/fips140-api.c @@ -129,4 +129,17 @@ DEFINE_CRYPTO_API_STUB(crypto_register_aeads); DEFINE_CRYPTO_API_STUB(crypto_unregister_aeads); DEFINE_CRYPTO_API_STUB(aead_register_instance); +#endif + +/* + * crypto/geniv.c + */ +#if IS_BUILTIN(CONFIG_CRYPTO_GENIV) + +#include <crypto/internal/geniv.h> + +DEFINE_CRYPTO_API_STUB(aead_geniv_alloc); +DEFINE_CRYPTO_API_STUB(aead_init_geniv); +DEFINE_CRYPTO_API_STUB(aead_exit_geniv); + #endif \ No newline at end of file diff --git a/include/crypto/internal/geniv.h b/include/crypto/internal/geniv.h index 012f5fb22d43..f6dfe3292b3c 100644 --- a/include/crypto/internal/geniv.h +++ b/include/crypto/internal/geniv.h @@ -8,6 +8,7 @@ #ifndef _CRYPTO_INTERNAL_GENIV_H #define _CRYPTO_INTERNAL_GENIV_H +#include <crypto/api.h> #include <crypto/internal/aead.h> #include <linux/spinlock.h> #include <linux/types.h> @@ -18,9 +19,14 @@ struct aead_geniv_ctx { u8 salt[] __attribute__ ((aligned(__alignof__(u32)))); }; -struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl, - struct rtattr **tb); -int aead_init_geniv(struct crypto_aead *tfm); -void aead_exit_geniv(struct crypto_aead *tfm); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_GENIV, aead_geniv_alloc, struct aead_instance *, + (struct crypto_template *tmpl, struct rtattr **tb), + (tmpl, tb)); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_GENIV, aead_init_geniv, int, + (struct crypto_aead *tfm), + (tfm)); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_GENIV, aead_exit_geniv, void, + (struct crypto_aead *tfm), + (tfm)); #endif /* _CRYPTO_INTERNAL_GENIV_H */ -- 2.47.3
