[FFmpeg-cvslog] random_seed: Support using CryptGenRandom on windows
Martin Storsjö
git at videolan.org
Fri Oct 12 14:19:07 CEST 2012
ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Thu Oct 11 14:30:23 2012 +0300| [1093383d6cf7112d54b849e29c739e957d157b25] | committer: Martin Storsjö
random_seed: Support using CryptGenRandom on windows
Signed-off-by: Martin Storsjö <martin at martin.st>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1093383d6cf7112d54b849e29c739e957d157b25
---
configure | 2 ++
libavutil/random_seed.c | 15 +++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/configure b/configure
index 17f38ec..67f88eb 100755
--- a/configure
+++ b/configure
@@ -1139,6 +1139,7 @@ HAVE_LIST="
closesocket
cmov
cpunop
+ CryptGenRandom
dcbzl
dev_bktr_ioctl_bt848_h
dev_bktr_ioctl_meteor_h
@@ -3202,6 +3203,7 @@ check_func sysctl
check_func usleep
check_func_headers io.h setmode
check_lib2 "windows.h shellapi.h" CommandLineToArgvW -lshell32
+check_lib2 "windows.h wincrypt.h" CryptGenRandom -ladvapi32
check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi
check_func_headers windows.h GetProcessAffinityMask
check_func_headers windows.h GetProcessTimes
diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
index 8ee4cb7..ec9caa7 100644
--- a/libavutil/random_seed.c
+++ b/libavutil/random_seed.c
@@ -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))
More information about the ffmpeg-cvslog
mailing list