Using custom time

This commit is contained in:
Philippe Antoine 2019-06-04 14:03:06 +02:00
parent dbc0db9449
commit 08633825c0
7 changed files with 34 additions and 5 deletions

View File

@ -25,14 +25,14 @@ target_link_libraries(fuzz_privkey ${libs})
add_executable(fuzz_pubkey fuzz_pubkey.c onefile.c)
target_link_libraries(fuzz_pubkey ${libs})
add_executable(fuzz_client fuzz_client.c onefile.c)
add_executable(fuzz_client fuzz_client.c common.c onefile.c)
target_link_libraries(fuzz_client ${libs})
add_executable(fuzz_server fuzz_server.c onefile.c)
add_executable(fuzz_server fuzz_server.c common.c onefile.c)
target_link_libraries(fuzz_server ${libs})
add_executable(fuzz_dtlsclient fuzz_dtlsclient.c onefile.c)
add_executable(fuzz_dtlsclient fuzz_dtlsclient.c common.c onefile.c)
target_link_libraries(fuzz_dtlsclient ${libs})
add_executable(fuzz_dtlsserver fuzz_dtlsserver.c onefile.c)
add_executable(fuzz_dtlsserver fuzz_dtlsserver.c common.c onefile.c)
target_link_libraries(fuzz_dtlsserver ${libs})

14
tests/fuzz/common.c Normal file
View File

@ -0,0 +1,14 @@
#include "common.h"
mbedtls_time_t dummy_constant_time( mbedtls_time_t* time ) {
(void) time;
return 0x5af2a056;
}
void dummy_init() {
#if defined(MBEDTLS_PLATFORM_TIME_ALT)
mbedtls_platform_set_time( dummy_constant_time );
#else
fprintf(stderr, "Warning: fuzzing without constant time\n");
#endif
}

4
tests/fuzz/common.h Normal file
View File

@ -0,0 +1,4 @@
#include "mbedtls/platform_time.h"
mbedtls_time_t dummy_constant_time( mbedtls_time_t* time );
void dummy_init();

View File

@ -2,6 +2,7 @@
#include "mbedtls/entropy.h"
#include "mbedtls/ctr_drbg.h"
#include "mbedtls/certs.h"
#include "common.h"
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
@ -90,7 +91,6 @@ static int dummy_entropy( void *data, unsigned char *output, size_t len )
return( 0 );
}
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
int ret;
size_t len;
@ -114,6 +114,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
alpn_list[1] = "fuzzalpn";
alpn_list[2] = NULL;
dummy_init();
initialized = 1;
}

View File

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include "common.h"
#include "mbedtls/ssl.h"
#if defined(MBEDTLS_SSL_PROTO_DTLS)
#include "mbedtls/entropy.h"
@ -113,6 +114,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
mbedtls_test_cas_pem_len ) != 0)
return 1;
#endif
dummy_init();
initialized = 1;
}

View File

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include "common.h"
#include "mbedtls/ssl.h"
#if defined(MBEDTLS_SSL_PROTO_DTLS)
#include "mbedtls/entropy.h"
@ -120,6 +121,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
mbedtls_test_srv_key_len, NULL, 0 ) != 0)
return 1;
#endif
dummy_init();
initialized = 1;
}
mbedtls_ssl_init( &ssl );

View File

@ -3,6 +3,7 @@
#include "mbedtls/ctr_drbg.h"
#include "mbedtls/certs.h"
#include "mbedtls/ssl_ticket.h"
#include "common.h"
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
@ -131,6 +132,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
alpn_list[1] = "fuzzalpn";
alpn_list[2] = NULL;
dummy_init();
initialized = 1;
}
mbedtls_ssl_init( &ssl );