| Server IP : 127.0.0.1 / Your IP : 216.73.216.109 Web Server : Apache/2.4.54 (Win64) OpenSSL/1.1.1q PHP/8.1.10 System : Windows NT DESKTOP-E5T4RUN 10.0 build 19045 (Windows 10) AMD64 User : SERVERWEB ( 0) PHP Version : 8.1.10 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/cygwin64/usr/src/debug/cygwin-3.5.1-1/winsup/cygwin/libc/ |
Upload File : |
/* getentropy.cc: getentropy/getrandmom functions
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include "winsup.h"
#include <ntsecapi.h>
#include <sys/param.h>
#include <sys/random.h>
#include "cygtls.h"
#include "ntdll.h"
extern "C" int
getentropy (void *ptr, size_t len)
{
/* Per BSD man page: The maximum buffer size permitted is 256 bytes.
If buflen exceeds this, an error of EIO will be indicated. */
if (len > 256)
{
debug_printf ("len (%U) > 256", len);
set_errno (EIO);
return -1;
}
__try
{
if (!RtlGenRandom (ptr, len))
{
debug_printf ("RtlGenRandom() = FALSE");
set_errno (EIO);
return -1;
}
}
__except (EFAULT)
{
return -1;
}
__endtry
return 0;
}
extern "C" ssize_t
getrandom (void *ptr, size_t len, unsigned int flags)
{
if (flags & ~(GRND_NONBLOCK | GRND_RANDOM))
{
debug_printf ("invalid flags: %y", flags);
set_errno (EINVAL);
return -1;
}
/* Max. bytes returned by Linux call. */
len = MIN (len, (flags & GRND_RANDOM) ? 512 : 33554431);
__try
{
if (!RtlGenRandom (ptr, len))
{
debug_printf ("RtlGenRandom() = FALSE");
set_errno (EIO);
return -1;
}
}
__except (EFAULT)
{
return -1;
}
__endtry
return len;
}