/src/yara/libyara/tlshc/tlsh.c
Line | Count | Source |
1 | | #include <stdlib.h> |
2 | | #include <tlshc/tlsh.h> |
3 | | #include "tlsh_impl.h" |
4 | | |
5 | | Tlsh* tlsh_new() |
6 | 546 | { |
7 | 546 | Tlsh* tlsh = malloc(sizeof(Tlsh)); |
8 | 546 | if (!tlsh) |
9 | 0 | return NULL; |
10 | | |
11 | 546 | tlsh->impl = tlsh_impl_new(); |
12 | 546 | if (!tlsh->impl) |
13 | 0 | { |
14 | 0 | free(tlsh); |
15 | 0 | return NULL; |
16 | 0 | } |
17 | | |
18 | 546 | return tlsh; |
19 | 546 | } |
20 | | |
21 | | void tlsh_free(Tlsh* tlsh) |
22 | 546 | { |
23 | 546 | if (tlsh) |
24 | 546 | { |
25 | 546 | tlsh_impl_free(tlsh->impl); |
26 | 546 | free(tlsh); |
27 | 546 | } |
28 | 546 | } |
29 | | |
30 | | int tlsh_update(Tlsh* tlsh, const unsigned char* data, unsigned int len) |
31 | 546 | { |
32 | 546 | int tlsh_option = 0; |
33 | 546 | if (tlsh->impl) |
34 | 546 | { |
35 | 546 | int res = tlsh_impl_update(tlsh->impl, data, len, tlsh_option); |
36 | 546 | if (res) |
37 | 0 | { |
38 | 0 | return 1; |
39 | 0 | } |
40 | 546 | } |
41 | | |
42 | 546 | return 0; |
43 | 546 | } |
44 | | |
45 | | void tlsh_reset(Tlsh* tlsh) |
46 | 546 | { |
47 | 546 | if (tlsh->impl) |
48 | 546 | tlsh_impl_reset(tlsh->impl); |
49 | 546 | } |
50 | | |
51 | | int tlsh_final( |
52 | | Tlsh* tlsh, |
53 | | const unsigned char* data, |
54 | | unsigned int len, |
55 | | int tlsh_option) |
56 | 546 | { |
57 | 546 | if (tlsh->impl) |
58 | 546 | { |
59 | 546 | if ((data != NULL) && (len > 0)) |
60 | 546 | { |
61 | 546 | int res = tlsh_impl_update(tlsh->impl, data, len, tlsh_option); |
62 | 546 | if (res) |
63 | 0 | { |
64 | 0 | return 1; |
65 | 0 | } |
66 | 546 | } |
67 | | |
68 | 546 | tlsh_impl_final(tlsh->impl, tlsh_option); |
69 | 546 | } |
70 | | |
71 | 546 | return 0; |
72 | 546 | } |
73 | | |
74 | | const char* tlsh_get_hash(Tlsh* tlsh, bool showvers) |
75 | 1.09k | { |
76 | 1.09k | if (tlsh->impl) |
77 | 1.09k | return tlsh_impl_hash(tlsh->impl, showvers); |
78 | 0 | else |
79 | 0 | return ""; |
80 | 1.09k | } |