Skip to contentSkip to conversation

crypto: Add reqsize to crypto_alg

PATCH New Herbert Xu 1 participant 8 messages Apr 7, 2025

Subsystems (3)
lore
Share & tools
lore

Herbert Xu

author maintainer
#0 lore raw

cover crypto: Add reqsize to crypto_alg

This patch series adds a reqsize field to the bas struct crypto_alg. A dynamic reqsize was needed for fallback algorithms. As we will switching to synchronous fallbacks with requests allocated on the stack, this will no longer be necessary.

Also document the fact tha cra_init and cra_exit should not be used in new code.

Herbert Xu (7):
crypto: api - Mark cra_init/cra_exit as deprecated
crypto: api - Add reqsize to crypto_alg
crypto: acomp - Use cra_reqsize
crypto: qat - Use cra_reqsize for acomp
crypto: iaa - Use cra_reqsize for acomp
crypto: acomp - Remove reqsize field
crypto: ahash - Use cra_reqsize

 crypto/acompress.c                            |  2 +-
 crypto/ahash.c                                |  4 ++--
 drivers/crypto/intel/iaa/iaa_crypto_main.c    |  2 +-
 .../intel/qat/qat_common/qat_comp_algs.c      |  2 +-
 include/crypto/hash.h                         |  3 ---
 include/crypto/internal/acompress.h           |  3 ---
 include/linux/crypto.h                        | 20 +++++++++----------
 7 files changed, 14 insertions(+), 22 deletions(-)
Signature · 1 line
2.39.5
author maintainer
#1 lore raw

PATCH 1/7 crypto: api - Mark cra_init/cra_exit as deprecated

These functions have been obsoleted by the type-specific init/exit functions.

---
 include/linux/crypto.h | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
