aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime/thread_openbsd.c
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2013-03-12 10:47:44 -0700
committerKeith Randall <khr@golang.org>2013-03-12 10:47:44 -0700
commita5d4024139231ca10b5347d17bbf702cfdf5fd5b (patch)
tree5ac78c98317c3bcb2b881629d69b225f76afad5f /src/pkg/runtime/thread_openbsd.c
parent4e032ce301f980d238d876278d60a4937c772814 (diff)
downloadgo-a5d4024139231ca10b5347d17bbf702cfdf5fd5b.tar.xz
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
Diffstat (limited to 'src/pkg/runtime/thread_openbsd.c')
-rw-r--r--src/pkg/runtime/thread_openbsd.c16
1 files changed, 16 insertions, 0 deletions
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
@@ -160,6 +160,22 @@ runtime·osinit(void)
}
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)
{
runtime·goenvs_unix();