Apply Crypto API wrappers to the exported crypto symbol in
CONFIG_CRYPTO_ENGINE-related crypto to convert them into pluggable
interface.

Signed-off-by: Jay Wang <[email protected]>
---
 crypto/Makefile              |   2 +-
 crypto/fips140/fips140-api.c |  40 ++++++++++
 include/crypto/engine.h      | 140 +++++++++++++++++++++++------------
 3 files changed, 135 insertions(+), 47 deletions(-)

diff --git a/crypto/Makefile b/crypto/Makefile
index d58b5e2b5b43..f2b9532a0320 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -8,7 +8,7 @@ CONTEXT_ANALYSIS := y
 crypto-objs-$(CONFIG_CRYPTO) += crypto.o
 crypto-y := api.o cipher.o
 
-obj-$(CONFIG_CRYPTO_ENGINE) += crypto_engine.o
+crypto-objs-$(CONFIG_CRYPTO_ENGINE) += crypto_engine.o
 obj-$(CONFIG_CRYPTO_FIPS) += fips.o
 
 crypto_algapi-$(CONFIG_PROC_FS) += proc.o
diff --git a/crypto/fips140/fips140-api.c b/crypto/fips140/fips140-api.c
index e679932ab552..05ada434d1ac 100644
--- a/crypto/fips140/fips140-api.c
+++ b/crypto/fips140/fips140-api.c
@@ -526,3 +526,43 @@ DEFINE_CRYPTO_API_STUB(pkcs7_verify);
 DEFINE_CRYPTO_API_STUB(pkcs7_supply_detached_data);
 
 #endif
+/*
+ * crypto/crypto_engine.c
+ */
+#if IS_BUILTIN(CONFIG_CRYPTO_ENGINE)
+
+#include <crypto/engine.h>
+
+DEFINE_CRYPTO_API_STUB(crypto_transfer_aead_request_to_engine);
+DEFINE_CRYPTO_API_STUB(crypto_transfer_akcipher_request_to_engine);
+DEFINE_CRYPTO_API_STUB(crypto_transfer_hash_request_to_engine);
+DEFINE_CRYPTO_API_STUB(crypto_transfer_kpp_request_to_engine);
+DEFINE_CRYPTO_API_STUB(crypto_transfer_skcipher_request_to_engine);
+DEFINE_CRYPTO_API_STUB(crypto_finalize_aead_request);
+DEFINE_CRYPTO_API_STUB(crypto_finalize_akcipher_request);
+DEFINE_CRYPTO_API_STUB(crypto_finalize_hash_request);
+DEFINE_CRYPTO_API_STUB(crypto_finalize_kpp_request);
+DEFINE_CRYPTO_API_STUB(crypto_finalize_skcipher_request);
+DEFINE_CRYPTO_API_STUB(crypto_engine_start);
+DEFINE_CRYPTO_API_STUB(crypto_engine_stop);
+DEFINE_CRYPTO_API_STUB(crypto_engine_alloc_init);
+DEFINE_CRYPTO_API_STUB(crypto_engine_alloc_init_and_set);
+DEFINE_CRYPTO_API_STUB(crypto_engine_exit);
+DEFINE_CRYPTO_API_STUB(crypto_engine_register_aead);
+DEFINE_CRYPTO_API_STUB(crypto_engine_unregister_aead);
+DEFINE_CRYPTO_API_STUB(crypto_engine_register_aeads);
+DEFINE_CRYPTO_API_STUB(crypto_engine_unregister_aeads);
+DEFINE_CRYPTO_API_STUB(crypto_engine_register_ahash);
+DEFINE_CRYPTO_API_STUB(crypto_engine_unregister_ahash);
+DEFINE_CRYPTO_API_STUB(crypto_engine_register_ahashes);
+DEFINE_CRYPTO_API_STUB(crypto_engine_unregister_ahashes);
+DEFINE_CRYPTO_API_STUB(crypto_engine_register_akcipher);
+DEFINE_CRYPTO_API_STUB(crypto_engine_unregister_akcipher);
+DEFINE_CRYPTO_API_STUB(crypto_engine_register_kpp);
+DEFINE_CRYPTO_API_STUB(crypto_engine_unregister_kpp);
+DEFINE_CRYPTO_API_STUB(crypto_engine_register_skcipher);
+DEFINE_CRYPTO_API_STUB(crypto_engine_unregister_skcipher);
+DEFINE_CRYPTO_API_STUB(crypto_engine_register_skciphers);
+DEFINE_CRYPTO_API_STUB(crypto_engine_unregister_skciphers);
+
+#endif
\ No newline at end of file
diff --git a/include/crypto/engine.h b/include/crypto/engine.h
index 2e60344437da..82552e11880a 100644
--- a/include/crypto/engine.h
+++ b/include/crypto/engine.h
@@ -7,6 +7,7 @@
 #ifndef _CRYPTO_ENGINE_H
 #define _CRYPTO_ENGINE_H
 
