diff --git a/programs/fuzz/common.c b/programs/fuzz/common.c index 5e6c84c26..ac39ee22f 100644 --- a/programs/fuzz/common.c +++ b/programs/fuzz/common.c @@ -58,8 +58,13 @@ int dummy_random( void *p_rng, unsigned char *output, size_t output_len ) int ret; size_t i; +#if defined(MBEDTLS_CTR_DRBG_C) //use mbedtls_ctr_drbg_random to find bugs in it ret = mbedtls_ctr_drbg_random(p_rng, output, output_len); +#else + (void) p_rng; + ret = 0; +#endif for (i=0; i -#ifdef MBEDTLS_SSL_CLI_C +#if defined(MBEDTLS_SSL_CLI_C) && \ + defined(MBEDTLS_ENTROPY_C) && \ + defined(MBEDTLS_CTR_DRBG_C) static int initialized = 0; #if defined(MBEDTLS_X509_CRT_PARSE_C) && defined(MBEDTLS_PEM_PARSE_C) static mbedtls_x509_crt cacert; @@ -25,11 +27,13 @@ const char psk_id[] = "Client_identity"; #endif const char *pers = "fuzz_client"; -#endif //MBEDTLS_SSL_CLI_C +#endif /* MBEDTLS_SSL_CLI_C && MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { -#ifdef MBEDTLS_SSL_CLI_C +#if defined(MBEDTLS_SSL_CLI_C) && \ + defined(MBEDTLS_ENTROPY_C) && \ + defined(MBEDTLS_CTR_DRBG_C) int ret; size_t len; mbedtls_ssl_context ssl; @@ -167,7 +171,7 @@ exit: #else (void) Data; (void) Size; -#endif //MBEDTLS_SSL_CLI_C +#endif /* MBEDTLS_SSL_CLI_C && MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */ return 0; } diff --git a/programs/fuzz/fuzz_dtlsclient.c b/programs/fuzz/fuzz_dtlsclient.c index 8197a6484..ff258bcc7 100644 --- a/programs/fuzz/fuzz_dtlsclient.c +++ b/programs/fuzz/fuzz_dtlsclient.c @@ -10,20 +10,27 @@ #include "mbedtls/timing.h" -#ifdef MBEDTLS_SSL_CLI_C +#if defined(MBEDTLS_SSL_CLI_C) && \ + defined(MBEDTLS_ENTROPY_C) && \ + defined(MBEDTLS_CTR_DRBG_C) && \ + defined(MBEDTLS_TIMING_C) static int initialized = 0; #if defined(MBEDTLS_X509_CRT_PARSE_C) && defined(MBEDTLS_PEM_PARSE_C) static mbedtls_x509_crt cacert; #endif const char *pers = "fuzz_dtlsclient"; -#endif // MBEDTLS_SSL_CLI_C +#endif #endif // MBEDTLS_SSL_PROTO_DTLS int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { -#if defined(MBEDTLS_SSL_PROTO_DTLS) && defined(MBEDTLS_SSL_CLI_C) +#if defined(MBEDTLS_SSL_PROTO_DTLS) && \ + defined(MBEDTLS_SSL_CLI_C) && \ + defined(MBEDTLS_ENTROPY_C) && \ + defined(MBEDTLS_CTR_DRBG_C) && \ + defined(MBEDTLS_TIMING_C) int ret; size_t len; mbedtls_ssl_context ssl; diff --git a/programs/fuzz/fuzz_dtlsserver.c b/programs/fuzz/fuzz_dtlsserver.c index 9e9fe8ebd..4cde1fe6c 100644 --- a/programs/fuzz/fuzz_dtlsserver.c +++ b/programs/fuzz/fuzz_dtlsserver.c @@ -11,7 +11,10 @@ #include "mbedtls/ssl_cookie.h" -#ifdef MBEDTLS_SSL_SRV_C +#if defined(MBEDTLS_SSL_SRV_C) && \ + defined(MBEDTLS_ENTROPY_C) && \ + defined(MBEDTLS_CTR_DRBG_C) && \ + defined(MBEDTLS_TIMING_C) const char *pers = "fuzz_dtlsserver"; const unsigned char client_ip[4] = {0x7F, 0, 0, 1}; static int initialized = 0; @@ -19,11 +22,15 @@ static int initialized = 0; static mbedtls_x509_crt srvcert; static mbedtls_pk_context pkey; #endif -#endif // MBEDTLS_SSL_SRV_C +#endif #endif // MBEDTLS_SSL_PROTO_DTLS int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { -#if defined(MBEDTLS_SSL_PROTO_DTLS) && defined(MBEDTLS_SSL_SRV_C) +#if defined(MBEDTLS_SSL_PROTO_DTLS) && \ + defined(MBEDTLS_SSL_SRV_C) && \ + defined(MBEDTLS_ENTROPY_C) && \ + defined(MBEDTLS_CTR_DRBG_C) && \ + defined(MBEDTLS_TIMING_C) int ret; size_t len; mbedtls_ssl_context ssl; diff --git a/programs/fuzz/fuzz_server.c b/programs/fuzz/fuzz_server.c index 006239c69..014f386ef 100644 --- a/programs/fuzz/fuzz_server.c +++ b/programs/fuzz/fuzz_server.c @@ -9,7 +9,9 @@ #include -#ifdef MBEDTLS_SSL_SRV_C +#if defined(MBEDTLS_SSL_SRV_C) && \ + defined(MBEDTLS_ENTROPY_C) && \ + defined(MBEDTLS_CTR_DRBG_C) const char *pers = "fuzz_server"; static int initialized = 0; #if defined(MBEDTLS_X509_CRT_PARSE_C) && defined(MBEDTLS_PEM_PARSE_C) @@ -25,11 +27,13 @@ const unsigned char psk[] = { }; const char psk_id[] = "Client_identity"; #endif -#endif // MBEDTLS_SSL_SRV_C +#endif // MBEDTLS_SSL_SRV_C && MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { -#ifdef MBEDTLS_SSL_SRV_C +#if defined(MBEDTLS_SSL_SRV_C) && \ + defined(MBEDTLS_ENTROPY_C) && \ + defined(MBEDTLS_CTR_DRBG_C) int ret; size_t len; mbedtls_ssl_context ssl; @@ -179,7 +183,7 @@ exit: #else (void) Data; (void) Size; -#endif //MBEDTLS_SSL_SRV_C +#endif /* MBEDTLS_SSL_SRV_C && MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */ return 0; }