include/linux/crypto.h +2 -11
index a387f1547ea0..56cf229e2530 100644
@@ -300,17 +300,8 @@ struct cipher_alg {
  *	   by @cra_type and @cra_flags above, the associated structure must be
  *	   filled with callbacks. This field might be empty. This is the case
  *	   for ahash, shash.
- * @cra_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.
- * @cra_exit: Deinitialize the cryptographic transformation object. This is a
- *	      counterpart to @cra_init, used to remove various changes set in
- *	      @cra_init.
+ * @cra_init: Deprecated, do not use.
+ * @cra_exit: Deprecated, do not use.
  * @cra_u.cipher: Union member which contains a single-block symmetric cipher
  *		  definition. See @struct @cipher_alg.
  * @cra_module: Owner of this transformation implementation. Set to THIS_MODULE
Signature · 1 line
2.39.5
author maintainer
#2 lore raw

PATCH 2/7 crypto: api - Add reqsize to crypto_alg

In reply to Herbert Xu

Add a reqsize field to crypto_alg with the intention of replacing the type-specific reqsize field currently used by ahash and acomp.

---
 include/linux/crypto.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/linux/crypto.h +7 -0
index 56cf229e2530..15476b085ce3 100644
@@ -276,6 +276,7 @@ struct cipher_alg {
  *		   to the alignmask of the algorithm being used, in order to
  *		   avoid the API having to realign them.  Note: the alignmask is
  *		   not supported for hash algorithms and is always 0 for them.
+ * @cra_reqsize: Size of the request context for this algorithm.
  * @cra_priority: Priority of this transformation implementation. In case
  *		  multiple transformations with same @cra_name are available to
  *		  the Crypto API, the kernel will use the one with highest
@@ -322,6 +323,7 @@ struct crypto_alg {
 	unsigned int cra_blocksize;
 	unsigned int cra_ctxsize;
 	unsigned int cra_alignmask;
+	unsigned int cra_reqsize;
 
 	int cra_priority;
 	refcount_t cra_refcnt;
@@ -441,6 +443,11 @@ static inline unsigned int crypto_tfm_alg_alignmask(struct crypto_tfm *tfm)
 	return tfm->__crt_alg->cra_alignmask;
 }
 
+static inline unsigned int crypto_tfm_alg_reqsize(struct crypto_tfm *tfm)
+{
+	return tfm->__crt_alg->cra_reqsize;
+}
+
 static inline u32 crypto_tfm_get_flags(struct crypto_tfm *tfm)
 {
 	return tfm->crt_flags;
Signature · 1 line
2.39.5
author maintainer
#3 lore raw

PATCH 3/7 crypto: acomp - Use cra_reqsize

In reply to Herbert Xu

Use the common reqsize if present.

---
 crypto/acompress.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/acompress.c +1 -1
index 869c926d3986..e9406eb8fcf4 100644
@@ -109,7 +109,7 @@ static int crypto_acomp_init_tfm(struct crypto_tfm *tfm)
 
 	acomp->compress = alg->compress;
 	acomp->decompress = alg->decompress;
-	acomp->reqsize = alg->reqsize;
+	acomp->reqsize = alg->base.cra_reqsize ?: alg->reqsize;
 
 	acomp->base.exit = crypto_acomp_exit_tfm;
 
Signature · 1 line
2.39.5
author maintainer
#4 lore raw

PATCH 4/7 crypto: qat - Use cra_reqsize for acomp

In reply to Herbert Xu

Use the common reqsize field for acomp algorithms.

---
 drivers/crypto/intel/qat/qat_common/qat_comp_algs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/intel/qat/qat_common/qat_comp_algs.c +1 -1
index a6e02405d402..a0a29b97a749 100644
@@ -241,13 +241,13 @@ static struct acomp_alg qat_acomp[] = { {
 		.cra_priority = 4001,
 		.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY,
 		.cra_ctxsize = sizeof(struct qat_compression_ctx),
+		.cra_reqsize = sizeof(struct qat_compression_req),
 		.cra_module = THIS_MODULE,
 	},
 	.init = qat_comp_alg_init_tfm,
 	.exit = qat_comp_alg_exit_tfm,
 	.compress = qat_comp_alg_compress,
 	.decompress = qat_comp_alg_decompress,
-	.reqsize = sizeof(struct qat_compression_req),
 }};
 
 int qat_comp_algs_register(void)
Signature · 1 line
2.39.5
author maintainer
#5 lore raw

PATCH 5/7 crypto: iaa - Use cra_reqsize for acomp

In reply to Herbert Xu

Use the common reqsize field for acomp algorithms.

---
 drivers/crypto/intel/iaa/iaa_crypto_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/intel/iaa/iaa_crypto_main.c +1 -1
index b4f15e738cee..be3b899c6977 100644
@@ -1685,12 +1685,12 @@ static struct acomp_alg iaa_acomp_fixed_deflate = {
 	.init			= iaa_comp_init_fixed,
 	.compress		= iaa_comp_acompress,
 	.decompress		= iaa_comp_adecompress,
-	.reqsize		= sizeof(u32),
 	.base			= {
 		.cra_name		= "deflate",
 		.cra_driver_name	= "deflate-iaa",
 		.cra_flags		= CRYPTO_ALG_ASYNC,
 		.cra_ctxsize		= sizeof(struct iaa_compression_ctx),
+		.cra_reqsize		= sizeof(u32),
 		.cra_module		= THIS_MODULE,
 		.cra_priority		= IAA_ALG_PRIORITY,
 	}
Signature · 1 line
2.39.5
author maintainer
#6 lore raw

PATCH 6/7 crypto: acomp - Remove reqsize field

In reply to Herbert Xu

Remove the type-specific reqsize field in favour of the common one.

---
 crypto/acompress.c                  | 2 +-
 include/crypto/internal/acompress.h | 3 ---
 2 files changed, 1 insertion(+), 4 deletions(-)
crypto/acompress.c +1 -1
index e9406eb8fcf4..dbf647810e50 100644
@@ -109,7 +109,7 @@ static int crypto_acomp_init_tfm(struct crypto_tfm *tfm)
 
 	acomp->compress = alg->compress;
 	acomp->decompress = alg->decompress;
-	acomp->reqsize = alg->base.cra_reqsize ?: alg->reqsize;
+	acomp->reqsize = alg->base.cra_reqsize;
 
 	acomp->base.exit = crypto_acomp_exit_tfm;
 
include/crypto/internal/acompress.h +0 -3
index d6d53c7696fd..0f3ad65be2d9 100644
@@ -40,7 +40,6 @@
  *		counterpart to @init, used to remove various changes set in
  *		@init.
  *
- * @reqsize:	Context size for (de)compression requests
  * @base:	Common crypto API algorithm data structure
  * @calg:	Cmonn algorithm data structure shared with scomp
  */
@@ -50,8 +49,6 @@ struct acomp_alg {
 	int (*init)(struct crypto_acomp *tfm);
 	void (*exit)(struct crypto_acomp *tfm);
 
-	unsigned int reqsize;
-
 	union {
 		struct COMP_ALG_COMMON;
 		struct comp_alg_common calg;
Signature · 1 line
2.39.5
author maintainer
#7 lore raw

PATCH 7/7 crypto: ahash - Use cra_reqsize

In reply to Herbert Xu

Use the common reqsize field and remove reqsize from ahash_alg.

---
 crypto/ahash.c        | 4 ++--
 include/crypto/hash.h | 3 ---
 2 files changed, 2 insertions(+), 5 deletions(-)
crypto/ahash.c +2 -2
index 079216180ad1..ad3f1e011a69 100644
@@ -723,7 +723,7 @@ static int crypto_ahash_init_tfm(struct crypto_tfm *tfm)
 	struct ahash_alg *alg = crypto_ahash_alg(hash);
 
 	crypto_ahash_set_statesize(hash, alg->halg.statesize);
-	crypto_ahash_set_reqsize(hash, alg->reqsize);
+	crypto_ahash_set_reqsize(hash, crypto_tfm_alg_reqsize(tfm));
 
 	if (tfm->__crt_alg->cra_type == &crypto_shash_type)
 		return crypto_init_ahash_using_shash(tfm);
@@ -889,7 +889,7 @@ static int ahash_prepare_alg(struct ahash_alg *alg)
 	if (alg->halg.statesize == 0)
 		return -EINVAL;
 
-	if (alg->reqsize && alg->reqsize < alg->halg.statesize)
+	if (base->cra_reqsize && base->cra_reqsize < alg->halg.statesize)
 		return -EINVAL;
 
 	err = hash_prepare_alg(&alg->halg);
include/crypto/hash.h +0 -3
index c14a3a90613f..a80dfa57656f 100644
@@ -135,7 +135,6 @@ struct ahash_request {
  *	      This is a counterpart to @init_tfm, used to remove
  *	      various changes set in @init_tfm.
  * @clone_tfm: Copy transform into new object, may allocate memory.
- * @reqsize: Size of the request context.
  * @halg: see struct hash_alg_common
  */
 struct ahash_alg {
@@ -152,8 +151,6 @@ struct ahash_alg {
 	void (*exit_tfm)(struct crypto_ahash *tfm);
 	int (*clone_tfm)(struct crypto_ahash *dst, struct crypto_ahash *src);
 
-	unsigned int reqsize;
-
 	struct hash_alg_common halg;
 };
 
Signature · 1 line
2.39.5