kernel+libluna: Fix the CRC32 algorithm and use it to verify the GPT header
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-07-10 14:54:55 +02:00
parent 16b0531d42
commit 56f3d26969
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 1 additions and 5 deletions

View File

@ -29,7 +29,6 @@ namespace GPT
check(header.reserved == 0); check(header.reserved == 0);
check(header.this_lba == 1); check(header.this_lba == 1);
#if 0
const u32 chksum = checksum_gpt(header); const u32 chksum = checksum_gpt(header);
if (chksum != header.checksum) if (chksum != header.checksum)
@ -37,7 +36,6 @@ namespace GPT
kwarnln("gpt: Header checksum does not match, %#.8x != %#.8x!", chksum, header.checksum); kwarnln("gpt: Header checksum does not match, %#.8x != %#.8x!", chksum, header.checksum);
return false; return false;
} }
#endif
u64 partition_table_start = header.partition_table_lba * GPT_SECTOR_SIZE; u64 partition_table_start = header.partition_table_lba * GPT_SECTOR_SIZE;

View File

@ -35,15 +35,13 @@ static const u32 crc_table[] = {
namespace CRC32 namespace CRC32
{ {
// FIXME: This shouldn't return 0xffffffff when there are 4 zeros in a row somewhere in the data, right? That's what
// happens to the GPT header. (other CRC32 implementations don't seem to have this problem)
u32 checksum(const u8* data, usize size) u32 checksum(const u8* data, usize size)
{ {
u32 crc = 0xffffffffu; u32 crc = 0xffffffffu;
for (usize i = 0; i < size; i++) for (usize i = 0; i < size; i++)
{ {
const u32 index = (crc & data[i]) & 0xff; const u32 index = (crc & 0xff) ^ data[i];
crc = (crc >> 8) ^ (crc_table[index]); crc = (crc >> 8) ^ (crc_table[index]);
} }