diff --git a/dlls/advapi32/advapi32.spec b/dlls/advapi32/advapi32.spec index 04c9bcf475e..821f6dd4415 100644 --- a/dlls/advapi32/advapi32.spec +++ b/dlls/advapi32/advapi32.spec @@ -343,7 +343,7 @@ @ stub SystemFunction033 @ stub SystemFunction034 @ stub SystemFunction035 -@ stub SystemFunction036 +@ stdcall SystemFunction036(ptr long) # RtlGenRandom @ stdcall SystemFunction040(ptr long long) # RtlEncryptMemory @ stdcall SystemFunction041(ptr long long) # RtlDecryptMemory @ stub TraceEvent diff --git a/dlls/advapi32/crypt.c b/dlls/advapi32/crypt.c index e29c326b9a4..8c08fca3eed 100644 --- a/dlls/advapi32/crypt.c +++ b/dlls/advapi32/crypt.c @@ -27,6 +27,10 @@ #include #include #include +#include +#include +#include +#include #include "crypt.h" #include "winnls.h" @@ -1891,6 +1895,39 @@ BOOL WINAPI CryptVerifySignatureA (HCRYPTHASH hHash, BYTE *pbSignature, DWORD dw return result; } +/****************************************************************************** + * SystemFunction036 (ADVAPI32.@) + * + * MSDN documents this function as RtlGenRandom and declares it in ntsecapi.h + * + * PARAMS + * pbBufer [O] Pointer to memory to receive random bytes. + * dwLen [I] Number of random bytes to fetch. + */ + +BOOL WINAPI SystemFunction036(PVOID pbBuffer, ULONG dwLen) +{ + int dev_random; + + /* FIXME: /dev/urandom does not provide random numbers of a sufficient + * quality for cryptographic applications. /dev/random is much better, + * but it blocks if the kernel has not yet collected enough entropy for + * the request, which will suspend the calling thread for an indefinite + * amount of time. */ + dev_random = open("/dev/urandom", O_RDONLY); + if (dev_random != -1) + { + if (read(dev_random, pbBuffer, dwLen) == (ssize_t)dwLen) + { + close(dev_random); + return TRUE; + } + close(dev_random); + } + SetLastError(NTE_FAIL); + return FALSE; +} + /* These functions have nearly identical prototypes to CryptProtectMemory and CryptUnprotectMemory, in crypt32.dll.