aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/noise.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-11-22 16:49:56 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2017-11-22 18:32:48 +0100
commit314c17259e09d18af9fcafa9d7e8b59c5cf1e1ca (patch)
tree92c96f7aca12855ba83431de6d766568664f1e97 /src/noise.c
parentpoly1305: import MIPS64 primitive from OpenSSL (diff)
downloadwireguard-monolithic-historical-314c17259e09d18af9fcafa9d7e8b59c5cf1e1ca.tar.xz
wireguard-monolithic-historical-314c17259e09d18af9fcafa9d7e8b59c5cf1e1ca.zip
global: switch from timeval to timespec
This gets us nanoseconds instead of microseconds, which is better, and we can do this pretty much without freaking out existing userspace, which doesn't actually make use of the nano/micro seconds field: zx2c4@thinkpad ~ $ cat a.c void main() { puts(sizeof(struct timeval) == sizeof(struct timespec) ? "success" : "failure"); } zx2c4@thinkpad ~ $ gcc a.c -m64 && ./a.out success zx2c4@thinkpad ~ $ gcc a.c -m32 && ./a.out success This doesn't solve y2038 problem, but timespec64 isn't yet a thing in userspace.
Diffstat (limited to 'src/noise.c')
-rw-r--r--src/noise.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/noise.c b/src/noise.c
index 6ce9b78..9d99bfa 100644
--- a/src/noise.c
+++ b/src/noise.c
@@ -349,12 +349,12 @@ static void message_ephemeral(u8 ephemeral_dst[NOISE_PUBLIC_KEY_LEN], const u8 e
static void tai64n_now(u8 output[NOISE_TIMESTAMP_LEN])
{
- struct timeval now;
+ struct timespec64 now;
- do_gettimeofday(&now);
+ getnstimeofday64(&now);
/* https://cr.yp.to/libtai/tai64.html */
*(__be64 *)output = cpu_to_be64(4611686018427387914ULL + now.tv_sec);
- *(__be32 *)(output + sizeof(__be64)) = cpu_to_be32(1000 * now.tv_usec + 500);
+ *(__be32 *)(output + sizeof(__be64)) = cpu_to_be32(now.tv_nsec);
}
bool noise_handshake_create_initiation(struct message_handshake_initiation *dst, struct noise_handshake *handshake)