diff --git a/include/mbedtls/config.h b/include/mbedtls/config.h index 0e539be51..dce8f48e8 100644 --- a/include/mbedtls/config.h +++ b/include/mbedtls/config.h @@ -2951,6 +2951,18 @@ */ //#define MBEDTLS_MEMORY_BUFFER_ALLOC_C +/** + * \def MBEDTLS_PLATFORM_FAULT_CALLBACKS + * + * Uncomment to provide your own alternate implementation for mbedtls_platform_fault(), + * used in library/platform_util.c to signal a fault injection in either + * mbedtls_platform_memcpy or mbedtls_platform_memset. + * + * You will need to provide a header "platform_fault.h" and an implementation at + * compile time. + */ +//#define MBEDTLS_PLATFORM_FAULT_CALLBACKS + /** * \def MBEDTLS_NET_C * diff --git a/library/platform_util.c b/library/platform_util.c index 19ba7b976..ecfdb84d1 100644 --- a/library/platform_util.c +++ b/library/platform_util.c @@ -48,6 +48,12 @@ #include "mbedtls/entropy_poll.h" #endif +#if defined(MBEDTLS_PLATFORM_FAULT_CALLBACKS) +#include "platform_fault.h" +#else +static void mbedtls_platform_fault(){} +#endif + #include #include @@ -167,7 +173,7 @@ void *mbedtls_platform_memset( void *ptr, int value, size_t num ) return ptr; } } - + mbedtls_platform_fault(); return NULL; } @@ -207,6 +213,7 @@ void *mbedtls_platform_memcpy( void *dst, const void *src, size_t num ) return dst; } } + mbedtls_platform_fault(); return NULL; } diff --git a/library/version_features.c b/library/version_features.c index b0e16375d..8044dc91d 100644 --- a/library/version_features.c +++ b/library/version_features.c @@ -729,6 +729,9 @@ static const char *features[] = { #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) "MBEDTLS_MEMORY_BUFFER_ALLOC_C", #endif /* MBEDTLS_MEMORY_BUFFER_ALLOC_C */ +#if defined(MBEDTLS_PLATFORM_FAULT_CALLBACKS) + "MBEDTLS_PLATFORM_FAULT_CALLBACKS", +#endif /* MBEDTLS_PLATFORM_FAULT_CALLBACKS */ #if defined(MBEDTLS_NET_C) "MBEDTLS_NET_C", #endif /* MBEDTLS_NET_C */ diff --git a/programs/ssl/query_config.c b/programs/ssl/query_config.c index bc6499dac..e86fdb5ec 100644 --- a/programs/ssl/query_config.c +++ b/programs/ssl/query_config.c @@ -1986,6 +1986,14 @@ int query_config( const char *config ) } #endif /* MBEDTLS_MEMORY_BUFFER_ALLOC_C */ +#if defined(MBEDTLS_PLATFORM_FAULT_CALLBACKS) + if( strcmp( "MBEDTLS_PLATFORM_FAULT_CALLBACKS", config ) == 0 ) + { + MACRO_EXPANSION_TO_STR( MBEDTLS_PLATFORM_FAULT_CALLBACKS ); + return( 0 ); + } +#endif /* MBEDTLS_PLATFORM_FAULT_CALLBACKS */ + #if defined(MBEDTLS_NET_C) if( strcmp( "MBEDTLS_NET_C", config ) == 0 ) { diff --git a/scripts/config.pl b/scripts/config.pl index 0a65ef438..82d711362 100755 --- a/scripts/config.pl +++ b/scripts/config.pl @@ -146,6 +146,7 @@ MBEDTLS_CTR_DRBG_USE_128_BIT_KEY MBEDTLS_SSL_TRANSFORM_OPTIMIZE_CIPHERS MBEDTLS_VALIDATE_SSL_KEYS_INTEGRITY MBEDTLS_OPTIMIZE_TINYCRYPT_ASM +MBEDTLS_PLATFORM_FAULT_CALLBACKS _ALT\s*$ );