]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
tai64n: whiten nano seconds
authorJason A. Donenfeld <Jason@zx2c4.com>
Sun, 3 Feb 2019 01:08:16 +0000 (02:08 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 5 Feb 2019 11:59:42 +0000 (12:59 +0100)
Avoid being too precise of a time oracle.

tai64n/tai64n.go

index f402f058cb7c94db606f93527fd504f1d80a9522..565aaa4b6831f0ea926c397535e656f60474119d 100644 (file)
@@ -12,7 +12,8 @@ import (
 )
 
 const TimestampSize = 12
-const base = uint64(4611686018427387914)
+const base = uint64(0x400000000000000a)
+const whitenerMask = uint32(0x1000000 - 1)
 
 type Timestamp [TimestampSize]byte
 
@@ -20,7 +21,7 @@ func Now() Timestamp {
        var tai64n Timestamp
        now := time.Now()
        secs := base + uint64(now.Unix())
-       nano := uint32(now.Nanosecond())
+       nano := uint32(now.Nanosecond()) &^ whitenerMask
        binary.BigEndian.PutUint64(tai64n[:], secs)
        binary.BigEndian.PutUint32(tai64n[8:], nano)
        return tai64n