/src/ndpi/fuzz/fuzz_alg_quick_encryption.cpp
Line | Count | Source |
1 | | #include "ndpi_api.h" |
2 | | #include "fuzz_common_code.h" |
3 | | |
4 | | #include <stdlib.h> |
5 | | #include <stdint.h> |
6 | | #include "fuzzer/FuzzedDataProvider.h" |
7 | | |
8 | | |
9 | 187 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
10 | 187 | FuzzedDataProvider fuzzed_data(data, size); |
11 | 187 | char *enc_buffer, *dec_buffer; |
12 | 187 | u_int16_t encrypted_msg_len, decrypted_msg_len; |
13 | | |
14 | 187 | if(fuzzed_data.remaining_bytes() <= 64) /* Some data */ |
15 | 11 | return -1; |
16 | | |
17 | | /* To allow memory allocation failures */ |
18 | 176 | fuzz_set_alloc_callbacks_and_seed(size); |
19 | | |
20 | 176 | std::vector<unsigned char>key = fuzzed_data.ConsumeBytes<u_int8_t>(64); |
21 | 176 | std::vector<char>cleartext_msg = fuzzed_data.ConsumeRemainingBytes<char>(); |
22 | | |
23 | 176 | enc_buffer = ndpi_quick_encrypt(cleartext_msg.data(), cleartext_msg.size(), &encrypted_msg_len, key.data()); |
24 | 176 | if(enc_buffer) { |
25 | 169 | dec_buffer = ndpi_quick_decrypt(enc_buffer, encrypted_msg_len, &decrypted_msg_len, key.data()); |
26 | 169 | ndpi_free(enc_buffer); |
27 | 169 | ndpi_free(dec_buffer); |
28 | 169 | } |
29 | 176 | return 0; |
30 | 187 | } |