mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-01 10:06:53 +03:00
@ -233,21 +233,20 @@ volatile int mbedtls_timing_alarmed = 0;
|
|||||||
|
|
||||||
unsigned long mbedtls_timing_get_timer(struct mbedtls_timing_hr_time *val, int reset)
|
unsigned long mbedtls_timing_get_timer(struct mbedtls_timing_hr_time *val, int reset)
|
||||||
{
|
{
|
||||||
/* Copy val to an 8-byte-aligned address, so that we can safely cast it */
|
/* We can't safely cast val because it may not be aligned, so use memcpy */
|
||||||
uint64_t val_aligned[(sizeof(struct mbedtls_timing_hr_time) + sizeof(uint64_t) - 1) / sizeof(uint64_t)];
|
struct _hr_time t;
|
||||||
memcpy(val_aligned, val, sizeof(struct mbedtls_timing_hr_time));
|
memcpy(&t, val, sizeof(struct _hr_time));
|
||||||
struct _hr_time *t = (struct _hr_time *)val_aligned;
|
|
||||||
|
|
||||||
if (reset) {
|
if (reset) {
|
||||||
QueryPerformanceCounter(&t->start);
|
QueryPerformanceCounter(&t.start);
|
||||||
memcpy(val, val_aligned, sizeof(struct mbedtls_timing_hr_time));
|
memcpy(val, &t, sizeof(struct _hr_time));
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
unsigned long delta;
|
unsigned long delta;
|
||||||
LARGE_INTEGER now, hfreq;
|
LARGE_INTEGER now, hfreq;
|
||||||
QueryPerformanceCounter(&now);
|
QueryPerformanceCounter(&now);
|
||||||
QueryPerformanceFrequency(&hfreq);
|
QueryPerformanceFrequency(&hfreq);
|
||||||
delta = (unsigned long) ((now.QuadPart - t->start.QuadPart) * 1000ul
|
delta = (unsigned long) ((now.QuadPart - t.start.QuadPart) * 1000ul
|
||||||
/ hfreq.QuadPart);
|
/ hfreq.QuadPart);
|
||||||
return delta;
|
return delta;
|
||||||
}
|
}
|
||||||
@ -283,21 +282,20 @@ void mbedtls_set_alarm(int seconds)
|
|||||||
|
|
||||||
unsigned long mbedtls_timing_get_timer(struct mbedtls_timing_hr_time *val, int reset)
|
unsigned long mbedtls_timing_get_timer(struct mbedtls_timing_hr_time *val, int reset)
|
||||||
{
|
{
|
||||||
/* Copy val to an 8-byte-aligned address, so that we can safely cast it */
|
/* We can't safely cast val because it may not be aligned, so use memcpy */
|
||||||
uint64_t val_aligned[(sizeof(struct mbedtls_timing_hr_time) + sizeof(uint64_t) - 1) / sizeof(uint64_t)];
|
struct _hr_time t;
|
||||||
memcpy(val_aligned, val, sizeof(struct mbedtls_timing_hr_time));
|
memcpy(&t, val, sizeof(struct _hr_time));
|
||||||
struct _hr_time *t = (struct _hr_time *)val_aligned;
|
|
||||||
|
|
||||||
if (reset) {
|
if (reset) {
|
||||||
gettimeofday(&t->start, NULL);
|
gettimeofday(&t.start, NULL);
|
||||||
memcpy(val, val_aligned, sizeof(struct mbedtls_timing_hr_time));
|
memcpy(val, &t, sizeof(struct _hr_time));
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
unsigned long delta;
|
unsigned long delta;
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
gettimeofday(&now, NULL);
|
gettimeofday(&now, NULL);
|
||||||
delta = (now.tv_sec - t->start.tv_sec) * 1000ul
|
delta = (now.tv_sec - t.start.tv_sec) * 1000ul
|
||||||
+ (now.tv_usec - t->start.tv_usec) / 1000;
|
+ (now.tv_usec - t.start.tv_usec) / 1000;
|
||||||
return delta;
|
return delta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user