]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: padlock-sha - Use core import and export for fallback
authorHerbert Xu <herbert@gondor.apana.org.au>
Sun, 4 May 2025 13:33:25 +0000 (21:33 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Mon, 5 May 2025 10:20:46 +0000 (18:20 +0800)
As padlock-sha is block-only, it needs to use core import and
export on the fallback.

Also call sha256_block_init instead of sha256_init although this
is harmless as sha256_init doesn't write into the partial block
area.

Fixes: 63dc06cd12f9 ("crypto: padlock-sha - Use API partial block handling")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/padlock-sha.c

index c89b9c6b5f4cc1c0da7de03540abb7e795c74008..329f60ad422e6fbec8639278a592561a8607c33d 100644 (file)
@@ -42,27 +42,33 @@ static int padlock_sha1_init(struct shash_desc *desc)
 
 static int padlock_sha256_init(struct shash_desc *desc)
 {
-       struct sha256_state *sctx = padlock_shash_desc_ctx(desc);
+       struct crypto_sha256_state *sctx = padlock_shash_desc_ctx(desc);
 
-       sha256_init(sctx);
+       sha256_block_init(sctx);
        return 0;
 }
 
 static int padlock_sha_update(struct shash_desc *desc,
                              const u8 *data, unsigned int length)
 {
-       struct padlock_sha_ctx *ctx = crypto_shash_ctx(desc->tfm);
        u8 *state = padlock_shash_desc_ctx(desc);
-       HASH_REQUEST_ON_STACK(req, ctx->fallback);
-       int remain;
+       struct crypto_shash *tfm = desc->tfm;
+       int err, remain;
+
+       remain = length - round_down(length, crypto_shash_blocksize(tfm));
+       {
+               struct padlock_sha_ctx *ctx = crypto_shash_ctx(tfm);
+               HASH_REQUEST_ON_STACK(req, ctx->fallback);
+
+               ahash_request_set_callback(req, 0, NULL, NULL);
+               ahash_request_set_virt(req, data, NULL, length - remain);
+               err = crypto_ahash_import_core(req, state) ?:
+                     crypto_ahash_update(req) ?:
+                     crypto_ahash_export_core(req, state);
+               HASH_REQUEST_ZERO(req);
+       }
 
-       ahash_request_set_callback(req, 0, NULL, NULL);
-       ahash_request_set_virt(req, data, NULL, length);
-       remain = crypto_ahash_import(req, state) ?:
-                crypto_ahash_update(req);
-       if (remain < 0)
-               return remain;
-       return crypto_ahash_export(req, state) ?: remain;
+       return err ?: remain;
 }
 
 static int padlock_sha_export(struct shash_desc *desc, void *out)
@@ -101,7 +107,7 @@ static int padlock_sha_finup(struct shash_desc *desc, const u8 *in,
 
        ahash_request_set_callback(req, 0, NULL, NULL);
        ahash_request_set_virt(req, in, out, count);
-       return crypto_ahash_import(req, padlock_shash_desc_ctx(desc)) ?:
+       return crypto_ahash_import_core(req, padlock_shash_desc_ctx(desc)) ?:
               crypto_ahash_finup(req);
 }
 
@@ -165,7 +171,7 @@ static int padlock_init_tfm(struct crypto_shash *hash)
                return PTR_ERR(fallback_tfm);
        }
 
-       if (crypto_shash_statesize(hash) <
+       if (crypto_shash_statesize(hash) !=
            crypto_ahash_statesize(fallback_tfm)) {
                crypto_free_ahash(fallback_tfm);
                return -EINVAL;