1 ext4: use the shash api correctly for crc32c
3 From: "Darrick J. Wong" <darrick.wong@oracle.com>
5 Since we're using the crypto shash API, let's use the full API to set
6 the seed and get the final checksum instead assuming the private data
7 structure layout in crc32c.ko to which we're not privy.
9 Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
10 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
12 fs/ext4/ext4.h | 8 ++++++--
13 include/linux/jbd2.h | 8 ++++++--
14 2 files changed, 12 insertions(+), 4 deletions(-)
16 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
17 index 67352ab..93e0efe 100644
20 @@ -1784,18 +1784,22 @@ static inline u32 ext4_chksum(struct ext4_sb_info *sbi, u32 crc,
21 struct shash_desc shash;
27 BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver)!=sizeof(desc.ctx));
29 desc.shash.tfm = sbi->s_chksum_driver;
31 - *(u32 *)desc.ctx = crc;
32 + crc = cpu_to_le32(crc);
33 + crypto_shash_setkey(desc.shash.tfm, (u8 *)&crc, sizeof(crc));
34 + crypto_shash_init(&desc.shash);
36 err = crypto_shash_update(&desc.shash, address, length);
39 - return *(u32 *)desc.ctx;
40 + crypto_shash_final(&desc.shash, (u8 *)&out_crc);
41 + return le32_to_cpu(~out_crc);
45 diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
46 index 704b9a5..8ce1196 100644
47 --- a/include/linux/jbd2.h
48 +++ b/include/linux/jbd2.h
49 @@ -1374,6 +1374,7 @@ static inline u32 jbd2_chksum(journal_t *journal, u32 crc,
50 struct shash_desc shash;
51 char ctx[JBD_MAX_CHECKSUM_SIZE];
56 BUG_ON(crypto_shash_descsize(journal->j_chksum_driver) >
57 @@ -1381,12 +1382,15 @@ static inline u32 jbd2_chksum(journal_t *journal, u32 crc,
59 desc.shash.tfm = journal->j_chksum_driver;
61 - *(u32 *)desc.ctx = crc;
62 + crc = cpu_to_le32(crc);
63 + crypto_shash_setkey(desc.shash.tfm, (u8 *)&crc, sizeof(crc));
64 + crypto_shash_init(&desc.shash);
66 err = crypto_shash_update(&desc.shash, address, length);
69 - return *(u32 *)desc.ctx;
70 + crypto_shash_final(&desc.shash, (u8 *)&out_crc);
71 + return le32_to_cpu(~out_crc);
74 /* Return most recent uncommitted transaction */