diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2016-03-18 14:46:20 +0100 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2016-03-18 14:46:20 +0100 |
commit | dcf31cdc994163b3ee5641545ae8706f3c10182f (patch) | |
tree | cc35cdafaf567f7d00d08f844c33141e9ab3c14b /winsup/cygwin/miscfuncs.cc | |
parent | e0fc33322d507c0730b1d1517eb4b85181f0a2d9 (diff) | |
download | newlib-dcf31cdc994163b3ee5641545ae8706f3c10182f.zip newlib-dcf31cdc994163b3ee5641545ae8706f3c10182f.tar.gz newlib-dcf31cdc994163b3ee5641545ae8706f3c10182f.tar.bz2 |
Implement getentropy for Cygwin
* miscfuncs.cc (getentropy): Move fhandler_dev_random::crypt_gen_random
here and rename to getentropy. Fix type and return values to match
getentropy requirements.
* miscfuncs.h (getentropy): Add prototype.
* fhandler.h (fhandler_dev_random::crypt_gen_random): Remove prototype.
* fhandler_random.cc (fhandler_dev_random::crypt_gen_random): Drop.
(fhandler_dev_random::write): Use getentropy instead.
(fhandler_dev_random::read): Ditto.
* fhandler_socket.cc (fhandler_socket::af_local_set_secret): Ditto.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup/cygwin/miscfuncs.cc')
-rw-r--r-- | winsup/cygwin/miscfuncs.cc | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc index 7964941..54150f1 100644 --- a/winsup/cygwin/miscfuncs.cc +++ b/winsup/cygwin/miscfuncs.cc @@ -236,6 +236,25 @@ check_iovec (const struct iovec *iov, int iovcnt, bool forwrite) return -1; } +/* There's a bug in ntsecapi.h (Mingw as well as MSFT). SystemFunction036 + is, in fact, a WINAPI function, but it's not defined as such. Therefore + we have to do it correctly here. */ +#define RtlGenRandom SystemFunction036 +extern "C" BOOLEAN WINAPI RtlGenRandom (PVOID, ULONG); + +/* Used by arc2random, fhandler_socket and fhandler_random. */ +extern "C" int +getentropy (void *ptr, size_t len) +{ + if (!RtlGenRandom (ptr, len)) + { + debug_printf ("%E = RtlGenRandom()"); + set_errno (EIO); + return -1; + } + return 0; +} + /* Try hard to schedule another thread. Remember not to call this in a lock condition or you'll potentially suffer starvation. */ |