forked from wolfSSL/wolfssl
ssl: refactoring CyaSSL_RAND_bytes to reduce stack usage:
--- variable tmpRNG moved to the heap (sizeof(RNG) saved)
This commit is contained in:
38
src/ssl.c
38
src/ssl.c
@@ -9930,25 +9930,35 @@ int CyaSSL_RAND_seed(const void* seed, int len)
|
|||||||
/* SSL_SUCCESS on ok */
|
/* SSL_SUCCESS on ok */
|
||||||
int CyaSSL_RAND_bytes(unsigned char* buf, int num)
|
int CyaSSL_RAND_bytes(unsigned char* buf, int num)
|
||||||
{
|
{
|
||||||
RNG tmpRNG;
|
int ret = 0;
|
||||||
RNG* rng = &tmpRNG;
|
RNG* rng = NULL;
|
||||||
|
#ifdef CYASSL_SMALL_STACK
|
||||||
|
RNG* tmpRNG = NULL;
|
||||||
|
#else
|
||||||
|
RNG tmpRNG[1];
|
||||||
|
#endif
|
||||||
|
|
||||||
CYASSL_ENTER("RAND_bytes");
|
CYASSL_ENTER("RAND_bytes");
|
||||||
if (InitRng(&tmpRNG) != 0) {
|
|
||||||
CYASSL_MSG("Bad RNG Init, trying global");
|
#ifdef CYASSL_SMALL_STACK
|
||||||
if (initGlobalRNG == 0) {
|
tmpRNG = (RNG*)XMALLOC(sizeof(RNG), NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
CYASSL_MSG("Global RNG no Init");
|
if (tmpRNG == NULL)
|
||||||
return 0;
|
return ret;
|
||||||
}
|
#endif
|
||||||
|
|
||||||
|
if (InitRng(tmpRNG) == 0)
|
||||||
|
rng = tmpRNG;
|
||||||
|
else if (initGlobalRNG)
|
||||||
rng = &globalRNG;
|
rng = &globalRNG;
|
||||||
}
|
|
||||||
|
|
||||||
if (RNG_GenerateBlock(rng, buf, num) != 0) {
|
if (rng) {
|
||||||
CYASSL_MSG("Bad RNG_GenerateBlock");
|
if (RNG_GenerateBlock(rng, buf, num) != 0)
|
||||||
return 0;
|
CYASSL_MSG("Bad RNG_GenerateBlock");
|
||||||
}
|
else
|
||||||
|
ret = SSL_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
return SSL_SUCCESS;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
CYASSL_BN_CTX* CyaSSL_BN_CTX_new(void)
|
CYASSL_BN_CTX* CyaSSL_BN_CTX_new(void)
|
||||||
|
Reference in New Issue
Block a user