Skip to content
This repository has been archived by the owner on Dec 27, 2019. It is now read-only.

Commit

Permalink
noise: whiten the nanoseconds portion of the timestamp
Browse files Browse the repository at this point in the history
This mitigates unrelated sidechannel attacks that think they can turn
WireGuard into a useful time oracle.
  • Loading branch information
zx2c4 committed Feb 3, 2019
1 parent 936973e commit c62836e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/noise.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,15 @@ static void tai64n_now(u8 output[NOISE_TIMESTAMP_LEN])
struct timespec64 now;

ktime_get_real_ts64(&now);

/* In order to prevent some sort of infoleak from precise timers, we
* round down the nanoseconds part to the closest rounded-down power of
* two to the maximum initiations per second allowed anyway by the
* implementation.
*/
now.tv_nsec = ALIGN_DOWN(now.tv_nsec,
rounddown_pow_of_two(NSEC_PER_SEC / INITIATIONS_PER_SECOND));

/* https://cr.yp.to/libtai/tai64.html */
*(__be64 *)output = cpu_to_be64(0x400000000000000aULL + now.tv_sec);
*(__be32 *)(output + sizeof(__be64)) = cpu_to_be32(now.tv_nsec);
Expand Down

0 comments on commit c62836e

Please sign in to comment.