-
Notifications
You must be signed in to change notification settings - Fork 2
/
HashJH.c
78 lines (57 loc) · 1.59 KB
/
HashJH.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "HashJH.h"
#include "jh_ref.h"
int HashFinishJH(HASH *Hash, char **HashStr)
{
int len;
char *DigestBuff=NULL;
DigestBuff=(char *) calloc(1,1024);
len=JHFinal((hashState *) Hash->Ctx, (unsigned char *) DigestBuff);
*HashStr=SetStrLen(*HashStr,len);
memcpy(*HashStr,DigestBuff,len);
DestroyString(DigestBuff);
return(len);
}
void HashUpdateJH(HASH *Hash, const char *Data, int Len)
{
JHUpdate( (hashState *) Hash->Ctx, (unsigned char *) Data, Len);
}
HASH *HashCloneJH(HASH *Hash)
{
HASH *NewHash;
NewHash=(HASH *) calloc(1,sizeof(HASH));
NewHash->Type=CopyStr(NewHash->Type,Hash->Type);
NewHash->Ctx=(void *) calloc(1,sizeof(hashState *));
memcpy(NewHash->Ctx, Hash->Ctx, sizeof(hashState *));
return(NewHash);
}
int HashInitJH(HASH *Hash, const char *Name, int Length)
{
switch (Length)
{
case 224:
case 256:
case 384:
case 512:
Hash->Ctx=(void *) calloc(1,sizeof(hashState));
JHInit((hashState *) Hash->Ctx, Length);
Hash->Update=HashUpdateJH;
Hash->Finish=HashFinishJH;
Hash->Clone=HashCloneJH;
break;
default:
return(FALSE);
break;
}
return(TRUE);
}
void HashRegisterJH()
{
HashRegister("jh224", 224, HashInitJH);
HashRegister("jh256", 256, HashInitJH);
HashRegister("jh384", 384, HashInitJH);
HashRegister("jh512", 512, HashInitJH);
HashRegister("jh-224", 224, HashInitJH);
HashRegister("jh-256", 256, HashInitJH);
HashRegister("jh-384", 384, HashInitJH);
HashRegister("jh-512", 512, HashInitJH);
}