OLD | NEW |
| (Empty) |
1 diff --git a/lib/freebl/win_rand.c b/lib/freebl/win_rand.c | |
2 --- a/lib/freebl/win_rand.c | |
3 +++ b/lib/freebl/win_rand.c | |
4 @@ -362,102 +362,37 @@ void RNG_FileForRNG(const char *filename | |
5 } | |
6 | |
7 nBytes = RNG_GetNoise(buffer, 20); // get up to 20 bytes | |
8 RNG_RandomUpdate(buffer, nBytes); | |
9 } | |
10 | |
11 | |
12 /* | |
13 - * CryptoAPI requires Windows NT 4.0 or Windows 95 OSR2 and later. | |
14 - * Until we drop support for Windows 95, we need to emulate some | |
15 - * definitions and declarations in <wincrypt.h> and look up the | |
16 - * functions in advapi32.dll at run time. | |
17 - */ | |
18 - | |
19 -#ifndef WIN64 | |
20 -typedef unsigned long HCRYPTPROV; | |
21 -#endif | |
22 - | |
23 -#define CRYPT_VERIFYCONTEXT 0xF0000000 | |
24 - | |
25 -#define PROV_RSA_FULL 1 | |
26 - | |
27 -typedef BOOL | |
28 -(WINAPI *CryptAcquireContextAFn)( | |
29 - HCRYPTPROV *phProv, | |
30 - LPCSTR pszContainer, | |
31 - LPCSTR pszProvider, | |
32 - DWORD dwProvType, | |
33 - DWORD dwFlags); | |
34 - | |
35 -typedef BOOL | |
36 -(WINAPI *CryptReleaseContextFn)( | |
37 - HCRYPTPROV hProv, | |
38 - DWORD dwFlags); | |
39 - | |
40 -typedef BOOL | |
41 -(WINAPI *CryptGenRandomFn)( | |
42 - HCRYPTPROV hProv, | |
43 - DWORD dwLen, | |
44 - BYTE *pbBuffer); | |
45 - | |
46 -/* | |
47 * Windows XP and Windows Server 2003 and later have RtlGenRandom, | |
48 * which must be looked up by the name SystemFunction036. | |
49 */ | |
50 typedef BOOLEAN | |
51 (APIENTRY *RtlGenRandomFn)( | |
52 PVOID RandomBuffer, | |
53 ULONG RandomBufferLength); | |
54 | |
55 size_t RNG_SystemRNG(void *dest, size_t maxLen) | |
56 { | |
57 HMODULE hModule; | |
58 RtlGenRandomFn pRtlGenRandom; | |
59 - CryptAcquireContextAFn pCryptAcquireContextA; | |
60 - CryptReleaseContextFn pCryptReleaseContext; | |
61 - CryptGenRandomFn pCryptGenRandom; | |
62 - HCRYPTPROV hCryptProv; | |
63 size_t bytes = 0; | |
64 | |
65 usedWindowsPRNG = PR_FALSE; | |
66 hModule = LoadLibrary("advapi32.dll"); | |
67 if (hModule == NULL) { | |
68 - return rng_systemFromNoise(dest,maxLen); | |
69 + return bytes; | |
70 } | |
71 pRtlGenRandom = (RtlGenRandomFn) | |
72 GetProcAddress(hModule, "SystemFunction036"); | |
73 - if (pRtlGenRandom) { | |
74 - if (pRtlGenRandom(dest, maxLen)) { | |
75 - bytes = maxLen; | |
76 - usedWindowsPRNG = PR_TRUE; | |
77 - } else { | |
78 - bytes = rng_systemFromNoise(dest,maxLen); | |
79 - } | |
80 - goto done; | |
81 + if (pRtlGenRandom && pRtlGenRandom(dest, maxLen)) { | |
82 + bytes = maxLen; | |
83 + usedWindowsPRNG = PR_TRUE; | |
84 } | |
85 - pCryptAcquireContextA = (CryptAcquireContextAFn) | |
86 - GetProcAddress(hModule, "CryptAcquireContextA"); | |
87 - pCryptReleaseContext = (CryptReleaseContextFn) | |
88 - GetProcAddress(hModule, "CryptReleaseContext"); | |
89 - pCryptGenRandom = (CryptGenRandomFn) | |
90 - GetProcAddress(hModule, "CryptGenRandom"); | |
91 - if (!pCryptAcquireContextA || !pCryptReleaseContext || !pCryptGenRandom) { | |
92 - bytes = rng_systemFromNoise(dest,maxLen); | |
93 - goto done; | |
94 - } | |
95 - if (pCryptAcquireContextA(&hCryptProv, NULL, NULL, | |
96 - PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { | |
97 - if (pCryptGenRandom(hCryptProv, maxLen, dest)) { | |
98 - bytes = maxLen; | |
99 - usedWindowsPRNG = PR_TRUE; | |
100 - } | |
101 - pCryptReleaseContext(hCryptProv, 0); | |
102 - } | |
103 - if (bytes == 0) { | |
104 - bytes = rng_systemFromNoise(dest,maxLen); | |
105 - } | |
106 -done: | |
107 FreeLibrary(hModule); | |
108 return bytes; | |
109 } | |
110 #endif /* is XP_WIN */ | |
OLD | NEW |