/src/ndpi/fuzz/fuzz_alg_crc32_md5.c
Line | Count | Source |
1 | | #include "ndpi_api.h" |
2 | | #include "ndpi_md5.h" |
3 | | |
4 | 177 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
5 | 177 | u_char hash[16]; |
6 | 177 | ndpi_MD5_CTX ctx; |
7 | 177 | struct ndpi_popcount popcount; |
8 | 177 | char *str; |
9 | 177 | u_int len; |
10 | 177 | u_char out[2048], out2[2048]; |
11 | 177 | int pseudo_bool; |
12 | 177 | char *enc; |
13 | 177 | u_char *dec; |
14 | 177 | size_t out_len; |
15 | | |
16 | | /* No memory allocations involved */ |
17 | | |
18 | | /* Used for crc32, md5, hash(es), popcount, hex2bin, hexencode algs */ |
19 | | |
20 | 177 | pseudo_bool = (size % 2 == 0); |
21 | | |
22 | 177 | ndpi_crc16_ccit(data, size); |
23 | 177 | ndpi_crc16_ccit_false(data, size); |
24 | 177 | ndpi_crc16_xmodem(data, size); |
25 | 177 | ndpi_crc16_x25(data, size); |
26 | 177 | ndpi_crc32(data, size, 0); |
27 | | |
28 | 177 | ndpi_md5(data, size, hash); |
29 | | |
30 | 177 | ndpi_MD5Init(&ctx); |
31 | 177 | ndpi_MD5Update(&ctx, data, size / 2); |
32 | 177 | ndpi_MD5Update(&ctx, data + size / 2, size - size / 2); |
33 | 177 | ndpi_MD5Final(hash, &ctx); |
34 | | |
35 | 177 | ndpi_murmur_hash((const char *)data, size); |
36 | 177 | ndpi_quick_hash(data, size); |
37 | | |
38 | 177 | if(size >= 16) |
39 | 156 | ndpi_quick_16_byte_hash(data); |
40 | | |
41 | 177 | str = ndpi_malloc(size + 1); |
42 | 177 | if(str) { |
43 | 177 | memcpy(str, data, size); |
44 | 177 | str[size] = '\0'; |
45 | | |
46 | 177 | ndpi_quick_hash64((const char *)str, strlen(str)); |
47 | 177 | ndpi_hash_string(str); |
48 | 177 | ndpi_rev_hash_string(str); |
49 | 177 | ndpi_hash_string_len(str, strlen(str)); |
50 | | |
51 | 177 | ndpi_free(str); |
52 | 177 | } |
53 | | |
54 | | |
55 | 177 | ndpi_popcount_init(pseudo_bool ? &popcount : NULL); |
56 | 177 | ndpi_popcount_count(pseudo_bool ? &popcount : NULL, data, size); |
57 | | |
58 | 177 | len = ndpi_bin2hex(out, sizeof(out), (u_char *)data, size); |
59 | 177 | ndpi_hex2bin(out2, sizeof(out2), out, len); |
60 | | |
61 | 177 | enc = ndpi_hex_encode(data, size); |
62 | 177 | dec = ndpi_hex_decode((u_char *)enc, size * 2, &out_len); |
63 | 177 | ndpi_free(enc); |
64 | 177 | ndpi_free(dec); |
65 | | |
66 | 177 | return 0; |
67 | 177 | } |