• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #if !defined(LIBRESSL_VERSION_NUMBER) && !defined(BORINGSSL_API_VERSION) && \
23     defined(OPENSSL_VERSION_NUMBER)
24 #define HF_SSL_IS_OPENSSL
25 #endif
26 
27 #define FUZZTIME 1485898104
__wrap_time(time_t * t)28 time_t __wrap_time(time_t* t) {
29     if (t != NULL) *t = FUZZTIME;
30     return FUZZTIME;
31 }
32 
33 #if defined(HF_SSL_IS_BORINGSSL)
hf_rnd(unsigned char * buf,size_t num)34 static int hf_rnd(unsigned char* buf, size_t num)
35 #else  /* defined(HF_SSL_IS_BORINGSSL) */
36 static int hf_rnd(unsigned char* buf, int num)
37 #endif /* defined(HF_SSL_IS_BORINGSSL) */
38 {
39     for (size_t v = 0; v < num; v++) {
40         buf[v] = v + 1;
41     }
42     return 1;
43 }
44 
hf_stat(void)45 static int hf_stat(void) {
46     return 1;
47 }
48 
49 static RAND_METHOD hf_method = {
50     NULL,
51     hf_rnd,
52     NULL,
53     NULL,
54     hf_rnd,
55     hf_stat,
56 };
57 
HFResetRand(void)58 static void HFResetRand(void) {
59     RAND_set_rand_method(&hf_method);
60 }
61 
62 #if defined(HF_SSL_FROM_STDIN)
63 int LLVMFuzzerInitialize(int* argc, char*** argv) __attribute__((weak));
64 
main(int argc,char ** argv)65 int main(int argc, char** argv) {
66     if (LLVMFuzzerInitialize) {
67         LLVMFuzzerInitialize(&argc, &argv);
68     }
69     return LLVMFuzzerTestOneInput(NULL, 0U);
70 }
71 #endif /* defined(HF_SSL_FROM_STDIN) */
72 #ifdef __cplusplus
73 }  // extern "C"
74 #endif
75 
HFInit(void)76 static void HFInit(void) {
77     SSL_library_init();
78     OpenSSL_add_ssl_algorithms();
79     ERR_load_crypto_strings();
80 }
81