Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: using CryptGenRandom to generate randomness slows process startup #15589

Closed
jstarks opened this issue May 7, 2016 · 3 comments

Comments

Projects
None yet
4 participants
@jstarks
Copy link

commented May 7, 2016

In Windows's runtime.getRandomData(), CryptGenRandom is used to retrieve random data from the system random number generator. Using this API causes initialization of the entire Windows crypto API surface, which is expensive and probably usually otherwise unnecessary.

The recommended way to fix this is to use BCryptGenRandom with a NULL provider and BCRYPT_USE_SYSTEM_PREFERRED_RNG. This is what .NET Core does on Windows, for example. However, this is only supported on Windows 7 and newer OSes.

A slightly faster approach and one that works on XP is to use RtlGenRandom. Although this function is not well-documented, it uses the same RNG as the other functions, it has been recommended by Microsoft in a blog, and it is used in other open source projects such as Chromium and Firefox.

I have a prototype (38633e2) of that uses RtlGenRandom that reduces process startup time from 22ms to 20ms on my machine.

If this approach seems worthwhile then I can send out a code review.

@alexbrainman

This comment has been minimized.

Copy link
Member

commented May 7, 2016

Use of RtlGenRandom sounds good to me. Please send a code review. But it won't get submitted until after go1.7 is released - the tree is frozen at this moment. Thank you.

Alex

@alexbrainman alexbrainman changed the title runtime/os_windows.go: Using CryptGenRandom to generate randomness slows process startup runtime: using CryptGenRandom to generate randomness slows process startup May 7, 2016

@gopherbot

This comment has been minimized.

Copy link

commented May 8, 2016

CL https://golang.org/cl/22933 mentions this issue.

@bradfitz bradfitz added this to the Go1.8 milestone May 9, 2016

@gopherbot

This comment has been minimized.

Copy link

commented Sep 27, 2016

CL https://golang.org/cl/29700 mentions this issue.

@gopherbot gopherbot closed this in db82cf4 Sep 28, 2016

@golang golang locked and limited conversation to collaborators Sep 28, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.