linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Question regarding the use of CRC32c for checksumming
@ 2023-06-26 20:17 Pedro Falcato
  2023-06-28  4:52 ` Eric Biggers
  0 siblings, 1 reply; 5+ messages in thread
From: Pedro Falcato @ 2023-06-26 20:17 UTC (permalink / raw)
  To: linux-ext4, Darrick J. Wong

Hi,

(+CC the original author, Darrick)
I've been investigating (in the context of my EFI ext4 driver) why all
ext4 checksums appear inverted. After making sure my CRC32c
implementation was correct and up-to-par with other ones, I looked at
the fs/ext4 checksumming code, which took me to the implementation of
ext4_chksum in ext4.h (excuse the gmail whitespace damage):

>static inline u32 ext4_chksum(struct ext4_sb_info *sbi, u32 crc,
>       const void *address, unsigned int length)
>{
> struct {
> struct shash_desc shash;
> char ctx[4];
> } desc;

Open coding the crc32c crypto driver's internal state, seemingly to save a call?
>
> BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver)!=sizeof(desc.ctx));
>
> desc.shash.tfm = sbi->s_chksum_driver;
> *(u32 *)desc.ctx = crc;

...we set the starting CRC
>
> BUG_ON(crypto_shash_update(&desc.shash, address, length));

then call update, which keeps the current internal state in ctx[4]
>
> return *(u32 *)desc.ctx;

and then we never call ->final() (nor ->finup()), which for crc32c would do:
> put_unaligned_le32(~ctx->crc, out);

and as such get me the properly "inverted" crc32c I would expect.
FreeBSD never found this issue as their calculate_crc32c seems borked
too, and never inverts the result.

Is my assessment correct? Was ->final() never called on purpose, or is
it an accident? Or is this merely a CRC32c variation I'm unaware of?

I'd like to make sure I get all the context on this, before sending
any kind of documentation patch :)

Thanks,
Pedro

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-08-04 21:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-26 20:17 Question regarding the use of CRC32c for checksumming Pedro Falcato
2023-06-28  4:52 ` Eric Biggers
2023-06-28 18:58   ` Darrick J. Wong
2023-07-03 19:48     ` Eric Biggers
2023-08-04 21:08       ` Pedro Falcato

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).