add jamcrc
This commit is contained in:
parent
4a9ac7ac1a
commit
b46d409f11
2 changed files with 81 additions and 0 deletions
69
src/plugin_jamcrc.c
Normal file
69
src/plugin_jamcrc.c
Normal file
|
@ -0,0 +1,69 @@
|
|||
#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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue