From a5ca02d79a953c883694061bba5c683b220fbfe4 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 3 Feb 2019 02:08:16 +0100 Subject: tai64n: whiten nano seconds Avoid being too precise of a time oracle. --- tai64n/tai64n.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tai64n') diff --git a/tai64n/tai64n.go b/tai64n/tai64n.go index f402f05..565aaa4 100644 --- a/tai64n/tai64n.go +++ b/tai64n/tai64n.go @@ -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 -- cgit v1.2.3