From a360c82b40d8590a1cd02725dfa8a617b99eb0a9 Mon Sep 17 00:00:00 2001 From: Damian Gryski Date: Tue, 7 Dec 2021 16:29:20 -0800 Subject: [PATCH] src/runtime: strengthen hash function for structs and arrays Using `|` to combine hash values will slowly turn every bit on. Hashes combined with `^` with keep more entropy. --- src/runtime/hashmap.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime/hashmap.go b/src/runtime/hashmap.go index 17299c49..826c0da3 100644 --- a/src/runtime/hashmap.go +++ b/src/runtime/hashmap.go @@ -391,13 +391,13 @@ func hashmapInterfaceHash(itf interface{}) uint32 { case reflect.Array: var hash uint32 for i := 0; i < x.Len(); i++ { - hash |= hashmapInterfaceHash(valueInterfaceUnsafe(x.Index(i))) + hash ^= hashmapInterfaceHash(valueInterfaceUnsafe(x.Index(i))) } return hash case reflect.Struct: var hash uint32 for i := 0; i < x.NumField(); i++ { - hash |= hashmapInterfaceHash(valueInterfaceUnsafe(x.Field(i))) + hash ^= hashmapInterfaceHash(valueInterfaceUnsafe(x.Field(i))) } return hash default: