mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 11:08:02 -06:00
Windows: Add function RandinitWithCheck to detect if random generator was already initialized before our call or not
This commit is contained in:
@@ -94,14 +94,21 @@ HCRYPTPROV hCryptProv;
|
|||||||
|
|
||||||
|
|
||||||
/* Init the random number generator, setup the hooks, and start the thread */
|
/* Init the random number generator, setup the hooks, and start the thread */
|
||||||
int Randinit ()
|
int RandinitWithCheck ( int* pAlreadyInitialized)
|
||||||
{
|
{
|
||||||
DWORD dwLastError = ERROR_SUCCESS;
|
DWORD dwLastError = ERROR_SUCCESS;
|
||||||
if (GetMaxPkcs5OutSize() > RNG_POOL_SIZE)
|
if (GetMaxPkcs5OutSize() > RNG_POOL_SIZE)
|
||||||
TC_THROW_FATAL_EXCEPTION;
|
TC_THROW_FATAL_EXCEPTION;
|
||||||
|
|
||||||
if(bRandDidInit)
|
if(bRandDidInit)
|
||||||
|
{
|
||||||
|
if (pAlreadyInitialized)
|
||||||
|
*pAlreadyInitialized = 1;
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pAlreadyInitialized)
|
||||||
|
*pAlreadyInitialized = 0;
|
||||||
|
|
||||||
InitializeCriticalSection (&critRandProt);
|
InitializeCriticalSection (&critRandProt);
|
||||||
|
|
||||||
@@ -153,6 +160,11 @@ error:
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Randinit ()
|
||||||
|
{
|
||||||
|
return RandinitWithCheck (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/* Close everything down, including the thread which is closed down by
|
/* Close everything down, including the thread which is closed down by
|
||||||
setting a flag which eventually causes the thread function to exit */
|
setting a flag which eventually causes the thread function to exit */
|
||||||
void RandStop (BOOL freePool)
|
void RandStop (BOOL freePool)
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ extern "C" {
|
|||||||
|
|
||||||
void RandAddInt ( unsigned __int32 x );
|
void RandAddInt ( unsigned __int32 x );
|
||||||
int Randinit ( void );
|
int Randinit ( void );
|
||||||
|
int RandinitWithCheck ( int* pAlreadyInitialized);
|
||||||
void RandStop (BOOL freePool);
|
void RandStop (BOOL freePool);
|
||||||
BOOL IsRandomNumberGeneratorStarted ();
|
BOOL IsRandomNumberGeneratorStarted ();
|
||||||
void RandSetHashFunction ( int hash_algo_id );
|
void RandSetHashFunction ( int hash_algo_id );
|
||||||
|
|||||||
Reference in New Issue
Block a user