diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-02-03 02:08:16 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-02-05 12:59:42 +0100 |
commit | a5ca02d79a953c883694061bba5c683b220fbfe4 (patch) | |
tree | 0c5b0af257d0d0e7bc3af9a406e55684e22529aa /tai64n | |
parent | 2b7562abbb9aad20214387492b8f4f2d089c6738 (diff) |
tai64n: whiten nano seconds
Avoid being too precise of a time oracle.
Diffstat (limited to 'tai64n')
-rw-r--r-- | tai64n/tai64n.go | 5 |
1 files changed, 3 insertions, 2 deletions
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 |