diff options
author | Nicolas Hillegeer <nicolas@hillegeer.com> | 2014-07-21 15:27:56 +0200 |
---|---|---|
committer | Nicolas Hillegeer <nicolas@hillegeer.com> | 2014-07-21 19:29:29 +0200 |
commit | 8ec0aef307f64353c4d21377f6482df238ef7764 (patch) | |
tree | b6af6c13241393f204937bc3329ed6df1b81349f | |
parent | 6cbda2cbf606aafe7a014ab66175048aea9da03e (diff) | |
download | rneovim-8ec0aef307f64353c4d21377f6482df238ef7764.tar.gz rneovim-8ec0aef307f64353c4d21377f6482df238ef7764.tar.bz2 rneovim-8ec0aef307f64353c4d21377f6482df238ef7764.zip |
sha256: replace gettimeofday()
gettimeofday() is not portable. I suspect os_hrtime() is also better as a
seed than gettimeofday() or time() were.
-rw-r--r-- | src/nvim/sha256.c | 21 |
1 files changed, 3 insertions, 18 deletions
diff --git a/src/nvim/sha256.c b/src/nvim/sha256.c index 9877a82fa1..b11ee2293c 100644 --- a/src/nvim/sha256.c +++ b/src/nvim/sha256.c @@ -15,10 +15,10 @@ #include <inttypes.h> #include <string.h> +#include "nvim/os/time.h" #include "nvim/vim.h" #include "nvim/sha256.h" - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "sha256.c.generated.h" #endif @@ -350,21 +350,6 @@ int sha256_self_test(void) return failures > 0 ? FAIL : OK; } -static unsigned int get_some_time(void) -{ -#ifdef HAVE_GETTIMEOFDAY - struct timeval tv; - - // Using usec makes it less predictable. - gettimeofday(&tv, NULL); - return (unsigned int) (tv.tv_sec + tv.tv_usec); - -#else // ifdef HAVE_GETTIMEOFDAY - return (unsigned int) time(NULL); - -#endif // ifdef HAVE_GETTIMEOFDAY -} - /// Fill "header[header_len]" with random_data. /// Also "salt[salt_len]" when "salt" is not NULL. /// @@ -378,11 +363,11 @@ void sha2_seed(char_u *header, int header_len, char_u *salt, int salt_len) char_u sha256sum[32]; context_sha256_T ctx; - srand(get_some_time()); + srand((unsigned int) os_hrtime()); int i; for (i = 0; i < (int) sizeof(random_data) - 1; i++) { - random_data[i] = (char_u) ((get_some_time() ^ rand()) & 0xff); + random_data[i] = (char_u) ((os_hrtime() ^ rand()) & 0xff); } sha256_start(&ctx); sha256_update(&ctx, (char_u *) random_data, sizeof(random_data)); |