[PATCH 2/4] crypto: engine - add acomp support

From: Chenghai Huang

Date: Mon Nov 09 2026 - 02:42:08 EST


Add support for asynchronous compression (acomp) algorithms to the
crypto engine framework: transfer/finalize helpers plus an
acomp_engine_alg registration interface, mirroring the existing
akcipher and kpp support.

As engine.h needs to embed struct acomp_alg by value, move it from
include/crypto/internal/acompress.h to include/crypto/acompress.h.
The internal header still provides it through the existing include.

Signed-off-by: Chenghai Huang <huangchenghai2@xxxxxxxxxx>
---
crypto/crypto_engine.c | 42 +++++++++++++++++++++++++++++
include/crypto/acompress.h | 33 +++++++++++++++++++++++
include/crypto/engine.h | 13 +++++++++
include/crypto/internal/acompress.h | 33 -----------------------
4 files changed, 88 insertions(+), 33 deletions(-)

diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c
index 5b669038acb4..2a0740d9dd63 100644
--- a/crypto/crypto_engine.c
+++ b/crypto/crypto_engine.c
@@ -7,6 +7,7 @@
* Author: Baolin Wang <baolin.wang@xxxxxxxxxx>
*/

+#include <crypto/internal/acompress.h>
#include <crypto/internal/aead.h>
#include <crypto/internal/akcipher.h>
#include <crypto/internal/engine.h>
@@ -220,6 +221,19 @@ static int crypto_transfer_request_to_engine(struct crypto_engine *engine,
return crypto_transfer_request(engine, req, true);
}

+/**
+ * crypto_transfer_acomp_request_to_engine - transfer one acomp_request
+ * to list into the engine queue
+ * @engine: the hardware engine
+ * @req: the request need to be listed into the engine queue
+ */
+int crypto_transfer_acomp_request_to_engine(struct crypto_engine *engine,
+ struct acomp_req *req)
+{
+ return crypto_transfer_request_to_engine(engine, &req->base);
+}
+EXPORT_SYMBOL_GPL(crypto_transfer_acomp_request_to_engine);
+
/**
* crypto_transfer_aead_request_to_engine - transfer one aead_request
* to list into the engine queue
@@ -285,6 +299,20 @@ int crypto_transfer_skcipher_request_to_engine(struct crypto_engine *engine,
}
EXPORT_SYMBOL_GPL(crypto_transfer_skcipher_request_to_engine);

+/**
+ * crypto_finalize_acomp_request - finalize one acomp_request if
+ * the request is done
+ * @engine: the hardware engine
+ * @req: the request need to be finalized
+ * @err: error number
+ */
+void crypto_finalize_acomp_request(struct crypto_engine *engine,
+ struct acomp_req *req, int err)
+{
+ return crypto_finalize_request(engine, &req->base, err);
+}
+EXPORT_SYMBOL_GPL(crypto_finalize_acomp_request);
+
/**
* crypto_finalize_aead_request - finalize one aead_request if
* the request is done
@@ -504,6 +532,20 @@ void crypto_engine_exit(struct crypto_engine *engine)
}
EXPORT_SYMBOL_GPL(crypto_engine_exit);

+int crypto_engine_register_acomp(struct acomp_engine_alg *alg)
+{
+ if (!alg->op.do_one_request)
+ return -EINVAL;
+ return crypto_register_acomp(&alg->base);
+}
+EXPORT_SYMBOL_GPL(crypto_engine_register_acomp);
+
+void crypto_engine_unregister_acomp(struct acomp_engine_alg *alg)
+{
+ crypto_unregister_acomp(&alg->base);
+}
+EXPORT_SYMBOL_GPL(crypto_engine_unregister_acomp);
+
int crypto_engine_register_aead(struct aead_engine_alg *alg)
{
if (!alg->op.do_one_request)
diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h
index 5d5358dfab73..0809fa35490a 100644
--- a/include/crypto/acompress.h
+++ b/include/crypto/acompress.h
@@ -122,6 +122,39 @@ struct crypto_acomp {
}
struct comp_alg_common COMP_ALG_COMMON;

+/**
+ * struct acomp_alg - asynchronous compression algorithm
+ *
+ * @compress: Function performs a compress operation
+ * @decompress: Function performs a de-compress operation
+ * @init: Initialize the cryptographic transformation object.
+ * This function is used to initialize the cryptographic
+ * transformation object. This function is called only once at
+ * the instantiation time, right after the transformation context
+ * was allocated. In case the cryptographic hardware has some
+ * special requirements which need to be handled by software, this
+ * function shall check for the precise requirement of the
+ * transformation and put any software fallbacks in place.
+ * @exit: Deinitialize the cryptographic transformation object. This is a
+ * counterpart to @init, used to remove various changes set in
+ * @init.
+ *
+ * @base: Common crypto API algorithm data structure
+ * @calg: Common algorithm data structure shared with scomp
+ * @COMP_ALG_COMMON: see struct comp_alg_common
+ */
+struct acomp_alg {
+ int (*compress)(struct acomp_req *req);
+ int (*decompress)(struct acomp_req *req);
+ int (*init)(struct crypto_acomp *tfm);
+ void (*exit)(struct crypto_acomp *tfm);
+
+ union {
+ struct COMP_ALG_COMMON;
+ struct comp_alg_common calg;
+ };
+};
+
/**
* DOC: Asynchronous Compression API
*
diff --git a/include/crypto/engine.h b/include/crypto/engine.h
index 2e60344437da..2b4e3d0e43ed 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/acompress.h>
#include <crypto/aead.h>
#include <crypto/akcipher.h>
#include <crypto/hash.h>
@@ -26,6 +27,11 @@ struct crypto_engine_op {
void *areq);
};

+struct acomp_engine_alg {
+ struct acomp_alg base;
+ struct crypto_engine_op op;
+};
+
struct aead_engine_alg {
struct aead_alg base;
struct crypto_engine_op op;
@@ -51,6 +57,8 @@ struct skcipher_engine_alg {
struct crypto_engine_op op;
};

+int crypto_transfer_acomp_request_to_engine(struct crypto_engine *engine,
+ struct acomp_req *req);
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,
@@ -61,6 +69,8 @@ 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_acomp_request(struct crypto_engine *engine,
+ struct acomp_req *req, int err);
void crypto_finalize_aead_request(struct crypto_engine *engine,
struct aead_request *req, int err);
void crypto_finalize_akcipher_request(struct crypto_engine *engine,
@@ -79,6 +89,9 @@ struct crypto_engine *crypto_engine_alloc_init_and_set(struct device *dev,
bool rt, int qlen);
void crypto_engine_exit(struct crypto_engine *engine);

+int crypto_engine_register_acomp(struct acomp_engine_alg *alg);
+void crypto_engine_unregister_acomp(struct acomp_engine_alg *alg);
+
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);
diff --git a/include/crypto/internal/acompress.h b/include/crypto/internal/acompress.h
index 9cd37df32dc4..75580e007c0c 100644
--- a/include/crypto/internal/acompress.h
+++ b/include/crypto/internal/acompress.h
@@ -23,39 +23,6 @@
struct acomp_req *name = acomp_fbreq_on_stack_init( \
__##name##_req, (req))

-/**
- * struct acomp_alg - asynchronous compression algorithm
- *
- * @compress: Function performs a compress operation
- * @decompress: Function performs a de-compress operation
- * @init: Initialize the cryptographic transformation object.
- * This function is used to initialize the cryptographic
- * transformation object. This function is called only once at
- * the instantiation time, right after the transformation context
- * was allocated. In case the cryptographic hardware has some
- * special requirements which need to be handled by software, this
- * function shall check for the precise requirement of the
- * transformation and put any software fallbacks in place.
- * @exit: Deinitialize the cryptographic transformation object. This is a
- * counterpart to @init, used to remove various changes set in
- * @init.
- *
- * @base: Common crypto API algorithm data structure
- * @calg: Cmonn algorithm data structure shared with scomp
- * @COMP_ALG_COMMON: see struct comp_alg_common
- */
-struct acomp_alg {
- int (*compress)(struct acomp_req *req);
- int (*decompress)(struct acomp_req *req);
- int (*init)(struct crypto_acomp *tfm);
- void (*exit)(struct crypto_acomp *tfm);
-
- union {
- struct COMP_ALG_COMMON;
- struct comp_alg_common calg;
- };
-};
-
struct crypto_acomp_stream {
spinlock_t lock;
void *ctx;
--
2.43.0