diff options
author | Terry Jan Reedy <tjreedy@udel.edu> | 2013-03-16 02:52:24 -0400 |
---|---|---|
committer | Terry Jan Reedy <tjreedy@udel.edu> | 2013-03-16 02:52:24 -0400 |
commit | ddf47eb8c61ed4d3ee3ec680336b016b627e53dd (patch) | |
tree | 7c238ff29a60d4957e6e26d336a6163f061d057d /Python/random.c | |
parent | f612c8fa7c1d6e244200a3eff0a82abcca4cca82 (diff) | |
parent | cdfac6f16bec10dcb4885fd7f74ae80884d0cdf1 (diff) | |
download | cpython-ddf47eb8c61ed4d3ee3ec680336b016b627e53dd.tar.gz |
Merge with 3.3
Diffstat (limited to 'Python/random.c')
-rw-r--r-- | Python/random.c | 33 |
1 files changed, 3 insertions, 30 deletions
diff --git a/Python/random.c b/Python/random.c index 53518c2ebe..1ad4c3df7f 100644 --- a/Python/random.c +++ b/Python/random.c @@ -12,13 +12,6 @@ static int _Py_HashSecret_Initialized = 0; #endif #ifdef MS_WINDOWS -typedef BOOL (WINAPI *CRYPTACQUIRECONTEXTA)(HCRYPTPROV *phProv,\ - LPCSTR pszContainer, LPCSTR pszProvider, DWORD dwProvType,\ - DWORD dwFlags ); -typedef BOOL (WINAPI *CRYPTGENRANDOM)(HCRYPTPROV hProv, DWORD dwLen,\ - BYTE *pbBuffer ); - -static CRYPTGENRANDOM pCryptGenRandom = NULL; /* This handle is never explicitly released. Instead, the operating system will release it when the process terminates. */ static HCRYPTPROV hCryptProv = 0; @@ -26,29 +19,9 @@ static HCRYPTPROV hCryptProv = 0; static int win32_urandom_init(int raise) { - HINSTANCE hAdvAPI32 = NULL; - CRYPTACQUIRECONTEXTA pCryptAcquireContext = NULL; - - /* Obtain handle to the DLL containing CryptoAPI. This should not fail. */ - hAdvAPI32 = GetModuleHandle("advapi32.dll"); - if(hAdvAPI32 == NULL) - goto error; - - /* Obtain pointers to the CryptoAPI functions. This will fail on some early - versions of Win95. */ - pCryptAcquireContext = (CRYPTACQUIRECONTEXTA)GetProcAddress( - hAdvAPI32, "CryptAcquireContextA"); - if (pCryptAcquireContext == NULL) - goto error; - - pCryptGenRandom = (CRYPTGENRANDOM)GetProcAddress(hAdvAPI32, - "CryptGenRandom"); - if (pCryptGenRandom == NULL) - goto error; - /* Acquire context */ - if (! pCryptAcquireContext(&hCryptProv, NULL, NULL, - PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) + if (!CryptAcquireContext(&hCryptProv, NULL, NULL, + PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) goto error; return 0; @@ -77,7 +50,7 @@ win32_urandom(unsigned char *buffer, Py_ssize_t size, int raise) while (size > 0) { chunk = size > INT_MAX ? INT_MAX : size; - if (!pCryptGenRandom(hCryptProv, chunk, buffer)) + if (!CryptGenRandom(hCryptProv, chunk, buffer)) { /* CryptGenRandom() failed */ if (raise) |