#include "common.h"
#if defined(MBEDTLS_TIMING_C)
#include "mbedtls/timing.h"
#if !defined(MBEDTLS_TIMING_ALT)
#if !defined(unix) && !defined(__unix__) && !defined(__unix) && \
!defined(__APPLE__) && !defined(_WIN32) && !defined(__QNXNTO__) && \
!defined(__HAIKU__) && !defined(__midipix__)
#error "This module only works on Unix and Windows, see MBEDTLS_TIMING_C in mbedtls_config.h"
#endif
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
#include <windows.h>
#include <process.h>
struct _hr_time {
LARGE_INTEGER start;
};
#else
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <time.h>
#include <sys/time.h>
struct _hr_time { … };
#endif
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
unsigned long mbedtls_timing_get_timer(struct mbedtls_timing_hr_time *val, int reset)
{
struct _hr_time *t = (struct _hr_time *) val;
if (reset) {
QueryPerformanceCounter(&t->start);
return 0;
} else {
unsigned long delta;
LARGE_INTEGER now, hfreq;
QueryPerformanceCounter(&now);
QueryPerformanceFrequency(&hfreq);
delta = (unsigned long) ((now.QuadPart - t->start.QuadPart) * 1000ul
/ hfreq.QuadPart);
return delta;
}
}
#else
unsigned long mbedtls_timing_get_timer(struct mbedtls_timing_hr_time *val, int reset)
{ … }
#endif
void mbedtls_timing_set_delay(void *data, uint32_t int_ms, uint32_t fin_ms)
{ … }
int mbedtls_timing_get_delay(void *data)
{ … }
uint32_t mbedtls_timing_get_final_delay(
const mbedtls_timing_delay_context *data)
{ … }
#endif
#endif