1 #include <openssl/err.h>
2 #include <openssl/opensslv.h>
3 #include <openssl/rand.h>
4 #include <openssl/ssl.h>
5
6 #include <libhfuzz/libhfuzz.h>
7
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11
12 #if defined(LIBRESSL_VERSION_NUMBER)
13 #define HF_SSL_IS_LIBRESSL 1
14 #endif
15 #if defined(BORINGSSL_API_VERSION)
16 #define HF_SSL_IS_BORINGSSL 1
17 #endif
18 #if !defined(LIBRESSL_VERSION_NUMBER) && !defined(BORINGSSL_API_VERSION) && \
19 OPENSSL_VERSION_NUMBER >= 0x10100000
20 #define HF_SSL_IS_OPENSSL_GE_1_1 1
21 #endif
22
23 #define FUZZTIME 1485898104
time(time_t * t)24 time_t time(time_t* t) {
25 if (t != NULL) *t = FUZZTIME;
26 return FUZZTIME;
27 }
28
29 #if defined(HF_SSL_IS_BORINGSSL)
hf_rnd(unsigned char * buf,size_t num)30 static int hf_rnd(unsigned char* buf, size_t num)
31 #else /* defined(HF_SSL_IS_OPENSSL) */
32 static int hf_rnd(unsigned char* buf, int num)
33 #endif /* defined(HF_SSL_IS_OPENSSL) */
34 {
35 for (size_t v = 0; v < num; v++) {
36 buf[v] = v + 1;
37 }
38 return 1;
39 }
40
hf_stat(void)41 static int hf_stat(void) { return 1; }
42
43 static RAND_METHOD hf_method = {
44 NULL,
45 hf_rnd,
46 NULL,
47 NULL,
48 hf_rnd,
49 hf_stat,
50 };
51
HFResetRand(void)52 static void HFResetRand(void) { RAND_set_rand_method(&hf_method); }
53
54 #if defined(HF_SSL_FROM_STDIN)
55 int LLVMFuzzerInitialize(int* argc, char*** argv) __attribute__((weak));
56
main(int argc,char ** argv)57 int main(int argc, char** argv) {
58 if (LLVMFuzzerInitialize) {
59 LLVMFuzzerInitialize(&argc, &argv);
60 }
61 return LLVMFuzzerTestOneInput(NULL, 0U);
62 }
63 #endif /* defined(HF_SSL_FROM_STDIN) */
64 #ifdef __cplusplus
65 } // extern "C"
66 #endif
67
HFInit(void)68 static void HFInit(void) {
69 SSL_library_init();
70 OpenSSL_add_ssl_algorithms();
71 ERR_load_crypto_strings();
72 }
73