authorgravatar for kt@connectfree.co.jpkristopher tate <kt@connectfree.co.jp> 2018-08-03 02:14:52+09:00
committergravatar for kt@connectfree.co.jpkristopher tate <kt@connectfree.co.jp> 2018-08-03 02:14:52+09:00
logc44653f40f37c93fc68a2e455d693bb11f1c11d3
treec74b9e998305eefdbc975c6a017b0afc3a297ba2
parent22fd359e2c601c9d0a009705bed60c88821f2b0f

std/os/index.zig: swap CryptGetRandom() with RtlGenRandom();

Tracking Issue #1318 ;

1 files changed, 4 insertions(+), 10 deletions(-)

std/os/index.zig+4-10
......@@ -130,16 +130,10 @@ pub fn getRandomBytes(buf: []u8) !void {
130130 try posixRead(fd, buf);
131131 },
132132 Os.windows => {
133 var hCryptProv: windows.HCRYPTPROV = undefined;
134 if (windows.CryptAcquireContextA(&hCryptProv, null, null, windows.PROV_RSA_FULL, 0) == 0) {
135 const err = windows.GetLastError();
136 return switch (err) {
137 else => unexpectedErrorWindows(err),
138 };
139 }
140 defer _ = windows.CryptReleaseContext(hCryptProv, 0);
141
142 if (windows.CryptGenRandom(hCryptProv, @intCast(windows.DWORD, buf.len), buf.ptr) == 0) {
133 // Call RtlGenRandom() instead of CryptGetRandom() on Windows
134 // https://github.com/rust-lang-nursery/rand/issues/111
135 // https://bugzilla.mozilla.org/show_bug.cgi?id=504270
136 if (!windows.RtlGenRandom(buf.ptr, buf.len)) {
143137 const err = windows.GetLastError();
144138 return switch (err) {
145139 else => unexpectedErrorWindows(err),