forked from wolfSSL/wolfssl
Protect use of globalRNG
This commit is contained in:
14
src/ssl.c
14
src/ssl.c
@ -30943,6 +30943,7 @@ int wolfSSL_RAND_bytes(unsigned char* buf, int num)
|
|||||||
#else
|
#else
|
||||||
WC_RNG tmpRNG[1];
|
WC_RNG tmpRNG[1];
|
||||||
#endif
|
#endif
|
||||||
|
int used_global = 0;
|
||||||
|
|
||||||
WOLFSSL_ENTER("wolfSSL_RAND_bytes");
|
WOLFSSL_ENTER("wolfSSL_RAND_bytes");
|
||||||
|
|
||||||
@ -30952,8 +30953,15 @@ int wolfSSL_RAND_bytes(unsigned char* buf, int num)
|
|||||||
return ret;
|
return ret;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (initGlobalRNG)
|
if (initGlobalRNG) {
|
||||||
|
if (wc_LockMutex(&globalRNGMutex) != 0) {
|
||||||
|
WOLFSSL_MSG("Bad Lock Mutex rng");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
rng = &globalRNG;
|
rng = &globalRNG;
|
||||||
|
used_global = 1;
|
||||||
|
}
|
||||||
else if(wc_InitRng(tmpRNG) == 0) {
|
else if(wc_InitRng(tmpRNG) == 0) {
|
||||||
rng = tmpRNG;
|
rng = tmpRNG;
|
||||||
initTmpRng = 1;
|
initTmpRng = 1;
|
||||||
@ -30965,6 +30973,10 @@ int wolfSSL_RAND_bytes(unsigned char* buf, int num)
|
|||||||
ret = WOLFSSL_SUCCESS;
|
ret = WOLFSSL_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (used_global == 1) {
|
||||||
|
wc_UnLockMutex(&globalRNGMutex);
|
||||||
|
}
|
||||||
|
|
||||||
if (initTmpRng)
|
if (initTmpRng)
|
||||||
wc_FreeRng(tmpRNG);
|
wc_FreeRng(tmpRNG);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user