Skip to content

Commit 307508d

Browse files
ebiggersherbertx
authored andcommitted
crypto: crct10dif-generic - fix use via crypto_shash_digest()
The ->digest() method of crct10dif-generic reads the current CRC value from the shash_desc context. But this value is uninitialized, causing crypto_shash_digest() to compute the wrong result. Fix it. Probably this wasn't noticed before because lib/crc-t10dif.c only uses crypto_shash_update(), not crypto_shash_digest(). Likewise, crypto_shash_digest() is not yet tested by the crypto self-tests because those only test the ahash API which only uses shash init/update/final. This bug was detected by my patches that improve testmgr to fuzz algorithms against their generic implementation. Fixes: 2d31e51 ("crypto: crct10dif - Wrap crc_t10dif function all to use crypto transform framework") Cc: <[email protected]> # v3.11+ Cc: Tim Chen <[email protected]> Signed-off-by: Eric Biggers <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent f947d7f commit 307508d

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

crypto/crct10dif_generic.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,9 @@ static int chksum_final(struct shash_desc *desc, u8 *out)
6565
return 0;
6666
}
6767

68-
static int __chksum_finup(__u16 *crcp, const u8 *data, unsigned int len,
69-
u8 *out)
68+
static int __chksum_finup(__u16 crc, const u8 *data, unsigned int len, u8 *out)
7069
{
71-
*(__u16 *)out = crc_t10dif_generic(*crcp, data, len);
70+
*(__u16 *)out = crc_t10dif_generic(crc, data, len);
7271
return 0;
7372
}
7473

@@ -77,15 +76,13 @@ static int chksum_finup(struct shash_desc *desc, const u8 *data,
7776
{
7877
struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
7978

80-
return __chksum_finup(&ctx->crc, data, len, out);
79+
return __chksum_finup(ctx->crc, data, len, out);
8180
}
8281

8382
static int chksum_digest(struct shash_desc *desc, const u8 *data,
8483
unsigned int length, u8 *out)
8584
{
86-
struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
87-
88-
return __chksum_finup(&ctx->crc, data, length, out);
85+
return __chksum_finup(0, data, length, out);
8986
}
9087

9188
static struct shash_alg alg = {

0 commit comments

Comments
 (0)