libluna+kernel: Make CRC32 a class
This commit is contained in:
parent
49a6c39c38
commit
e8e05159c1
@ -66,6 +66,9 @@ namespace GPT
|
||||
{
|
||||
header.checksum = 0;
|
||||
|
||||
return CRC32::checksum((u8*)&header, 0x5c);
|
||||
CRC32 crc;
|
||||
crc.append((u8*)&header, 0x5c);
|
||||
|
||||
return crc.digest();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,13 @@
|
||||
#pragma once
|
||||
#include <luna/Types.h>
|
||||
|
||||
namespace CRC32
|
||||
class CRC32
|
||||
{
|
||||
u32 checksum(const u8* data, usize size);
|
||||
}
|
||||
public:
|
||||
void append(const u8* data, usize size);
|
||||
|
||||
u32 digest();
|
||||
|
||||
private:
|
||||
u32 m_checksum = 0xffffffffu;
|
||||
};
|
||||
|
@ -33,18 +33,16 @@ static const u32 crc_table[] = {
|
||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
||||
};
|
||||
|
||||
namespace CRC32
|
||||
void CRC32::append(const u8* data, usize size)
|
||||
{
|
||||
u32 checksum(const u8* data, usize size)
|
||||
for (usize i = 0; i < size; i++)
|
||||
{
|
||||
u32 crc = 0xffffffffu;
|
||||
|
||||
for (usize i = 0; i < size; i++)
|
||||
{
|
||||
const u32 index = (crc & 0xff) ^ data[i];
|
||||
crc = (crc >> 8) ^ (crc_table[index]);
|
||||
}
|
||||
|
||||
return ~crc;
|
||||
const u32 index = (m_checksum & 0xff) ^ data[i];
|
||||
m_checksum = (m_checksum >> 8) ^ (crc_table[index]);
|
||||
}
|
||||
}
|
||||
|
||||
u32 CRC32::digest()
|
||||
{
|
||||
return ~m_checksum;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user