forked from espressif/esp-idf
Merge branch 'bugfix/get_random_inside_assert' into 'master'
fix(linux): calling getrandom() outside assert() See merge request espressif/esp-idf!30517
This commit is contained in:
@@ -17,13 +17,16 @@ static void __attribute__((constructor)) esp_random_init(void) { }
|
|||||||
uint32_t esp_random(void)
|
uint32_t esp_random(void)
|
||||||
{
|
{
|
||||||
uint32_t random_number;
|
uint32_t random_number;
|
||||||
assert(getentropy(&random_number, sizeof(random_number)) == 0);
|
int result = getentropy(&random_number, sizeof(random_number));
|
||||||
|
assert(result == 0);
|
||||||
|
(void)result;
|
||||||
return random_number;
|
return random_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
void esp_fill_random(void *buf, size_t len)
|
void esp_fill_random(void *buf, size_t len)
|
||||||
{
|
{
|
||||||
assert(buf != NULL);
|
assert(buf != NULL);
|
||||||
|
int result;
|
||||||
|
|
||||||
// Note that we can't use getentropy() with len > 256 directly (see getentropy man page),
|
// Note that we can't use getentropy() with len > 256 directly (see getentropy man page),
|
||||||
// hence reading in chunks
|
// hence reading in chunks
|
||||||
@@ -31,8 +34,12 @@ void esp_fill_random(void *buf, size_t len)
|
|||||||
const size_t REST_CHUNK_SIZE = len % GETENTROPY_MAX_LEN;
|
const size_t REST_CHUNK_SIZE = len % GETENTROPY_MAX_LEN;
|
||||||
|
|
||||||
for (size_t chunk_num = 0; chunk_num < FULL_CHUNKS_NUM; chunk_num++) {
|
for (size_t chunk_num = 0; chunk_num < FULL_CHUNKS_NUM; chunk_num++) {
|
||||||
assert(getentropy(buf + chunk_num * GETENTROPY_MAX_LEN, GETENTROPY_MAX_LEN) == 0);
|
result = getentropy(buf + chunk_num * GETENTROPY_MAX_LEN, GETENTROPY_MAX_LEN);
|
||||||
|
assert(result == 0);
|
||||||
|
(void)result;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(getentropy(buf + FULL_CHUNKS_NUM * GETENTROPY_MAX_LEN, REST_CHUNK_SIZE) == 0);
|
result = getentropy(buf + FULL_CHUNKS_NUM * GETENTROPY_MAX_LEN, REST_CHUNK_SIZE);
|
||||||
|
assert(result == 0);
|
||||||
|
(void)result;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user