From a5d4024139231ca10b5347d17bbf702cfdf5fd5b Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 12 Mar 2013 10:47:44 -0700 Subject: runtime: faster & safer hash function Uses AES hardware instructions on 386/amd64 to implement a fast hash function. Incorporates a random key to thwart hash collision DOS attacks. Depends on CL#7548043 for new assembly instructions. Update #3885 Helps some by making hashing faster. Go time drops from 0.65s to 0.51s. R=rsc, r, bradfitz, remyoudompheng, khr, dsymonds, minux.ma, elias.naur CC=golang-dev https://golang.org/cl/7543043 --- src/pkg/runtime/runtime.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/pkg/runtime/runtime.h') diff --git a/src/pkg/runtime/runtime.h b/src/pkg/runtime/runtime.h index ffbd5c219d..026c7a5375 100644 --- a/src/pkg/runtime/runtime.h +++ b/src/pkg/runtime/runtime.h @@ -558,11 +558,25 @@ struct Alg extern Alg runtime·algarray[Amax]; +byte* runtime·startup_random_data; +uint32 runtime·startup_random_data_len; +void runtime·get_random_data(byte**, int32*); + +enum { + // hashinit wants this many random bytes + HashRandomBytes = 32 +}; +void runtime·hashinit(void); + void runtime·memhash(uintptr*, uintptr, void*); void runtime·nohash(uintptr*, uintptr, void*); void runtime·strhash(uintptr*, uintptr, void*); void runtime·interhash(uintptr*, uintptr, void*); void runtime·nilinterhash(uintptr*, uintptr, void*); +void runtime·aeshash(uintptr*, uintptr, void*); +void runtime·aeshash32(uintptr*, uintptr, void*); +void runtime·aeshash64(uintptr*, uintptr, void*); +void runtime·aeshashstr(uintptr*, uintptr, void*); void runtime·memequal(bool*, uintptr, void*, void*); void runtime·noequal(bool*, uintptr, void*, void*); @@ -581,7 +595,6 @@ void runtime·memcopy16(uintptr, void*, void*); void runtime·memcopy32(uintptr, void*, void*); void runtime·memcopy64(uintptr, void*, void*); void runtime·memcopy128(uintptr, void*, void*); -void runtime·memcopy(uintptr, void*, void*); void runtime·strcopy(uintptr, void*, void*); void runtime·algslicecopy(uintptr, void*, void*); void runtime·intercopy(uintptr, void*, void*); @@ -638,6 +651,8 @@ extern bool runtime·iscgo; extern void (*runtime·sysargs)(int32, uint8**); extern uint32 runtime·maxstring; extern uint32 runtime·Hchansize; +extern uint32 runtime·cpuid_ecx; +extern uint32 runtime·cpuid_edx; /* * common functions and data @@ -684,7 +699,10 @@ int32 runtime·gotraceback(void); void runtime·goroutineheader(G*); void runtime·traceback(uint8 *pc, uint8 *sp, uint8 *lr, G* gp); void runtime·tracebackothers(G*); +int32 runtime·open(int8*, int32, int32); +int32 runtime·read(int32, void*, int32); int32 runtime·write(int32, void*, int32); +int32 runtime·close(int32); int32 runtime·mincore(void*, uintptr, byte*); bool runtime·cas(uint32*, uint32, uint32); bool runtime·cas64(uint64*, uint64*, uint64); -- cgit v1.3