Skip to content

Commit

Permalink
Remove the dependency on MBEDTLS_HAVE_TIME from MBEDTLS_TIMING_C
Browse files Browse the repository at this point in the history
The timing module might include time.h on its own when on 
a suitable platform, even if MBEDTLS_HAVE_TIME is disabled. 


Co-authored-by: Tom Cosgrove <[email protected]>
Signed-off-by: Andrzej Kurek <[email protected]>
  • Loading branch information
Andrzej Kurek and tom-cosgrove-arm committed Apr 7, 2022
1 parent 714b660 commit 06cb315
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
10 changes: 9 additions & 1 deletion include/mbedtls/mbedtls_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@
* 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 regardless of the setting
* of MBEDTLS_HAVE_TIME, unless MBEDTLS_TIMING_ALT is used.
*/
#define MBEDTLS_HAVE_TIME

Expand Down Expand Up @@ -3013,6 +3017,10 @@
* your own implementation of the whole module by setting
* \c MBEDTLS_TIMING_ALT in the current file.
*
* \note If MBEDTLS_TIMING_C is set - to enable the semi-portable timing
* interface - timing.c will include time.h regardless of the setting
* of MBEDTLS_HAVE_TIME, unless MBEDTLS_TIMING_ALT is used.
*
* \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
Expand Down
6 changes: 2 additions & 4 deletions library/timing.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ struct _hr_time
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#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 <time.h>
#include <sys/time.h>
struct _hr_time
{
struct timeval start;
};
#endif
#endif /* _WIN32 && !EFIX64 && !EFI32 */

/**
Expand All @@ -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 )
Expand Down Expand Up @@ -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 */
3 changes: 0 additions & 3 deletions tests/suites/test_suite_timing.data
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit 06cb315

Please sign in to comment.