lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <4f6ebdb42f3a999cc77e81dc1ceeb4ea46f615df.1714581792.git.andre.glover@linux.intel.com>
Date: Wed,  1 May 2024 14:46:27 -0700
From: Andre Glover <andre.glover@...ux.intel.com>
To: tom.zanussi@...ux.intel.com,
	minchan@...nel.org,
	senozhatsky@...omium.org,
	hannes@...xchg.org,
	yosryahmed@...gle.com,
	nphamcs@...il.com,
	chengming.zhou@...ux.dev,
	herbert@...dor.apana.org.au,
	davem@...emloft.net,
	fenghua.yu@...el.com,
	dave.jiang@...el.com
Cc: wajdi.k.feghali@...el.com,
	james.guilford@...el.com,
	vinodh.gopal@...el.com,
	bala.seshasayee@...el.com,
	heath.caldwell@...el.com,
	kanchana.p.sridhar@...el.com,
	andre.glover@...ux.intel.com,
	linux-kernel@...r.kernel.org,
	linux-mm@...ck.org,
	21cnbao@...il.com,
	ryan.roberts@....com,
	linux-crypto@...r.kernel.org,
	dmaengine@...r.kernel.org
Subject: [RFC PATCH 1/3] crypto: Add pre_alloc and post_free callbacks for acomp algorithms

Add callbacks to acomp crypto algorithms that facilitate the allocation and
subsequent freeing of resources required by an acomp_req before and after
a series of compress and/or decompress operations.

Signed-off-by: Andre Glover <andre.glover@...ux.intel.com>
---
 crypto/acompress.c                  | 13 +++++++++++++
 include/crypto/acompress.h          |  2 ++
 include/crypto/internal/acompress.h |  6 ++++++
 3 files changed, 21 insertions(+)

diff --git a/crypto/acompress.c b/crypto/acompress.c
index 6fdf0ff9f3c0..873918be75cc 100644
--- a/crypto/acompress.c
+++ b/crypto/acompress.c
@@ -71,9 +71,13 @@ static int crypto_acomp_init_tfm(struct crypto_tfm *tfm)
 
 	acomp->compress = alg->compress;
 	acomp->decompress = alg->decompress;
+
 	acomp->dst_free = alg->dst_free;
 	acomp->reqsize = alg->reqsize;
 
+	acomp->pre_alloc = alg->pre_alloc;
+	acomp->post_free = alg->post_free;
+
 	if (alg->exit)
 		acomp->base.exit = crypto_acomp_exit_tfm;
 
@@ -129,6 +133,12 @@ struct acomp_req *acomp_request_alloc(struct crypto_acomp *acomp)
 	struct acomp_req *req;
 
 	req = __acomp_request_alloc(acomp);
+
+	if (req && (acomp->pre_alloc && acomp->pre_alloc(req))) {
+		__acomp_request_free(req);
+		return NULL;
+	}
+
 	if (req && (tfm->__crt_alg->cra_type != &crypto_acomp_type))
 		return crypto_acomp_scomp_alloc_ctx(req);
 
@@ -144,6 +154,9 @@ void acomp_request_free(struct acomp_req *req)
 	if (tfm->__crt_alg->cra_type != &crypto_acomp_type)
 		crypto_acomp_scomp_free_ctx(req);
 
+	if (acomp->post_free)
+		acomp->post_free(req);
+
 	if (req->flags & CRYPTO_ACOMP_ALLOC_OUTPUT) {
 		acomp->dst_free(req->dst);
 		req->dst = NULL;
diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h
index 54937b615239..2b73cef2f430 100644
--- a/include/crypto/acompress.h
+++ b/include/crypto/acompress.h
@@ -51,6 +51,8 @@ struct acomp_req {
 struct crypto_acomp {
 	int (*compress)(struct acomp_req *req);
 	int (*decompress)(struct acomp_req *req);
+	int (*pre_alloc)(struct acomp_req *req);
+	void (*post_free)(struct acomp_req *req);
 	void (*dst_free)(struct scatterlist *dst);
 	unsigned int reqsize;
 	struct crypto_tfm base;
diff --git a/include/crypto/internal/acompress.h b/include/crypto/internal/acompress.h
index d00392d1988e..081e1cf5235f 100644
--- a/include/crypto/internal/acompress.h
+++ b/include/crypto/internal/acompress.h
@@ -29,6 +29,10 @@
  * @exit:	Deinitialize the cryptographic transformation object. This is a
  *		counterpart to @init, used to remove various changes set in
  *		@init.
+ * @pre_alloc:	Function that performs any pre-allocation and setup that an
+ *		algorithm may require on a per req basis.
+ * @post_free:	Function that performs any post freeing that an algorithm
+ *		may require on a per req basis.
  *
  * @reqsize:	Context size for (de)compression requests
  * @base:	Common crypto API algorithm data structure
@@ -40,6 +44,8 @@ struct acomp_alg {
 	void (*dst_free)(struct scatterlist *dst);
 	int (*init)(struct crypto_acomp *tfm);
 	void (*exit)(struct crypto_acomp *tfm);
+	int (*pre_alloc)(struct acomp_req *req);
+	void (*post_free)(struct acomp_req *req);
 
 	unsigned int reqsize;
 
-- 
2.27.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