-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathtlsh.c
80 lines (69 loc) · 1.18 KB
/
tlsh.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
79
80
#include <stdlib.h>
#include <tlshc/tlsh.h>
#include "tlsh_impl.h"
Tlsh* tlsh_new()
{
Tlsh* tlsh = malloc(sizeof(Tlsh));
if (!tlsh)
return NULL;
tlsh->impl = tlsh_impl_new();
if (!tlsh->impl)
{
free(tlsh);
return NULL;
}
return tlsh;
}
void tlsh_free(Tlsh* tlsh)
{
if (tlsh)
{
tlsh_impl_free(tlsh->impl);
free(tlsh);
}
}
int tlsh_update(Tlsh* tlsh, const unsigned char* data, unsigned int len)
{
int tlsh_option = 0;
if (tlsh->impl)
{
int res = tlsh_impl_update(tlsh->impl, data, len, tlsh_option);
if (res)
{
return 1;
}
}
return 0;
}
void tlsh_reset(Tlsh* tlsh)
{
if (tlsh->impl)
tlsh_impl_reset(tlsh->impl);
}
int tlsh_final(
Tlsh* tlsh,
const unsigned char* data,
unsigned int len,
int tlsh_option)
{
if (tlsh->impl)
{
if ((data != NULL) && (len > 0))
{
int res = tlsh_impl_update(tlsh->impl, data, len, tlsh_option);
if (res)
{
return 1;
}
}
tlsh_impl_final(tlsh->impl, tlsh_option);
}
return 0;
}
const char* tlsh_get_hash(Tlsh* tlsh, bool showvers)
{
if (tlsh->impl)
return tlsh_impl_hash(tlsh->impl, showvers);
else
return "";
}