diff --git a/kernel/src/fs/GPT.cpp b/kernel/src/fs/GPT.cpp index e3556a5f..46eb2a54 100644 --- a/kernel/src/fs/GPT.cpp +++ b/kernel/src/fs/GPT.cpp @@ -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(); } } diff --git a/libluna/include/luna/CRC32.h b/libluna/include/luna/CRC32.h index 8b019756..4e4c033e 100644 --- a/libluna/include/luna/CRC32.h +++ b/libluna/include/luna/CRC32.h @@ -1,7 +1,13 @@ #pragma once #include -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; +}; diff --git a/libluna/src/CRC32.cpp b/libluna/src/CRC32.cpp index d23ff684..66594c74 100644 --- a/libluna/src/CRC32.cpp +++ b/libluna/src/CRC32.cpp @@ -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; +}