Replacing 'time' function(s)

I’m porting mbed_tls to my platform, and would appreciate advice re. time/date functions.
I have an RTC driver which has a function that returns Epoch Time. Can you advise please on which config options need to be (re)defined to hook my function in and override defaults?

Hi @ColH
Thank you for your query!

The following articles may assist you in your porting effort:

Specifically for you the time functions, you can look at platform_time.h for the API you need to implement.

You will need mbedtls_time_t defined in your system. It is either defined as MBEDTLS_PLATFORM_TIME_TYPE_MACRO , which you will need to set, if it is defined, or it is defined as time_t.

As for the functions themselves, you can choose either to have an alternative implementation of the time function, configured as MBEDTLS_PLATFORM_TIME_ALT , and its prototype is extern mbedtls_time_t (*mbedtls_time)( mbedtls_time_t* time );
In your application, you will need to set this callback by calling mbedtls_platform_set_time().
Alternatively, you can configure MBEDTLS_PLATFORM_TIME_MACRO to be as your time function, if your time function has same prototype is the standard time() function,

If your question is about gmtime_r, then you should probably have MBEDTLS_PLATFORM_GMTIME_R_ALT configured, and implement mbedtls_platform_gmtime_r() , as seen in platfrom_util.c

Mbed TLS Team member

Thanks - got it!