From 1298f83aa49948962b57dc302cc868130b60c0b5 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Thu, 3 Oct 2019 19:25:57 +0200 Subject: [PATCH] Windows: Add function RandinitWithCheck to detect if random generator was already initialized before our call or not --- src/Common/Random.c | 14 +++++++++++++- src/Common/Random.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Common/Random.c b/src/Common/Random.c index a2da77f8..09c55bf3 100644 --- a/src/Common/Random.c +++ b/src/Common/Random.c @@ -94,14 +94,21 @@ HCRYPTPROV hCryptProv; /* Init the random number generator, setup the hooks, and start the thread */ -int Randinit () +int RandinitWithCheck ( int* pAlreadyInitialized) { DWORD dwLastError = ERROR_SUCCESS; if (GetMaxPkcs5OutSize() > RNG_POOL_SIZE) TC_THROW_FATAL_EXCEPTION; if(bRandDidInit) + { + if (pAlreadyInitialized) + *pAlreadyInitialized = 1; return 0; + } + + if (pAlreadyInitialized) + *pAlreadyInitialized = 0; InitializeCriticalSection (&critRandProt); @@ -153,6 +160,11 @@ int Randinit () return 1; } +int Randinit () +{ + return RandinitWithCheck (NULL); +} + /* Close everything down, including the thread which is closed down by setting a flag which eventually causes the thread function to exit */ void RandStop (BOOL freePool) diff --git a/src/Common/Random.h b/src/Common/Random.h index 46fe59a8..88dd041b 100644 --- a/src/Common/Random.h +++ b/src/Common/Random.h @@ -35,6 +35,7 @@ extern "C" { void RandAddInt ( unsigned __int32 x ); int Randinit ( void ); +int RandinitWithCheck ( int* pAlreadyInitialized); void RandStop (BOOL freePool); BOOL IsRandomNumberGeneratorStarted (); void RandSetHashFunction ( int hash_algo_id );