Skip to content

Commit 1e38a10

Browse files
committed
wolfcrypt/src/wolfentropy.c: in wc_Entropy_Get():
* use a bss segment allocation for noise, to avoid a heap allocation (access is already mutex-protected), and * in the loop, WC_CHECK_FOR_INTR_SIGNALS() and WC_RELAX_LONG_LOOP().
1 parent 38b675e commit 1e38a10

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

wolfcrypt/src/wolfentropy.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -735,13 +735,10 @@ static wolfSSL_Mutex entropy_mutex WOLFSSL_MUTEX_INITIALIZER_CLAUSE(entropy_mute
735735
int wc_Entropy_Get(int bits, unsigned char* entropy, word32 len)
736736
{
737737
int ret = 0;
738-
WC_DECLARE_VAR(noise, byte, MAX_NOISE_CNT, 0);
739738
/* Noise length is the number of 8 byte samples required to get the bits of
740739
* entropy requested. */
741740
int noise_len = (bits + ENTROPY_EXTRA) / ENTROPY_MIN;
742-
743-
WC_ALLOC_VAR_EX(noise, byte, MAX_NOISE_CNT, NULL, DYNAMIC_TYPE_TMP_BUFFER,
744-
return MEMORY_E);
741+
static byte noise[MAX_NOISE_CNT];
745742

746743
/* Lock the mutex as collection uses globals. */
747744
if ((ret == 0) && (wc_LockMutex(&entropy_mutex) != 0)) {
@@ -790,6 +787,12 @@ int wc_Entropy_Get(int bits, unsigned char* entropy, word32 len)
790787
entropy += entropy_len;
791788
len -= entropy_len;
792789
}
790+
if (ret == 0) {
791+
ret = WC_CHECK_FOR_INTR_SIGNALS();
792+
}
793+
if (ret == 0) {
794+
WC_RELAX_LONG_LOOP();
795+
}
793796
}
794797

795798
#ifdef ENTROPY_MEMUSE_THREADED
@@ -802,8 +805,6 @@ int wc_Entropy_Get(int bits, unsigned char* entropy, word32 len)
802805
wc_UnLockMutex(&entropy_mutex);
803806
}
804807

805-
WC_FREE_VAR_EX(noise, NULL, DYNAMIC_TYPE_TMP_BUFFER);
806-
807808
return ret;
808809
}
809810

0 commit comments

Comments
 (0)