1 /**
2  * \file platform_time.h
3  *
4  * \brief Mbed TLS Platform time abstraction
5  */
6 /*
7  *  Copyright The Mbed TLS Contributors
8  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9  */
10 #ifndef MBEDTLS_PLATFORM_TIME_H
11 #define MBEDTLS_PLATFORM_TIME_H
12 
13 #include "mbedtls/build_info.h"
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 /*
20  * The time_t datatype
21  */
22 #if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO)
23 typedef MBEDTLS_PLATFORM_TIME_TYPE_MACRO mbedtls_time_t;
24 #else
25 /* For time_t */
26 #include <time.h>
27 typedef time_t mbedtls_time_t;
28 #endif /* MBEDTLS_PLATFORM_TIME_TYPE_MACRO */
29 
30 #if defined(MBEDTLS_PLATFORM_MS_TIME_TYPE_MACRO)
31 typedef MBEDTLS_PLATFORM_MS_TIME_TYPE_MACRO mbedtls_ms_time_t;
32 #else
33 #include <stdint.h>
34 #include <inttypes.h>
35 typedef int64_t mbedtls_ms_time_t;
36 #endif /* MBEDTLS_PLATFORM_MS_TIME_TYPE_MACRO */
37 
38 /**
39  * \brief   Get time in milliseconds.
40  *
41  * \return Monotonically-increasing current time in milliseconds.
42  *
43  * \note Define MBEDTLS_PLATFORM_MS_TIME_ALT to be able to provide an
44  *       alternative implementation
45  *
46  * \warning This function returns a monotonically-increasing time value from a
47  *          start time that will differ from platform to platform, and possibly
48  *          from run to run of the process.
49  *
50  */
51 mbedtls_ms_time_t mbedtls_ms_time(void);
52 
53 /*
54  * The function pointers for time
55  */
56 #if defined(MBEDTLS_PLATFORM_TIME_ALT)
57 extern mbedtls_time_t (*mbedtls_time)(mbedtls_time_t *time);
58 
59 /**
60  * \brief   Set your own time function pointer
61  *
62  * \param   time_func   the time function implementation
63  *
64  * \return              0
65  */
66 int mbedtls_platform_set_time(mbedtls_time_t (*time_func)(mbedtls_time_t *time));
67 #else
68 #if defined(MBEDTLS_PLATFORM_TIME_MACRO)
69 #define mbedtls_time    MBEDTLS_PLATFORM_TIME_MACRO
70 #else
71 #define mbedtls_time   time
72 #endif /* MBEDTLS_PLATFORM_TIME_MACRO */
73 #endif /* MBEDTLS_PLATFORM_TIME_ALT */
74 
75 #ifdef __cplusplus
76 }
77 #endif
78 
79 #endif /* platform_time.h */
80