Fix return value of w32crypto_bytes() and use correct data types

This commit is contained in:
Asanka Herath
2010-05-26 10:03:03 -04:00
parent e7337145ee
commit 7b8ebf0efe

View File

@@ -48,25 +48,25 @@ volatile static HCRYPTPROV g_cryptprovider = 0;
static HCRYPTPROV static HCRYPTPROV
_hc_CryptProvider(void) _hc_CryptProvider(void)
{ {
BOOL res; BOOL rv;
HCRYPTPROV cryptprovider = 0; HCRYPTPROV cryptprovider = 0;
if (g_cryptprovider != 0) if (g_cryptprovider != 0)
return g_cryptprovider; return g_cryptprovider;
res = CryptAcquireContext(&cryptprovider, NULL, rv = CryptAcquireContext(&cryptprovider, NULL,
MS_ENHANCED_PROV, PROV_RSA_FULL, MS_ENHANCED_PROV, PROV_RSA_FULL,
0); 0);
if (GetLastError() == NTE_BAD_KEYSET) { if (GetLastError() == NTE_BAD_KEYSET) {
if(!res) if(!rv)
res = CryptAcquireContext(&cryptprovider, NULL, rv = CryptAcquireContext(&cryptprovider, NULL,
MS_ENHANCED_PROV, PROV_RSA_FULL, MS_ENHANCED_PROV, PROV_RSA_FULL,
CRYPT_NEWKEYSET); CRYPT_NEWKEYSET);
} }
if (res && if (rv &&
InterlockedCompareExchange(&g_cryptprovider, cryptprovider, 0) != 0) { InterlockedCompareExchangePointer(&g_cryptprovider, cryptprovider, 0) != 0) {
CryptReleaseContext(cryptprovider, 0); CryptReleaseContext(cryptprovider, 0);
cryptprovider = g_cryptprovider; cryptprovider = g_cryptprovider;
@@ -90,8 +90,8 @@ static int
w32crypto_bytes(unsigned char *outdata, int size) w32crypto_bytes(unsigned char *outdata, int size)
{ {
if (CryptGenRandom(_hc_CryptProvider(), size, outdata)) if (CryptGenRandom(_hc_CryptProvider(), size, outdata))
return 0; return 1;
return 1; return 0;
} }
static void static void