31 #if !(defined(HAVE_WINCRYPT_H) && defined(OS_WIN32))
32 #if defined(HAVE_CLOCK_GETTIME)
34 static long int RandomGetClock(
void)
37 clock_gettime(CLOCK_REALTIME, &
ts);
40 srandom(
ts.tv_nsec ^
ts.tv_sec);
41 long int value = random();
47 static long int RandomGetPosix(
void)
50 memset(&
tv, 0,
sizeof(
tv));
51 gettimeofday(&
tv, NULL);
54 srandom(
tv.tv_usec ^
tv.tv_sec);
55 long int value = random();
62 #if defined(HAVE_WINCRYPT_H) && defined(OS_WIN32)
71 if (!CryptAcquireContext(&p, NULL, NULL, PROV_RSA_FULL, 0)) {
72 DWORD err = GetLastError();
73 SCLogDebug(
"CryptAcquireContext error: %" PRIu32, (uint32_t)err);
74 if (err == (DWORD)NTE_BAD_KEYSET) {
76 if (!CryptAcquireContext(&p, NULL, NULL, PROV_RSA_FULL,
79 SCLogDebug(
"CryptAcquireContext error: %" PRIu32,
89 if (!CryptGenRandom(p,
sizeof(value), (BYTE *)&value)) {
90 (void)CryptReleaseContext(p, 0);
94 (void)CryptReleaseContext(p, 0);
98 #elif defined(HAVE_GETRANDOM)
105 int ret = getrandom(&value,
sizeof(value), 0);
109 if (ret == -1 && errno == ENOSYS) {
110 #if defined(HAVE_CLOCK_GETTIME)
111 return RandomGetClock();
113 return RandomGetPosix();
120 #elif defined(HAVE_CLOCK_GETTIME)
126 return RandomGetClock();
134 return RandomGetPosix();