]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: s390/sha512 - Fix sha512 state size
authorHerbert Xu <herbert@gondor.apana.org.au>
Tue, 29 Apr 2025 09:12:30 +0000 (17:12 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Wed, 30 Apr 2025 02:49:20 +0000 (10:49 +0800)
The sha512 state size in s390_sha_ctx is out by a factor of 8,
fix it so that it stays below HASH_MAX_DESCSIZE.  Also fix the
state init function which was writing garbage to the state.  Luckily
this is not actually used for anything other than export.

Reported-by: Harald Freudenberger <freude@linux.ibm.com>
Fixes: 572b5c4682c7 ("crypto: s390/sha512 - Use API partial block handling")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
arch/s390/crypto/sha.h
arch/s390/crypto/sha512_s390.c

index 0a3cc17391443f6215c21bdc6692ed5d9d80b40b..d757ccbce2b4f4fe76db6654264ebbf97313098d 100644 (file)
@@ -24,7 +24,7 @@ struct s390_sha_ctx {
        union {
                u32 state[CPACF_MAX_PARMBLOCK_SIZE / sizeof(u32)];
                struct {
-                       u64 state[SHA512_DIGEST_SIZE];
+                       u64 state[SHA512_DIGEST_SIZE / sizeof(u64)];
                        u64 count_hi;
                } sha512;
        };
index 14818fcc9cd4f84c102ef981b398360a65cef28f..3c5175e6dda61aa98e8b29304190351c420dfeec 100644 (file)
@@ -22,13 +22,13 @@ static int sha512_init(struct shash_desc *desc)
        struct s390_sha_ctx *ctx = shash_desc_ctx(desc);
 
        ctx->sha512.state[0] = SHA512_H0;
-       ctx->sha512.state[2] = SHA512_H1;
-       ctx->sha512.state[4] = SHA512_H2;
-       ctx->sha512.state[6] = SHA512_H3;
-       ctx->sha512.state[8] = SHA512_H4;
-       ctx->sha512.state[10] = SHA512_H5;
-       ctx->sha512.state[12] = SHA512_H6;
-       ctx->sha512.state[14] = SHA512_H7;
+       ctx->sha512.state[1] = SHA512_H1;
+       ctx->sha512.state[2] = SHA512_H2;
+       ctx->sha512.state[3] = SHA512_H3;
+       ctx->sha512.state[4] = SHA512_H4;
+       ctx->sha512.state[5] = SHA512_H5;
+       ctx->sha512.state[6] = SHA512_H6;
+       ctx->sha512.state[7] = SHA512_H7;
        ctx->count = 0;
        ctx->sha512.count_hi = 0;
        ctx->func = CPACF_KIMD_SHA_512;