1
0
mirror of https://github.com/golang/go synced 2024-11-26 14:36:52 -07:00

runtime: always incorporate hash seed at start of hash computation

Otherwise we can get predictable collisions.

R=golang-dev, dave, patrick, rsc
CC=golang-dev
https://golang.org/cl/7051043
This commit is contained in:
Ian Lance Taylor 2013-01-04 07:53:42 -08:00
parent c09649890f
commit 63bee953a2
3 changed files with 13 additions and 14 deletions

View File

@ -19,13 +19,13 @@ runtime·memhash(uintptr *h, uintptr s, void *a)
uintptr hash;
b = a;
hash = M0;
hash = M0 ^ *h;
while(s > 0) {
hash = (hash ^ *b) * M1;
b++;
s--;
}
*h = (*h ^ hash) * M1;
*h = hash;
}
void
@ -355,7 +355,7 @@ void
runtime·interhash(uintptr *h, uintptr s, void *a)
{
USED(s);
*h = (*h ^ runtime·ifacehash(*(Iface*)a)) * M1;
*h = runtime·ifacehash(*(Iface*)a, *h ^ M0) * M1;
}
void
@ -389,7 +389,7 @@ void
runtime·nilinterhash(uintptr *h, uintptr s, void *a)
{
USED(s);
*h = (*h ^ runtime·efacehash(*(Eface*)a)) * M1;
*h = runtime·efacehash(*(Eface*)a, *h ^ M0) * M1;
}
void

View File

@ -546,10 +546,10 @@ runtime·assertE2E2(InterfaceType* inter, Eface e, Eface ret, bool ok)
}
static uintptr
ifacehash1(void *data, Type *t)
ifacehash1(void *data, Type *t, uintptr h)
{
Alg *alg;
uintptr size, h;
uintptr size;
Eface err;
if(t == nil)
@ -563,7 +563,6 @@ ifacehash1(void *data, Type *t)
runtime·newErrorString(runtime·catstring(runtime·gostringnocopy((byte*)"hash of unhashable type "), *t->string), &err);
runtime·panic(err);
}
h = 0;
if(size <= sizeof(data))
alg->hash(&h, size, &data);
else
@ -572,17 +571,17 @@ ifacehash1(void *data, Type *t)
}
uintptr
runtime·ifacehash(Iface a)
runtime·ifacehash(Iface a, uintptr h)
{
if(a.tab == nil)
return 0;
return ifacehash1(a.data, a.tab->type);
return h;
return ifacehash1(a.data, a.tab->type, h);
}
uintptr
runtime·efacehash(Eface a)
runtime·efacehash(Eface a, uintptr h)
{
return ifacehash1(a.data, a.type);
return ifacehash1(a.data, a.type, h);
}
static bool

View File

@ -644,8 +644,8 @@ void runtime·freemcache(MCache*);
void runtime·mallocinit(void);
bool runtime·ifaceeq_c(Iface, Iface);
bool runtime·efaceeq_c(Eface, Eface);
uintptr runtime·ifacehash(Iface);
uintptr runtime·efacehash(Eface);
uintptr runtime·ifacehash(Iface, uintptr);
uintptr runtime·efacehash(Eface, uintptr);
void* runtime·malloc(uintptr size);
void runtime·free(void *v);
bool runtime·addfinalizer(void*, void(*fn)(void*), uintptr);