1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 11:08:02 -06:00

Windows Setup: correct call to CryptAcquireContext to use memory only container for random generation and remove use of srand/rand (if CryptGenRandom fails which is very unlikely, we just use one color).

This commit is contained in:
Mounir IDRASSI
2016-09-26 13:42:02 +02:00
parent 3c09765208
commit f40755fd7c

View File

@@ -180,15 +180,11 @@ static int GetDonVal (int minVal, int maxVal)
if (!prngInitialized)
{
if (!CryptAcquireContext (&hCryptProv, NULL, NULL, PROV_RSA_FULL, 0)
&& !CryptAcquireContext (&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET))
if (!CryptAcquireContext (&hCryptProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
OsPrngAvailable = FALSE;
else
OsPrngAvailable = TRUE;
srand ((unsigned int) time (NULL));
rand(); // Generate and discard the inital value, as it always appears to be somewhat non-random.
prngInitialized = TRUE;
}
@@ -197,7 +193,7 @@ static int GetDonVal (int minVal, int maxVal)
return ((int) ((double) *((uint16 *) buffer) / (0xFFFF+1) * (maxVal + 1 - minVal)) + minVal);
}
else
return ((int) ((double) rand() / (RAND_MAX+1) * (maxVal + 1 - minVal)) + minVal);
return maxVal;
}