tai64n: whiten nano seconds

Avoid being too precise of a time oracle.
This commit is contained in:
Jason A. Donenfeld 2019-02-03 02:08:16 +01:00
parent 2b7562abbb
commit a5ca02d79a

View 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