feat(newlib): Implement getentropy() function

Closes https://github.com/espressif/esp-idf/issues/11963
This commit is contained in:
Alexey Gerenkov
2023-08-03 16:25:53 +03:00
parent 172f086c6e
commit f8e020b1d7
5 changed files with 58 additions and 4 deletions

View File

@@ -0,0 +1,30 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <sys/random.h>
#include <errno.h>
int getentropy(void *buffer, size_t length)
{
ssize_t ret;
if (buffer == NULL) {
errno = EFAULT;
return -1;
}
if (length > 256) {
errno = EIO;
return -1;
}
ret = getrandom(buffer, length, 0);
if (ret == -1) {
return -1;
}
return 0;
}