diff --git a/include/mbedtls/mbedtls_config.h b/include/mbedtls/mbedtls_config.h index e8a270586..5e74980b1 100644 --- a/include/mbedtls/mbedtls_config.h +++ b/include/mbedtls/mbedtls_config.h @@ -129,7 +129,12 @@ * MBEDTLS_PLATFORM_TIME_MACRO, MBEDTLS_PLATFORM_TIME_TYPE_MACRO and * MBEDTLS_PLATFORM_STD_TIME. * - * Comment if your system does not support time functions + * Comment if your system does not support time functions. + * + * \note If MBEDTLS_TIMING_C is set - to enable the semi-portable timing + * interface - timing.c will include time.h on suitable platforms + * regardless of the setting of MBEDTLS_HAVE_TIME, unless + * MBEDTLS_TIMING_ALT is used. See timing.c for more information. */ #define MBEDTLS_HAVE_TIME @@ -3013,6 +3018,10 @@ * your own implementation of the whole module by setting * \c MBEDTLS_TIMING_ALT in the current file. * + * \note The timing module will include time.h on suitable platforms + * regardless of the setting of MBEDTLS_HAVE_TIME, unless + * MBEDTLS_TIMING_ALT is used. See timing.c for more information. + * * \note See also our Knowledge Base article about porting to a new * environment: * https://tls.mbed.org/kb/how-to/how-do-i-port-mbed-tls-to-a-new-environment-OS diff --git a/library/timing.c b/library/timing.c index 9a35eedb1..859c1b83f 100644 --- a/library/timing.c +++ b/library/timing.c @@ -46,14 +46,14 @@ struct _hr_time #include #include #include -#if defined(MBEDTLS_HAVE_TIME) +/* time.h should be included independently of MBEDTLS_HAVE_TIME. If the + * platform matches the ifdefs above, it will be used. */ #include #include struct _hr_time { struct timeval start; }; -#endif #endif /* _WIN32 && !EFIX64 && !EFI32 */ /** @@ -75,7 +75,6 @@ struct _hr_time * get_timer(0) }` the value time1+time2 is only approximately * the delay since the first reset. */ -#if defined(MBEDTLS_HAVE_TIME) #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int reset ) @@ -167,6 +166,5 @@ uint32_t mbedtls_timing_get_final_delay( { return( data->fin_ms ); } -#endif /* MBEDTLS_HAVE_TIME */ #endif /* !MBEDTLS_TIMING_ALT */ #endif /* MBEDTLS_TIMING_C */ diff --git a/tests/suites/test_suite_timing.data b/tests/suites/test_suite_timing.data index a45ed0e99..de89239e7 100644 --- a/tests/suites/test_suite_timing.data +++ b/tests/suites/test_suite_timing.data @@ -1,11 +1,8 @@ Timing: get timer -depends_on:MBEDTLS_HAVE_TIME timing_get_timer: Timing: delay 0ms -depends_on:MBEDTLS_HAVE_TIME timing_delay:0: Timing: delay 100ms -depends_on:MBEDTLS_HAVE_TIME timing_delay:100: