Skip to content

Commit 16ff016

Browse files
minadsjaeckel
authored andcommitted
win32 rand - just leak the crypt handle
* it will be closed so or so atexit * the user could request more random data in another atexit routine leading to another atexit routine being registered
1 parent 2a2e271 commit 16ff016

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

bn_s_mp_rand_platform.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,18 @@
2626
#include <windows.h>
2727
#include <wincrypt.h>
2828

29-
static HCRYPTPROV hProv = 0;
30-
31-
static void s_cleanup_win_csp(void)
32-
{
33-
CryptReleaseContext(hProv, 0);
34-
hProv = 0;
35-
}
36-
3729
static int s_read_win_csp(void *p, size_t n)
3830
{
31+
static HCRYPTPROV hProv = 0;
3932
if (hProv == 0) {
40-
if (!CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL,
33+
HCRYPTPROV h = 0;
34+
if (!CryptAcquireContext(&h, NULL, MS_DEF_PROV, PROV_RSA_FULL,
4135
(CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET)) &&
42-
!CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL,
36+
!CryptAcquireContext(&h, NULL, MS_DEF_PROV, PROV_RSA_FULL,
4337
CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET | CRYPT_NEWKEYSET)) {
44-
hProv = 0;
4538
return MP_ERR;
4639
}
47-
atexit(s_cleanup_win_csp);
40+
hProc = h;
4841
}
4942
return CryptGenRandom(hProv, (DWORD)n, (BYTE *)p) == TRUE ? MP_OKAY : MP_ERR;
5043
}

0 commit comments

Comments
 (0)