summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWan-Teh Chang <wtc@google.com>2013-06-17 18:57:01 -0700
committerWan-Teh Chang <wtc@google.com>2013-06-17 18:57:01 -0700
commit8ffc29305842691f84693832585a6e1c5568ad2d (patch)
tree33f5aa02242d8921f5a068078f557aef6f5c1a26
parenta435a679671e58ba293a0357fcca021f6999015f (diff)
downloadnss-hg-8ffc29305842691f84693832585a6e1c5568ad2d.tar.gz
Bug 882829: RNG_SystemRNG should fail rather than falling back onNSS_3_15_1_BETA2
rng_systemFromNoise if it cannot call RtlGenRandom on Windows. Remove the obsolete code for Windows versions older than Windows XP. r=sleevi.
-rw-r--r--lib/freebl/win_rand.c73
1 files changed, 4 insertions, 69 deletions
diff --git a/lib/freebl/win_rand.c b/lib/freebl/win_rand.c
index 0100ac446..2ddac8d75 100644
--- a/lib/freebl/win_rand.c
+++ b/lib/freebl/win_rand.c
@@ -367,40 +367,6 @@ void RNG_FileForRNG(const char *filename)
/*
- * 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 @@ size_t RNG_SystemRNG(void *dest, size_t maxLen)
{
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;
- }
- 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);
+ if (pRtlGenRandom && pRtlGenRandom(dest, maxLen)) {
+ bytes = maxLen;
+ usedWindowsPRNG = PR_TRUE;
}
-done:
FreeLibrary(hModule);
return bytes;
}