diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2022-02-07 17:33:55 +0100 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2022-02-14 10:45:50 +0100 |
commit | 6b5634b96aa90ab2db7357b353fc8f96ad4878c5 (patch) | |
tree | 79683c4d2e538e5702a74a5b431a0913777ee0ed /platform/windows | |
parent | 8317753c24f6a05d4fdc8541fecf1cd2ec189b41 (diff) |
[OS/Crypto] Add get_entropy to OS.
Implemented via `BCryptGenRandom` on Windows.
Implemented via `getentropy` syscall when available.
Implemented via `/dev/urandom` device as a fallback.
The `/dev/urandom` fallback can be disabled via the `NO_URANDOM` build
flag.
Note: The HTML5 version relies on emscripten file system urandom
device which itself uses the Crypto API when available or the plain
old not crypto-safe `Math.random()` otherwise.
Restore get_entropy.
Diffstat (limited to 'platform/windows')
-rw-r--r-- | platform/windows/os_windows.cpp | 7 | ||||
-rw-r--r-- | platform/windows/os_windows.h | 2 |
2 files changed, 9 insertions, 0 deletions
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index d844531071..59f55b5dd2 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -46,6 +46,7 @@ #include "windows_terminal_logger.h" #include <avrt.h> +#include <bcrypt.h> #include <direct.h> #include <knownfolders.h> #include <process.h> @@ -192,6 +193,12 @@ void OS_Windows::finalize_core() { NetSocketPosix::cleanup(); } +Error OS_Windows::get_entropy(uint8_t *r_buffer, int p_bytes) { + NTSTATUS status = BCryptGenRandom(nullptr, r_buffer, p_bytes, BCRYPT_USE_SYSTEM_PREFERRED_RNG); + ERR_FAIL_COND_V(status, FAILED); + return OK; +} + Error OS_Windows::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) { String path = p_path.replace("/", "\\"); diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index 0a11416b1b..bde663a27b 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -106,6 +106,8 @@ protected: public: virtual void alert(const String &p_alert, const String &p_title = "ALERT!") override; + virtual Error get_entropy(uint8_t *r_buffer, int p_bytes) override; + virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false) override; virtual Error close_dynamic_library(void *p_library_handle) override; virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional = false) override; |