-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHashCRC32.c
52 lines (40 loc) · 1.13 KB
/
HashCRC32.c
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "HashCRC32.h"
#include "crc32.h"
void HashUpdateCRC(HASH *Hash, const char *Data, int Len)
{
crc32Update((unsigned long *) Hash->Ctx, (unsigned char *) Data, Len);
}
HASH *HashCloneCRC(HASH *Hash)
{
HASH *NewHash;
NewHash=(HASH *) calloc(1,sizeof(HASH));
NewHash->Type=CopyStr(NewHash->Type,Hash->Type);
NewHash->Ctx=(void *) calloc(1,sizeof(unsigned long));
memcpy(NewHash->Ctx, Hash->Ctx, sizeof(unsigned long));
return(NewHash);
}
int HashFinishCRC(HASH *Hash, char **HashStr)
{
unsigned long crc;
int len=0;
*HashStr=CopyStr(*HashStr, "");
len=sizeof(unsigned long);
crc32Finish((unsigned long *) Hash->Ctx);
crc=htonl(* (unsigned long *) Hash->Ctx);
*HashStr=SetStrLen(*HashStr,len);
memcpy(*HashStr,&crc,len);
return(len);
}
int HashInitCRC(HASH *Hash, const char *Name, int Len)
{
Hash->Ctx=(void *) calloc(1,sizeof(unsigned long));
crc32Init((unsigned long *) Hash->Ctx);
Hash->Update=HashUpdateCRC;
Hash->Finish=HashFinishCRC;
Hash->Clone=HashCloneCRC;
return(TRUE);
}
void HashRegisterCRC32()
{
HashRegister("crc32", 32, HashInitCRC);
}