From e326ef90301cf570a5e6691c46d4a1d37adc1e07 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Fri, 29 May 2015 17:35:54 +0200 Subject: [PATCH] Do not use timeval. The structure is not defined on Windows RT. --- .../salsa20/randombytes_salsa20_random.c | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c b/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c index 43e2d0f2..1ab34b70 100644 --- a/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +++ b/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c @@ -65,27 +65,24 @@ static Salsa20Random stream = { static uint64_t sodium_hrtime(void) { - struct timeval tv; - uint64_t ts = (uint64_t) 0U; - int ret; + uint64_t ts; #ifdef _WIN32 - struct _timeb tb; - + { + struct _timeb tb; # pragma warning(push) # pragma warning(disable: 4996) - _ftime(&tb); + _ftime(&tb); # pragma warning(pop) - tv.tv_sec = (long) tb.time; - tv.tv_usec = ((int) tb.millitm) * 1000; - ret = 0; -#else - ret = gettimeofday(&tv, NULL); -#endif - assert(ret == 0); - if (ret == 0) { - ts = (uint64_t) tv.tv_sec * 1000000U + (uint64_t) tv.tv_usec; + ts = ((uint64_t) tb.time) * 1000000U + ((uint64_t) tb.millitm) * 1000U; } +#else + { + struct timeval tv; + assert(gettimeofday(&tv, NULL) == 0); + ts = ((uint64_t) tv.tv_sec) * 1000000U + (uint64_t) tv.tv_usec; + } +#endif return ts; }