From 9b2c9b6c1f457be5015f6f651730c93c63c06fe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Fri, 20 Sep 2019 21:42:48 +0200 Subject: [PATCH] win: simplify mkdtemp Use our builtin getrandom helper instead of the more verbose CryptoAPI functions, which also happen to be deprecated. PR-URL: https://github.com/libuv/libuv/pull/2485 Reviewed-By: Colin Ihrig Reviewed-By: Bartosz Sosnowski --- src/win/fs.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/win/fs.c b/src/win/fs.c index 5dccca77..10a8bc16 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -36,8 +36,6 @@ #include "handle-inl.h" #include "fs-fd-hash-inl.h" -#include - #define UV_FS_FREE_PATHS 0x0002 #define UV_FS_FREE_PTR 0x0008 @@ -1207,9 +1205,7 @@ void fs__mkdtemp(uv_fs_t* req) { WCHAR *cp, *ep; unsigned int tries, i; size_t len; - HCRYPTPROV h_crypt_prov; uint64_t v; - BOOL released; len = wcslen(req->file.pathw); ep = req->file.pathw + len; @@ -1218,16 +1214,10 @@ void fs__mkdtemp(uv_fs_t* req) { return; } - if (!CryptAcquireContext(&h_crypt_prov, NULL, NULL, PROV_RSA_FULL, - CRYPT_VERIFYCONTEXT)) { - SET_REQ_WIN32_ERROR(req, GetLastError()); - return; - } - tries = TMP_MAX; do { - if (!CryptGenRandom(h_crypt_prov, sizeof(v), (BYTE*) &v)) { - SET_REQ_WIN32_ERROR(req, GetLastError()); + if (uv__random_rtlgenrandom((void *)&v, sizeof(v)) < 0) { + SET_REQ_UV_ERROR(req, UV_EIO, ERROR_IO_DEVICE); break; } @@ -1248,8 +1238,6 @@ void fs__mkdtemp(uv_fs_t* req) { } } while (--tries); - released = CryptReleaseContext(h_crypt_prov, 0); - assert(released); if (tries == 0) { SET_REQ_RESULT(req, -1); }