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/thread_openbsd.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/pkg/runtime/thread_openbsd.c') diff --git a/src/pkg/runtime/thread_openbsd.c b/src/pkg/runtime/thread_openbsd.c index 700c481475..f2d17404fd 100644 --- a/src/pkg/runtime/thread_openbsd.c +++ b/src/pkg/runtime/thread_openbsd.c @@ -159,6 +159,22 @@ runtime·osinit(void) runtime·ncpu = getncpu(); } +void +runtime·get_random_data(byte **rnd, int32 *rnd_len) +{ + static byte urandom_data[HashRandomBytes]; + int32 fd; + fd = runtime·open("/dev/urandom", 0 /* O_RDONLY */, 0); + if(runtime·read(fd, urandom_data, HashRandomBytes) == HashRandomBytes) { + *rnd = urandom_data; + *rnd_len = HashRandomBytes; + } else { + *rnd = nil; + *rnd_len = 0; + } + runtime·close(fd); +} + void runtime·goenvs(void) { -- cgit v1.3