forked from kif/imageAlignment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrc64.cpp
More file actions
35 lines (31 loc) · 645 Bytes
/
Copy pathcrc64.cpp
File metadata and controls
35 lines (31 loc) · 645 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdint.h>
#define POLY64REV 0x95AC9329AC4BC9B5
#define INITIALCRC 0xFFFFFFFFFFFFFFFF
uint64_t crc64(char *seq, unsigned int lg_seq)
{
unsigned short i;
unsigned char j;
uint64_t crc = INITIALCRC;
uint64_t part;
static bool init = false;
static uint64_t CRCTable[256];
if (!init)
{
init = true;
for (i = 0; i < 256; i++)
{
part = i;
for (j = 0; j < 8; j++)
{
if (part & 1)
part = (part >> 1) ^ POLY64REV;
else
part >>= 1;
}
CRCTable[i] = part;
}
}
while (lg_seq-- > 0)
crc = CRCTable[(crc ^ *seq++) & 0xff] ^ (crc >> 8);
return crc;
}