Skip to content

Commit b1aa11d

Browse files
committed
Entropy MemUse: fix for when block size less than update bits
When the block size is less than the number of update bits, adding the update value will make the index larger than ENTROPY_NUM_WORDS. The update bits, ENTROPY_NUM_UPDATES_BITS, should be less than or equal to ENTROPY_BLOCK_SZ but is not practical. Add extra elements to the entropy state to accomadate this.
1 parent 6bf93c9 commit b1aa11d

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

wolfcrypt/src/random.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,8 +1038,14 @@ static void Entropy_StopThread(void)
10381038
#error "ENTROPY_NUM_64BIT_WORDS must be <= SHA3-256 digest size in bytes"
10391039
#endif
10401040

1041+
#if ENTROPY_BLOCK_SZ < ENTROPY_NUM_UPDATES_BITS
1042+
#define EXTRA_ENTROPY_WORDS ENTROPY_NUM_UPDATES
1043+
#else
1044+
#define EXTRA_ENTROPY_WORDS 0
1045+
#endif
1046+
10411047
/* State to update that is multiple cache lines long. */
1042-
static word64 entropy_state[ENTROPY_NUM_WORDS] = {0};
1048+
static word64 entropy_state[ENTROPY_NUM_WORDS + EXTRA_ENTROPY_WORDS] = {0};
10431049

10441050
/* Using memory will take different amount of times depending on the CPU's
10451051
* caches and business.

0 commit comments

Comments
 (0)