Apply Crypto API wrappers to the exported crypto symbol in
CONFIG_CRYPTO_SIMD-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   | 15 +++++++++++++++
 include/crypto/internal/simd.h | 33 ++++++++++++++++++++-------------
 3 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/crypto/Makefile b/crypto/Makefile
index c1088b10f49a..7403364c9afa 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -200,7 +200,7 @@ crypto-objs-$(CONFIG_XOR_BLOCKS) += xor.o
 obj-$(CONFIG_ASYNC_CORE) += async_tx/
 obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += asymmetric_keys/
 crypto_simd-y := simd.o
-obj-$(CONFIG_CRYPTO_SIMD) += crypto_simd.o
+crypto-objs-$(CONFIG_CRYPTO_SIMD) += crypto_simd.o
 
 #
 # Key derivation function
diff --git a/crypto/fips140/fips140-api.c b/crypto/fips140/fips140-api.c
index 74eae8815067..126ecd09ae07 100644
--- a/crypto/fips140/fips140-api.c
+++ b/crypto/fips140/fips140-api.c
@@ -913,4 +913,19 @@ DEFINE_CRYPTO_API_STUB(crypto_ecdh_decode_key);
 
 DEFINE_CRYPTO_API_STUB(verify_pefile_signature);
 
+#endif
+/*
+ * crypto/simd.c
+ */
+#if IS_BUILTIN(CONFIG_CRYPTO_SIMD)
+
+#include <crypto/internal/simd.h>
+
+DEFINE_CRYPTO_API_STUB(simd_skcipher_create_compat);
+DEFINE_CRYPTO_API_STUB(simd_skcipher_free);
+DEFINE_CRYPTO_API_STUB(simd_register_skciphers_compat);
+DEFINE_CRYPTO_API_STUB(simd_unregister_skciphers);
+DEFINE_CRYPTO_API_STUB(simd_register_aeads_compat);
+DEFINE_CRYPTO_API_STUB(simd_unregister_aeads);
+
 #endif
\ No newline at end of file
diff --git a/include/crypto/internal/simd.h b/include/crypto/internal/simd.h
index 9e338e7aafbd..be84d67f3ceb 100644
--- a/include/crypto/internal/simd.h
+++ b/include/crypto/internal/simd.h
@@ -6,6 +6,8 @@
 #ifndef _CRYPTO_INTERNAL_SIMD_H
 #define _CRYPTO_INTERNAL_SIMD_H
 
+#include <crypto/api.h>
+
 #include <asm/simd.h>
 #include <linux/percpu.h>
 #include <linux/types.h>
@@ -15,28 +17,33 @@
 struct simd_skcipher_alg;
 struct skcipher_alg;
 
-struct simd_skcipher_alg *simd_skcipher_create_compat(struct skcipher_alg 
*ialg,
-                                                     const char *algname,
-                                                     const char *drvname,
-                                                     const char *basename);
-void simd_skcipher_free(struct simd_skcipher_alg *alg);
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_SIMD, simd_skcipher_create_compat, struct 
simd_skcipher_alg *,
+       (struct skcipher_alg *ialg, const char *algname, const char *drvname, 
const char *basename),
+       (ialg, algname, drvname, basename));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_SIMD, simd_skcipher_free, void,
+       (struct simd_skcipher_alg *alg),
+       (alg));
 
-int simd_register_skciphers_compat(struct skcipher_alg *algs, int count,
-                                  struct simd_skcipher_alg **simd_algs);
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_SIMD, simd_register_skciphers_compat, int,
+       (struct skcipher_alg *algs, int count, struct simd_skcipher_alg 
**simd_algs),
+       (algs, count, simd_algs));
 
-void simd_unregister_skciphers(struct skcipher_alg *algs, int count,
-                              struct simd_skcipher_alg **simd_algs);
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_SIMD, simd_unregister_skciphers, void,
+       (struct skcipher_alg *algs, int count, struct simd_skcipher_alg 
**simd_algs),
+       (algs, count, simd_algs));
 
 /* AEAD support */
 
 struct simd_aead_alg;
 struct aead_alg;
 
-int simd_register_aeads_compat(struct aead_alg *algs, int count,
-                              struct simd_aead_alg **simd_algs);
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_SIMD, simd_register_aeads_compat, int,
+       (struct aead_alg *algs, int count, struct simd_aead_alg **simd_algs),
+       (algs, count, simd_algs));
 
-void simd_unregister_aeads(struct aead_alg *algs, int count,
-                          struct simd_aead_alg **simd_algs);
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_SIMD, simd_unregister_aeads, void,
+       (struct aead_alg *algs, int count, struct simd_aead_alg **simd_algs),
+       (algs, count, simd_algs));
 
 /*
  * crypto_simd_usable() - is it allowed at this time to use SIMD instructions 
or
-- 
2.47.3


Reply via email to