Minor fix in liboqs GetRandomData

Fixes F-4443
This commit is contained in:
Tobias Frauenschläger
2026-06-08 08:19:13 +02:00
parent 9c60d87abc
commit c01152d35a
+12 -1
View File
@@ -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;
}
}