std/os/index.zig: swap CryptGetRandom() with RtlGenRandom();
Tracking Issue #1318 ;
This commit is contained in:
parent
22fd359e2c
commit
c44653f40f
@ -130,16 +130,10 @@ pub fn getRandomBytes(buf: []u8) !void {
|
|||||||
try posixRead(fd, buf);
|
try posixRead(fd, buf);
|
||||||
},
|
},
|
||||||
Os.windows => {
|
Os.windows => {
|
||||||
var hCryptProv: windows.HCRYPTPROV = undefined;
|
// Call RtlGenRandom() instead of CryptGetRandom() on Windows
|
||||||
if (windows.CryptAcquireContextA(&hCryptProv, null, null, windows.PROV_RSA_FULL, 0) == 0) {
|
// https://github.com/rust-lang-nursery/rand/issues/111
|
||||||
const err = windows.GetLastError();
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=504270
|
||||||
return switch (err) {
|
if (!windows.RtlGenRandom(buf.ptr, buf.len)) {
|
||||||
else => unexpectedErrorWindows(err),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
defer _ = windows.CryptReleaseContext(hCryptProv, 0);
|
|
||||||
|
|
||||||
if (windows.CryptGenRandom(hCryptProv, @intCast(windows.DWORD, buf.len), buf.ptr) == 0) {
|
|
||||||
const err = windows.GetLastError();
|
const err = windows.GetLastError();
|
||||||
return switch (err) {
|
return switch (err) {
|
||||||
else => unexpectedErrorWindows(err),
|
else => unexpectedErrorWindows(err),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user