aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/hash_test.go
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2016-05-26 08:56:49 -0700
committerKeith Randall <khr@golang.org>2016-06-11 00:35:47 +0000
commitc83e6f50d983d81166d21736ff9ab0ad2182f0fa (patch)
treee01a4665ebf3bda86355dd71477fc8377e8e55b3 /src/runtime/hash_test.go
parentcea29c4a358004d84d8711a07628c2f856b381e8 (diff)
downloadgo-c83e6f50d983d81166d21736ff9ab0ad2182f0fa.tar.gz
go-c83e6f50d983d81166d21736ff9ab0ad2182f0fa.zip
runtime: aeshash, xor seed in earlier
Instead of doing: x = input one round of aes on x x ^= seed two rounds of aes on x Do: x = input x ^= seed three rounds of aes on x This change provides some additional seed-dependent scrambling which should help prevent collisions. Change-Id: I02c774d09c2eb6917cf861513816a1024a9b65d7 Reviewed-on: https://go-review.googlesource.com/23577 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime/hash_test.go')
-rw-r--r--src/runtime/hash_test.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/runtime/hash_test.go b/src/runtime/hash_test.go
index 96ed68247e..3108b3bf59 100644
--- a/src/runtime/hash_test.go
+++ b/src/runtime/hash_test.go
@@ -681,3 +681,23 @@ func BenchmarkUnalignedLoad(b *testing.B) {
}
sink = s
}
+
+func TestCollisions(t *testing.T) {
+ for i := 0; i < 16; i++ {
+ for j := 0; j < 16; j++ {
+ if j == i {
+ continue
+ }
+ var a [16]byte
+ m := make(map[uint16]struct{}, 1<<16)
+ for n := 0; n < 1<<16; n++ {
+ a[i] = byte(n)
+ a[j] = byte(n >> 8)
+ m[uint16(BytesHash(a[:], 0))] = struct{}{}
+ }
+ if len(m) <= 1<<15 {
+ t.Errorf("too many collisions i=%d j=%d outputs=%d out of 65536\n", i, j, len(m))
+ }
+ }
+ }
+}