Abstracts away time()/stdlib.h into platform
Substitutes time() into a configurable platform interface to allow it to be
easily substituted.
diff --git a/library/ssl_srv.c b/library/ssl_srv.c
index 6bd0b59..9fc21a5 100644
--- a/library/ssl_srv.c
+++ b/library/ssl_srv.c
@@ -27,6 +27,16 @@
#if defined(MBEDTLS_SSL_SRV_C)
+#if defined(MBEDTLS_PLATFORM_C)
+#include "mbedtls/platform.h"
+#else
+#include <stdlib.h>
+#define mbedtls_calloc calloc
+#define mbedtls_free free
+#define mbedtls_time time
+#define mbedtls_time_t time_t
+#endif
+
#include "mbedtls/debug.h"
#include "mbedtls/ssl.h"
#include "mbedtls/ssl_internal.h"
@@ -37,14 +47,6 @@
#include "mbedtls/ecp.h"
#endif
-#if defined(MBEDTLS_PLATFORM_C)
-#include "mbedtls/platform.h"
-#else
-#include <stdlib.h>
-#define mbedtls_calloc calloc
-#define mbedtls_free free
-#endif
-
#if defined(MBEDTLS_HAVE_TIME)
#include <time.h>
#endif
@@ -2210,7 +2212,7 @@
static int ssl_write_server_hello( mbedtls_ssl_context *ssl )
{
#if defined(MBEDTLS_HAVE_TIME)
- time_t t;
+ mbedtls_time_t t;
#endif
int ret;
size_t olen, ext_len = 0, n;
@@ -2253,7 +2255,7 @@
buf[4], buf[5] ) );
#if defined(MBEDTLS_HAVE_TIME)
- t = time( NULL );
+ t = mbedtls_time( NULL );
*p++ = (unsigned char)( t >> 24 );
*p++ = (unsigned char)( t >> 16 );
*p++ = (unsigned char)( t >> 8 );
@@ -2302,7 +2304,7 @@
ssl->state++;
#if defined(MBEDTLS_HAVE_TIME)
- ssl->session_negotiate->start = time( NULL );
+ ssl->session_negotiate->start = mbedtls_time( NULL );
#endif
#if defined(MBEDTLS_SSL_SESSION_TICKETS)