+#include <crypto/api.h>
 #include <crypto/aead.h>
 #include <crypto/akcipher.h>
 #include <crypto/hash.h>
@@ -51,56 +52,103 @@ struct skcipher_engine_alg {
        struct crypto_engine_op op;
 };
 
-int crypto_transfer_aead_request_to_engine(struct crypto_engine *engine,
-                                          struct aead_request *req);
-int crypto_transfer_akcipher_request_to_engine(struct crypto_engine *engine,
-                                              struct akcipher_request *req);
-int crypto_transfer_hash_request_to_engine(struct crypto_engine *engine,
-                                              struct ahash_request *req);
-int crypto_transfer_kpp_request_to_engine(struct crypto_engine *engine,
-                                         struct kpp_request *req);
-int crypto_transfer_skcipher_request_to_engine(struct crypto_engine *engine,
-                                              struct skcipher_request *req);
-void crypto_finalize_aead_request(struct crypto_engine *engine,
-                                 struct aead_request *req, int err);
-void crypto_finalize_akcipher_request(struct crypto_engine *engine,
-                                     struct akcipher_request *req, int err);
-void crypto_finalize_hash_request(struct crypto_engine *engine,
-                                 struct ahash_request *req, int err);
-void crypto_finalize_kpp_request(struct crypto_engine *engine,
-                                struct kpp_request *req, int err);
-void crypto_finalize_skcipher_request(struct crypto_engine *engine,
-                                     struct skcipher_request *req, int err);
-int crypto_engine_start(struct crypto_engine *engine);
-int crypto_engine_stop(struct crypto_engine *engine);
-struct crypto_engine *crypto_engine_alloc_init(struct device *dev, bool rt);
-struct crypto_engine *crypto_engine_alloc_init_and_set(struct device *dev,
-                                                      bool retry_support,
-                                                      bool rt, int qlen);
-void crypto_engine_exit(struct crypto_engine *engine);
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, 
crypto_transfer_aead_request_to_engine, int,
+       (struct crypto_engine *engine, struct aead_request *req),
+       (engine, req));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, 
crypto_transfer_akcipher_request_to_engine, int,
+       (struct crypto_engine *engine, struct akcipher_request *req),
+       (engine, req));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, 
crypto_transfer_hash_request_to_engine, int,
+       (struct crypto_engine *engine, struct ahash_request *req),
+       (engine, req));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, 
crypto_transfer_kpp_request_to_engine, int,
+       (struct crypto_engine *engine, struct kpp_request *req),
+       (engine, req));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, 
crypto_transfer_skcipher_request_to_engine, int,
+       (struct crypto_engine *engine, struct skcipher_request *req),
+       (engine, req));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_finalize_aead_request, void,
+       (struct crypto_engine *engine, struct aead_request *req, int err),
+       (engine, req, err));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_finalize_akcipher_request, 
void,
+       (struct crypto_engine *engine, struct akcipher_request *req, int err),
+       (engine, req, err));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_finalize_hash_request, void,
+       (struct crypto_engine *engine, struct ahash_request *req, int err),
+       (engine, req, err));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_finalize_kpp_request, void,
+       (struct crypto_engine *engine, struct kpp_request *req, int err),
+       (engine, req, err));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_finalize_skcipher_request, 
void,
+       (struct crypto_engine *engine, struct skcipher_request *req, int err),
+       (engine, req, err));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_start, int,
+       (struct crypto_engine *engine),
+       (engine));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_stop, int,
+       (struct crypto_engine *engine),
+       (engine));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_alloc_init, struct 
crypto_engine *,
+       (struct device *dev, bool rt),
+       (dev, rt));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_alloc_init_and_set, 
struct crypto_engine *,
+       (struct device *dev, bool retry_support, bool rt, int qlen),
+       (dev, retry_support, rt, qlen));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_exit, void,
+       (struct crypto_engine *engine),
+       (engine));
 
