aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkristopher tate <kt@connectfree.co.jp>2018-08-03 02:14:52 +0900
committerkristopher tate <kt@connectfree.co.jp>2018-08-03 02:14:52 +0900
commitc44653f40f37c93fc68a2e455d693bb11f1c11d3 (patch)
treec74b9e998305eefdbc975c6a017b0afc3a297ba2
parent22fd359e2c601c9d0a009705bed60c88821f2b0f (diff)
downloadzig-c44653f40f37c93fc68a2e455d693bb11f1c11d3.tar.gz
zig-c44653f40f37c93fc68a2e455d693bb11f1c11d3.zip
std/os/index.zig: swap CryptGetRandom() with RtlGenRandom();
Tracking Issue #1318 ;
-rw-r--r--std/os/index.zig14
1 files changed, 4 insertions, 10 deletions
diff --git a/std/os/index.zig b/std/os/index.zig
index 77fd2a78ad..7042247a2f 100644
--- a/std/os/index.zig
+++ b/std/os/index.zig
@@ -130,16 +130,10 @@ pub fn getRandomBytes(buf: []u8) !void {
try posixRead(fd, buf);
},
Os.windows => {
- var hCryptProv: windows.HCRYPTPROV = undefined;
- if (windows.CryptAcquireContextA(&hCryptProv, null, null, windows.PROV_RSA_FULL, 0) == 0) {
- const err = windows.GetLastError();
- return switch (err) {
- else => unexpectedErrorWindows(err),
- };
- }
- defer _ = windows.CryptReleaseContext(hCryptProv, 0);
-
- if (windows.CryptGenRandom(hCryptProv, @intCast(windows.DWORD, buf.len), buf.ptr) == 0) {
+ // Call RtlGenRandom() instead of CryptGetRandom() on Windows
+ // https://github.com/rust-lang-nursery/rand/issues/111
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=504270
+ if (!windows.RtlGenRandom(buf.ptr, buf.len)) {
const err = windows.GetLastError();
return switch (err) {
else => unexpectedErrorWindows(err),