70 lines
1.2 KiB
C
70 lines
1.2 KiB
C
#include <stdbool.h>
|
|
#include "checksum.h"
|
|
|
|
static void init_crc32_tab(void);
|
|
static bool crc_tab32_init = false;
|
|
static uint32_t crc_tab32[256];
|
|
|
|
static void init_crc32_tab(void) {
|
|
|
|
uint32_t i;
|
|
uint32_t j;
|
|
uint32_t crc;
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
crc = i;
|
|
for (j = 0; j < 8; j++) {
|
|
if (crc & 0x00000001L) {
|
|
crc = (crc >> 1) ^ CRC_POLY_32;
|
|
}
|
|
else {
|
|
crc = crc >> 1;
|
|
}
|
|
}
|
|
crc_tab32[i] = crc;
|
|
}
|
|
crc_tab32_init = true;
|
|
}
|
|
|
|
const char* checkbrute_format()
|
|
{
|
|
return "JAMCRC";
|
|
}
|
|
|
|
const char* checkbrute_version()
|
|
{
|
|
return "0.1";
|
|
}
|
|
|
|
uint32_t checkbrute_hash32(unsigned char* data, size_t size)
|
|
{
|
|
uint32_t crc;
|
|
uint32_t tmp;
|
|
uint32_t long_c;
|
|
const unsigned char *ptr;
|
|
size_t a;
|
|
|
|
if (!crc_tab32_init)
|
|
init_crc32_tab();
|
|
|
|
crc = CRC_START_32;
|
|
ptr = data;
|
|
|
|
if (ptr != NULL)
|
|
for (a = 0; a < size; a++) {
|
|
long_c = 0x000000FFL & (uint32_t)*ptr;
|
|
tmp = crc ^ long_c;
|
|
crc = (crc >> 8) ^ crc_tab32[tmp & 0xff];
|
|
ptr++;
|
|
}
|
|
|
|
crc ^= 0x00000000L;
|
|
|
|
return crc & 0xffffffffL;
|
|
}
|
|
|
|
int checkbrute_hashsz()
|
|
{
|
|
return 4;
|
|
}
|