-int crypto_engine_register_aead(struct aead_engine_alg *alg);
-void crypto_engine_unregister_aead(struct aead_engine_alg *alg);
-int crypto_engine_register_aeads(struct aead_engine_alg *algs, int count);
-void crypto_engine_unregister_aeads(struct aead_engine_alg *algs, int count);
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_register_aead, int,
+       (struct aead_engine_alg *alg),
+       (alg));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_unregister_aead, void,
+       (struct aead_engine_alg *alg),
+       (alg));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_register_aeads, int,
+       (struct aead_engine_alg *algs, int count),
+       (algs, count));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_unregister_aeads, void,
+       (struct aead_engine_alg *algs, int count),
+       (algs, count));
 
-int crypto_engine_register_ahash(struct ahash_engine_alg *alg);
-void crypto_engine_unregister_ahash(struct ahash_engine_alg *alg);
-int crypto_engine_register_ahashes(struct ahash_engine_alg *algs, int count);
-void crypto_engine_unregister_ahashes(struct ahash_engine_alg *algs,
-                                     int count);
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_register_ahash, int,
+       (struct ahash_engine_alg *alg),
+       (alg));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_unregister_ahash, void,
+       (struct ahash_engine_alg *alg),
+       (alg));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_register_ahashes, int,
+       (struct ahash_engine_alg *algs, int count),
+       (algs, count));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_unregister_ahashes, 
void,
+       (struct ahash_engine_alg *algs, int count),
+       (algs, count));
 
-int crypto_engine_register_akcipher(struct akcipher_engine_alg *alg);
-void crypto_engine_unregister_akcipher(struct akcipher_engine_alg *alg);
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_register_akcipher, int,
+       (struct akcipher_engine_alg *alg),
+       (alg));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_unregister_akcipher, 
void,
+       (struct akcipher_engine_alg *alg),
+       (alg));
 
-int crypto_engine_register_kpp(struct kpp_engine_alg *alg);
-void crypto_engine_unregister_kpp(struct kpp_engine_alg *alg);
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_register_kpp, int,
+       (struct kpp_engine_alg *alg),
+       (alg));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_unregister_kpp, void,
+       (struct kpp_engine_alg *alg),
+       (alg));
 
-int crypto_engine_register_skcipher(struct skcipher_engine_alg *alg);
-void crypto_engine_unregister_skcipher(struct skcipher_engine_alg *alg);
-int crypto_engine_register_skciphers(struct skcipher_engine_alg *algs,
-                                    int count);
-void crypto_engine_unregister_skciphers(struct skcipher_engine_alg *algs,
-                                       int count);
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_register_skcipher, int,
+       (struct skcipher_engine_alg *alg),
+       (alg));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_unregister_skcipher, 
void,
+       (struct skcipher_engine_alg *alg),
+       (alg));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_register_skciphers, int,
+       (struct skcipher_engine_alg *algs, int count),
+       (algs, count));
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_ENGINE, crypto_engine_unregister_skciphers, 
void,
+       (struct skcipher_engine_alg *algs, int count),
+       (algs, count));
 
 #endif /* _CRYPTO_ENGINE_H */
-- 
2.47.3


Reply via email to