| ... | @@ -130,16 +130,10 @@ pub fn getRandomBytes(buf: []u8) !void { | ... | @@ -130,16 +130,10 @@ pub fn getRandomBytes(buf: []u8) !void { |
| 130 | try posixRead(fd, buf); | 130 | try posixRead(fd, buf); |
| 131 | }, | 131 | }, |
| 132 | Os.windows => { | 132 | Os.windows => { |
| 133 | var hCryptProv: windows.HCRYPTPROV = undefined; | 133 | // Call RtlGenRandom() instead of CryptGetRandom() on Windows |
| 134 | if (windows.CryptAcquireContextA(&hCryptProv, null, null, windows.PROV_RSA_FULL, 0) == 0) { | 134 | // https://github.com/rust-lang-nursery/rand/issues/111 |
| 135 | const err = windows.GetLastError(); | 135 | // https://bugzilla.mozilla.org/show_bug.cgi?id=504270 |
| 136 | return switch (err) { | 136 | if (!windows.RtlGenRandom(buf.ptr, buf.len)) { |
| 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) { | | |
| 143 | const err = windows.GetLastError(); | 137 | const err = windows.GetLastError(); |
| 144 | return switch (err) { | 138 | return switch (err) { |
| 145 | else => unexpectedErrorWindows(err), | 139 | else => unexpectedErrorWindows(err), |