]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: ahash - Set default reqsize from ahash_alg
authorHerbert Xu <herbert@gondor.apana.org.au>
Sun, 16 Feb 2025 03:07:24 +0000 (11:07 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sat, 22 Feb 2025 08:09:05 +0000 (16:09 +0800)
Add a reqsize field to struct ahash_alg and use it to set the
default reqsize so that algorithms with a static reqsize are
not forced to create an init_tfm function.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/ahash.c
include/crypto/hash.h

index 208aa4c8d7252844022fe8b2dd30c4f1857f3433..9c26175c21a8f79fc4b37d0bb359a143c09879a6 100644 (file)
@@ -879,6 +879,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);
 
        if (tfm->__crt_alg->cra_type == &crypto_shash_type)
                return crypto_init_ahash_using_shash(tfm);
@@ -1044,6 +1045,9 @@ static int ahash_prepare_alg(struct ahash_alg *alg)
        if (alg->halg.statesize == 0)
                return -EINVAL;
 
+       if (alg->reqsize && alg->reqsize < alg->halg.statesize)
+               return -EINVAL;
+
        err = hash_prepare_alg(&alg->halg);
        if (err)
                return err;
index 4e87e39679cb58e3966aecac7c3fd19b757dbb46..2aa83ee0ec989b31f0bf418f5ef8bf15865e9fd3 100644 (file)
@@ -135,6 +135,7 @@ 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 {
@@ -151,6 +152,8 @@ 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;
 };