Apply Crypto API wrappers to the exported crypto symbol in CONFIG_CRYPTO_SM4_AESNI_AVX_X86_64-related crypto to convert them into pluggable interface.
Signed-off-by: Jay Wang <[email protected]> --- arch/x86/crypto/Makefile | 2 +- arch/x86/crypto/fips140/fips140-api.c | 15 +++++++++++++++ arch/x86/crypto/sm4-avx.h | 26 +++++++++++++++++--------- arch/x86/crypto/sm4_aesni_avx_glue.c | 4 ++-- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/arch/x86/crypto/Makefile b/arch/x86/crypto/Makefile index ffe37f4d4a7b..ce00d3e0e451 100644 --- a/arch/x86/crypto/Makefile +++ b/arch/x86/crypto/Makefile @@ -56,7 +56,7 @@ ghash-clmulni-intel-y := ghash-clmulni-intel_asm.o ghash-clmulni-intel_glue.o crypto-objs-$(CONFIG_CRYPTO_SM3_AVX_X86_64) += sm3-avx-x86_64.o sm3-avx-x86_64-y := sm3-avx-asm_64.o sm3_avx_glue.o -obj-$(CONFIG_CRYPTO_SM4_AESNI_AVX_X86_64) += sm4-aesni-avx-x86_64.o +crypto-objs-$(CONFIG_CRYPTO_SM4_AESNI_AVX_X86_64) += sm4-aesni-avx-x86_64.o sm4-aesni-avx-x86_64-y := sm4-aesni-avx-asm_64.o sm4_aesni_avx_glue.o obj-$(CONFIG_CRYPTO_SM4_AESNI_AVX2_X86_64) += sm4-aesni-avx2-x86_64.o diff --git a/arch/x86/crypto/fips140/fips140-api.c b/arch/x86/crypto/fips140/fips140-api.c index 8048f1568852..1333b1ce6cdf 100644 --- a/arch/x86/crypto/fips140/fips140-api.c +++ b/arch/x86/crypto/fips140/fips140-api.c @@ -63,4 +63,19 @@ DEFINE_CRYPTO_API_STUB(camellia_ecb_enc_16way); DEFINE_CRYPTO_API_STUB(camellia_ecb_dec_16way); DEFINE_CRYPTO_API_STUB(camellia_cbc_dec_16way); +#endif + +/* + * arch/x86/crypto/sm4_aesni_avx_glue.c + */ +#if IS_BUILTIN(CONFIG_CRYPTO_SM4_AESNI_AVX_X86_64) + +#include <arch/x86/crypto/sm4-avx.h> + +DEFINE_CRYPTO_API_STUB(sm4_avx_ecb_encrypt); +DEFINE_CRYPTO_API_STUB(sm4_avx_ecb_decrypt); +DEFINE_CRYPTO_API_STUB(sm4_cbc_encrypt); +DEFINE_CRYPTO_API_STUB(sm4_avx_cbc_decrypt); +DEFINE_CRYPTO_API_STUB(sm4_avx_ctr_crypt); + #endif \ No newline at end of file diff --git a/arch/x86/crypto/sm4-avx.h b/arch/x86/crypto/sm4-avx.h index b5b5e67e40ed..2a8c05e6f255 100644 --- a/arch/x86/crypto/sm4-avx.h +++ b/arch/x86/crypto/sm4-avx.h @@ -2,19 +2,27 @@ #ifndef ASM_X86_SM4_AVX_H #define ASM_X86_SM4_AVX_H +#include <crypto/api.h> #include <linux/types.h> #include <crypto/sm4.h> typedef void (*sm4_crypt_func)(const u32 *rk, u8 *dst, const u8 *src, u8 *iv); -int sm4_avx_ecb_encrypt(struct skcipher_request *req); -int sm4_avx_ecb_decrypt(struct skcipher_request *req); - -int sm4_cbc_encrypt(struct skcipher_request *req); -int sm4_avx_cbc_decrypt(struct skcipher_request *req, - unsigned int bsize, sm4_crypt_func func); - -int sm4_avx_ctr_crypt(struct skcipher_request *req, - unsigned int bsize, sm4_crypt_func func); +struct skcipher_request; +DECLARE_CRYPTO_API(CONFIG_CRYPTO_SM4_AESNI_AVX_X86_64, sm4_avx_ecb_encrypt, int, + (struct skcipher_request *req), + (req)); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_SM4_AESNI_AVX_X86_64, sm4_avx_ecb_decrypt, int, + (struct skcipher_request *req), + (req)); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_SM4_AESNI_AVX_X86_64, sm4_cbc_encrypt, int, + (struct skcipher_request *req), + (req)); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_SM4_AESNI_AVX_X86_64, sm4_avx_cbc_decrypt, int, + (struct skcipher_request *req, unsigned int bsize, sm4_crypt_func func), + (req, bsize, func)); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_SM4_AESNI_AVX_X86_64, sm4_avx_ctr_crypt, int, + (struct skcipher_request *req, unsigned int bsize, sm4_crypt_func func), + (req, bsize, func)); #endif diff --git a/arch/x86/crypto/sm4_aesni_avx_glue.c b/arch/x86/crypto/sm4_aesni_avx_glue.c index 88caf418a06f..787468f9dcf2 100644 --- a/arch/x86/crypto/sm4_aesni_avx_glue.c +++ b/arch/x86/crypto/sm4_aesni_avx_glue.c @@ -339,8 +339,8 @@ static void __exit sm4_exit(void) ARRAY_SIZE(sm4_aesni_avx_skciphers)); } -module_init(sm4_init); -module_exit(sm4_exit); +crypto_module_init(sm4_init); +crypto_module_exit(sm4_exit); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Tianjia Zhang <[email protected]>"); -- 2.47.3
