-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathHashWhirlpool.c
64 lines (49 loc) · 1.41 KB
/
HashWhirlpool.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
53
54
55
56
57
58
59
60
61
62
63
64
#include "HashWhirlpool.h"
#ifdef USE_WHIRL
#include "whirlpool.h"
int HashFinishWhirlpool(HASH *Hash, char **HashStr)
{
int len;
char *DigestBuff=NULL;
DigestBuff=(char *) calloc(1,WHIRLPOOL_DIGESTBYTES+1);
WHIRLPOOLfinalize((WHIRLPOOLstruct *) Hash->Ctx, (unsigned char *) DigestBuff);
len=WHIRLPOOL_DIGESTBYTES;
*HashStr=SetStrLen(*HashStr,len);
memcpy(*HashStr,DigestBuff,len);
DestroyString(DigestBuff);
return(len);
}
void HashUpdateWhirlpool(HASH *Hash, const char *Data, int Len)
{
WHIRLPOOLadd((unsigned char *) Data, Len * 8, (WHIRLPOOLstruct *) Hash->Ctx);
}
HASH *HashCloneWhirlpool(HASH *Hash)
{
HASH *NewHash;
NewHash=(HASH *) calloc(1,sizeof(HASH));
NewHash->Type=CopyStr(NewHash->Type,Hash->Type);
NewHash->Ctx=(void *) calloc(1,sizeof(WHIRLPOOLstruct *));
memcpy(NewHash->Ctx, Hash->Ctx, sizeof(WHIRLPOOLstruct *));
return(NewHash);
}
#endif
int HashInitWhirlpool(HASH *Hash, const char *Name, int Len)
{
#ifdef USE_WHIRL
Hash->Ctx=(void *) calloc(1,sizeof(WHIRLPOOLstruct));
WHIRLPOOLinit((WHIRLPOOLstruct *) Hash->Ctx);
Hash->Update=HashUpdateWhirlpool;
Hash->Finish=HashFinishWhirlpool;
Hash->Clone=HashCloneWhirlpool;
return(TRUE);
#else
return(FALSE);
#endif
}
void HashRegisterWhirlpool()
{
#ifdef USE_WHIRL
HashRegister("whirl", 0, HashInitWhirlpool);
HashRegister("whirlpool", 0, HashInitWhirlpool);
#endif
}