diff options
| author | Keith Randall <khr@golang.org> | 2013-03-12 10:47:44 -0700 |
|---|---|---|
| committer | Keith Randall <khr@golang.org> | 2013-03-12 10:47:44 -0700 |
| commit | a5d4024139231ca10b5347d17bbf702cfdf5fd5b (patch) | |
| tree | 5ac78c98317c3bcb2b881629d69b225f76afad5f /src/pkg/runtime/thread_linux.c | |
| parent | 4e032ce301f980d238d876278d60a4937c772814 (diff) | |
| download | go-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_linux.c')
| -rw-r--r-- | src/pkg/runtime/thread_linux.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/pkg/runtime/thread_linux.c b/src/pkg/runtime/thread_linux.c index 78ddef878b..fe924b264a 100644 --- a/src/pkg/runtime/thread_linux.c +++ b/src/pkg/runtime/thread_linux.c @@ -9,10 +9,6 @@ extern SigTab runtime·sigtab[]; -int32 runtime·open(uint8*, int32, int32); -int32 runtime·close(int32); -int32 runtime·read(int32, void*, int32); - static Sigset sigset_none; static Sigset sigset_all = { ~(uint32)0, ~(uint32)0 }; @@ -164,6 +160,32 @@ runtime·osinit(void) runtime·ncpu = getproccount(); } +// Random bytes initialized at startup. These come +// from the ELF AT_RANDOM auxiliary vector (vdso_linux_amd64.c). +byte* runtime·startup_random_data; +uint32 runtime·startup_random_data_len; + +void +runtime·get_random_data(byte **rnd, int32 *rnd_len) +{ + if(runtime·startup_random_data != nil) { + *rnd = runtime·startup_random_data; + *rnd_len = runtime·startup_random_data_len; + } else { + 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) { |
