mirror of
https://github.com/subhobhai943/SUB-OS.git
synced 2026-10-25 16:52:29 +00:00
Initial commit: SUB-OS 64-Bit Production Monolithic Operating System with LazyBox userland suite
This commit is contained in:
commit
cd9c786d14
88 files changed
+7132
No files matched your search
@@ -0,0 +1,35 @@
|
||||
#include <crypto/crypto.h>
|
||||
|
||||
static uint32_t crc32_table[256];
|
||||
static bool table_computed = false;
|
||||
|
||||
static void make_crc32_table(void) {
|
||||
uint32_t c;
|
||||
for (uint32_t n = 0; n < 256; n++) {
|
||||
c = n;
|
||||
for (int k = 0; k < 8; k++) {
|
||||
if (c & 1) {
|
||||
c = 0xEDB88320L ^ (c >> 1);
|
||||
} else {
|
||||
c = c >> 1;
|
||||
}
|
||||
}
|
||||
crc32_table[n] = c;
|
||||
}
|
||||
table_computed = true;
|
||||
}
|
||||
|
||||
uint32_t crc32(uint32_t crc, const void* buf, size_t size) {
|
||||
if (!table_computed) {
|
||||
make_crc32_table();
|
||||
}
|
||||
|
||||
const uint8_t* p = (const uint8_t*)buf;
|
||||
crc = crc ^ 0xFFFFFFFF;
|
||||
|
||||
while (size--) {
|
||||
crc = crc32_table[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
|
||||
}
|
||||
|
||||
return crc ^ 0xFFFFFFFF;
|
||||
}
|
||||
Reference in new issue
Block a user