mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-07-05 14:00:48 +02:00
Minor fix in liboqs GetRandomData
Fixes F-4443
This commit is contained in:
@@ -49,7 +49,14 @@ static void wolfSSL_liboqsGetRandomData(uint8_t* buffer, size_t numOfBytes)
|
||||
|
||||
while (numOfBytes > 0) {
|
||||
numOfBytes_word32 = (word32)numOfBytes;
|
||||
numOfBytes -= numOfBytes_word32;
|
||||
/* On platforms where size_t is wider than word32, the cast above can
|
||||
* truncate. If numOfBytes does not fit into a word32 (including the
|
||||
* case where it is an exact multiple of 2^32 and truncates to 0),
|
||||
* generate the largest chunk that fits to guarantee forward progress
|
||||
* and avoid an infinite loop. */
|
||||
if ((size_t)numOfBytes_word32 != numOfBytes) {
|
||||
numOfBytes_word32 = 0xFFFFFFFFU;
|
||||
}
|
||||
ret = wc_RNG_GenerateBlock(liboqsCurrentRNG, buffer,
|
||||
numOfBytes_word32);
|
||||
if (ret != 0) {
|
||||
@@ -62,6 +69,10 @@ static void wolfSSL_liboqsGetRandomData(uint8_t* buffer, size_t numOfBytes)
|
||||
);
|
||||
abort();
|
||||
}
|
||||
/* Advance the buffer so subsequent iterations append rather than
|
||||
* overwrite the previously generated bytes. */
|
||||
buffer += numOfBytes_word32;
|
||||
numOfBytes -= numOfBytes_word32;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user