random_seed: Support using CryptGenRandom on windows
Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
parent
26b3fde6a7
commit
1093383d6c
2 changed files with 17 additions and 0 deletions
|
@ -23,6 +23,10 @@
|
|||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#if HAVE_CRYPTGENRANDOM
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
|
@ -82,6 +86,17 @@ uint32_t av_get_random_seed(void)
|
|||
{
|
||||
uint32_t seed;
|
||||
|
||||
#if HAVE_CRYPTGENRANDOM
|
||||
HCRYPTPROV provider;
|
||||
if (CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL,
|
||||
CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
|
||||
BOOL ret = CryptGenRandom(provider, sizeof(seed), (PBYTE) &seed);
|
||||
CryptReleaseContext(provider, 0);
|
||||
if (ret)
|
||||
return seed;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (read_random(&seed, "/dev/urandom") == sizeof(seed))
|
||||
return seed;
|
||||
if (read_random(&seed, "/dev/random") == sizeof(seed))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue