Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: nss/lib/freebl/win_rand.c

Issue 17058006: RNG_SystemRNG should fail rather than falling back on rng_systemFromNoise (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/nss/
Patch Set: Use zu to print size_t Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « nss/lib/freebl/unix_rand.c ('k') | patches/nss-rtlgenrandom.patch » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: nss/lib/freebl/win_rand.c
===================================================================
--- nss/lib/freebl/win_rand.c (revision 206814)
+++ nss/lib/freebl/win_rand.c (working copy)
@@ -367,40 +367,6 @@
/*
- * CryptoAPI requires Windows NT 4.0 or Windows 95 OSR2 and later.
- * Until we drop support for Windows 95, we need to emulate some
- * definitions and declarations in <wincrypt.h> and look up the
- * functions in advapi32.dll at run time.
- */
-
-#ifndef WIN64
-typedef unsigned long HCRYPTPROV;
-#endif
-
-#define CRYPT_VERIFYCONTEXT 0xF0000000
-
-#define PROV_RSA_FULL 1
-
-typedef BOOL
-(WINAPI *CryptAcquireContextAFn)(
- HCRYPTPROV *phProv,
- LPCSTR pszContainer,
- LPCSTR pszProvider,
- DWORD dwProvType,
- DWORD dwFlags);
-
-typedef BOOL
-(WINAPI *CryptReleaseContextFn)(
- HCRYPTPROV hProv,
- DWORD dwFlags);
-
-typedef BOOL
-(WINAPI *CryptGenRandomFn)(
- HCRYPTPROV hProv,
- DWORD dwLen,
- BYTE *pbBuffer);
-
-/*
* Windows XP and Windows Server 2003 and later have RtlGenRandom,
* which must be looked up by the name SystemFunction036.
*/
@@ -413,50 +379,19 @@
{
HMODULE hModule;
RtlGenRandomFn pRtlGenRandom;
- CryptAcquireContextAFn pCryptAcquireContextA;
- CryptReleaseContextFn pCryptReleaseContext;
- CryptGenRandomFn pCryptGenRandom;
- HCRYPTPROV hCryptProv;
size_t bytes = 0;
usedWindowsPRNG = PR_FALSE;
hModule = LoadLibrary("advapi32.dll");
if (hModule == NULL) {
- return rng_systemFromNoise(dest,maxLen);
+ return bytes;
}
pRtlGenRandom = (RtlGenRandomFn)
GetProcAddress(hModule, "SystemFunction036");
- if (pRtlGenRandom) {
- if (pRtlGenRandom(dest, maxLen)) {
- bytes = maxLen;
- usedWindowsPRNG = PR_TRUE;
- } else {
- bytes = rng_systemFromNoise(dest,maxLen);
- }
- goto done;
+ if (pRtlGenRandom && pRtlGenRandom(dest, maxLen)) {
+ bytes = maxLen;
+ usedWindowsPRNG = PR_TRUE;
}
- pCryptAcquireContextA = (CryptAcquireContextAFn)
- GetProcAddress(hModule, "CryptAcquireContextA");
- pCryptReleaseContext = (CryptReleaseContextFn)
- GetProcAddress(hModule, "CryptReleaseContext");
- pCryptGenRandom = (CryptGenRandomFn)
- GetProcAddress(hModule, "CryptGenRandom");
- if (!pCryptAcquireContextA || !pCryptReleaseContext || !pCryptGenRandom) {
- bytes = rng_systemFromNoise(dest,maxLen);
- goto done;
- }
- if (pCryptAcquireContextA(&hCryptProv, NULL, NULL,
- PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
- if (pCryptGenRandom(hCryptProv, maxLen, dest)) {
- bytes = maxLen;
- usedWindowsPRNG = PR_TRUE;
- }
- pCryptReleaseContext(hCryptProv, 0);
- }
- if (bytes == 0) {
- bytes = rng_systemFromNoise(dest,maxLen);
- }
-done:
FreeLibrary(hModule);
return bytes;
}
« no previous file with comments | « nss/lib/freebl/unix_rand.c ('k') | patches/nss-rtlgenrandom.patch » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698