32 #if !(defined(HAVE_WINCRYPT_H) && defined(OS_WIN32))
33 #if defined(HAVE_CLOCK_GETTIME)
35 static long int RandomGetClock(
void)
38 clock_gettime(CLOCK_REALTIME, &
ts);
41 srandom(
ts.tv_nsec ^
ts.tv_sec);
42 long int value = random();
48 static long int RandomGetPosix(
void)
51 memset(&
tv, 0,
sizeof(
tv));
52 gettimeofday(&
tv, NULL);
55 srandom(
tv.tv_usec ^
tv.tv_sec);
56 long int value = random();
63 #if defined(HAVE_WINCRYPT_H) && defined(OS_WIN32)
72 if (!CryptAcquireContext(&p, NULL, NULL, PROV_RSA_FULL, 0)) {
73 DWORD err = GetLastError();
74 SCLogDebug(
"CryptAcquireContext error: %" PRIu32, (uint32_t)err);
75 if (err == (DWORD)NTE_BAD_KEYSET) {
77 if (!CryptAcquireContext(&p, NULL, NULL, PROV_RSA_FULL,
80 SCLogDebug(
"CryptAcquireContext error: %" PRIu32,
90 if (!CryptGenRandom(p,
sizeof(value), (BYTE *)&value)) {
91 (void)CryptReleaseContext(p, 0);
95 (void)CryptReleaseContext(p, 0);
99 #elif defined(HAVE_GETRANDOM)
106 int ret = getrandom(&value,
sizeof(value), 0);
110 if (ret == -1 && errno == ENOSYS) {
111 #if defined(HAVE_CLOCK_GETTIME)
112 return RandomGetClock();
114 return RandomGetPosix();
121 #elif defined(HAVE_CLOCK_GETTIME)
127 return RandomGetClock();
135 return RandomGetPosix();