diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2019-06-22 15:18:17 +0200 |
---|---|---|
committer | Saúl Ibarra Corretgé <s@saghul.net> | 2019-09-18 08:09:14 +0200 |
commit | 4ed2a78f0eb1c9d2a0c98ea4a88c6824e5958dc6 (patch) | |
tree | ce6b8b3282f3ac65d6bbeba5cec36463b68f06e5 /src/win/util.c | |
parent | fd1502f5630591bf8ce79502df9b5d76868dfd3b (diff) | |
download | libuv-4ed2a78f0eb1c9d2a0c98ea4a88c6824e5958dc6.tar.gz libuv-4ed2a78f0eb1c9d2a0c98ea4a88c6824e5958dc6.zip |
unix,win: add uv_random()
Add an API for obtaining cryptographically strong random data from the
system PRNG.
Co-authored-by: Saúl Ibarra Corretgé <s@saghul.net>
Refs: https://github.com/libuv/libuv/pull/1055
PR-URL: https://github.com/libuv/libuv/pull/2347
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Diffstat (limited to 'src/win/util.c')
-rw-r--r-- | src/win/util.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/win/util.c b/src/win/util.c index d52dd99c..4bbeb315 100644 --- a/src/win/util.c +++ b/src/win/util.c @@ -1860,3 +1860,16 @@ int uv_gettimeofday(uv_timeval64_t* tv) { tv->tv_usec = (int32_t) (((ularge.QuadPart - epoch) % 10000000L) / 10); return 0; } + +int uv__random_rtlgenrandom(void* buf, size_t buflen) { + if (pRtlGenRandom == NULL) + return UV_ENOSYS; + + if (buflen == 0) + return 0; + + if (pRtlGenRandom(buf, buflen) == FALSE) + return UV_EIO; + + return 0; +} |