mirror of
https://github.com/Silicondust/libhdhomerun
synced 2025-08-20 05:23:27 -07:00
Use RtlGenRandom when available to elminiate TLS and heap leaks
This commit is contained in:
parent
b0e5d5f5c8
commit
a68406e84c
2 changed files with 8 additions and 22 deletions
|
@ -20,34 +20,16 @@
|
||||||
|
|
||||||
#include "hdhomerun.h"
|
#include "hdhomerun.h"
|
||||||
|
|
||||||
#if defined(_WINRT)
|
|
||||||
uint32_t random_get32(void)
|
uint32_t random_get32(void)
|
||||||
{
|
{
|
||||||
return (uint32_t)getcurrenttime();
|
uint32_t Result = (uint32_t)getcurrenttime();
|
||||||
}
|
|
||||||
#else
|
|
||||||
uint32_t random_get32(void)
|
|
||||||
{
|
|
||||||
static DWORD random_get32_context_tls = 0xFFFFFFFF;
|
|
||||||
if (random_get32_context_tls == 0xFFFFFFFF) {
|
|
||||||
random_get32_context_tls = TlsAlloc();
|
|
||||||
}
|
|
||||||
|
|
||||||
HCRYPTPROV *phProv = (HCRYPTPROV *)TlsGetValue(random_get32_context_tls);
|
#if defined(RtlGenRandom)
|
||||||
if (!phProv) {
|
RtlGenRandom(&Result, sizeof(Result));
|
||||||
phProv = (HCRYPTPROV *)calloc(1, sizeof(HCRYPTPROV));
|
#endif
|
||||||
CryptAcquireContext(phProv, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
|
|
||||||
TlsSetValue(random_get32_context_tls, phProv);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t Result;
|
|
||||||
if (!CryptGenRandom(*phProv, sizeof(Result), (BYTE *)&Result)) {
|
|
||||||
return (uint32_t)getcurrenttime();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
uint64_t getcurrenttime(void)
|
uint64_t getcurrenttime(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -46,6 +46,10 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#define SystemFunction036 NTAPI SystemFunction036
|
||||||
|
#include <ntsecapi.h>
|
||||||
|
#undef SystemFunction036
|
||||||
|
|
||||||
#ifdef LIBHDHOMERUN_DLLEXPORT
|
#ifdef LIBHDHOMERUN_DLLEXPORT
|
||||||
#define LIBHDHOMERUN_API __declspec(dllexport)
|
#define LIBHDHOMERUN_API __declspec(dllexport)
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue