mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2024-11-22 07:13:09 +01:00
tai64n: whiten nano seconds
Avoid being too precise of a time oracle.
This commit is contained in:
parent
2b7562abbb
commit
a5ca02d79a
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user