diff --git a/crypto/random_pool.c b/crypto/random_pool.c index e7846901da0..d5bdcb56126 100644 --- a/crypto/random_pool.c +++ b/crypto/random_pool.c @@ -559,11 +559,17 @@ void up_randompool_initialize(void) * together. * * Returned Value: - * None + * On success, getrandom() returns the number of bytes that were copied + * to the buffer buf. This may be less than the number of bytes + * requested via buflen if either GRND_RANDOM was specified in flags and + * insufficient entropy was present in the random source or the system + * call was interrupted by a signal. + + * On error, -1 is returned, and errno is set appropriately. * ****************************************************************************/ -void getrandom(FAR void *bytes, size_t nbytes, unsigned int flags) +ssize_t getrandom(FAR void *bytes, size_t nbytes, unsigned int flags) { int ret; @@ -572,5 +578,13 @@ void getrandom(FAR void *bytes, size_t nbytes, unsigned int flags) { rng_buf_internal(bytes, nbytes); nxsem_post(&g_rng.rd_sem); + ret = nbytes; } + else + { + set_errno(-ret); + ret = ERROR; + } + + return ret; } diff --git a/include/sys/random.h b/include/sys/random.h index 4ac586176b9..d394e0f350c 100644 --- a/include/sys/random.h +++ b/include/sys/random.h @@ -48,8 +48,7 @@ * Pre-processor Definitions ****************************************************************************/ -/* - * Flags for getrandom(2) +/* Flags for getrandom(2) * * GRND_NONBLOCK Don't block and return EAGAIN instead * GRND_RANDOM No effect @@ -84,11 +83,17 @@ * together. * * Returned Value: - * None + * On success, getrandom() returns the number of bytes that were copied + * to the buffer buf. This may be less than the number of bytes + * requested via buflen if either GRND_RANDOM was specified in flags and + * insufficient entropy was present in the random source or the system + * call was interrupted by a signal. + * + * On error, -1 is returned, and errno is set appropriately. * ****************************************************************************/ -void getrandom(FAR void *bytes, size_t nbytes, unsigned int flags); +ssize_t getrandom(FAR void *bytes, size_t nbytes, unsigned int flags); #endif /* CONFIG_CRYPTO_RANDOM_POOL */ diff --git a/syscall/syscall.csv b/syscall/syscall.csv index 7d4a401a021..1bade984e07 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -35,7 +35,7 @@ "getitimer","sys/time.h","!defined(CONFIG_DISABLE_POSIX_TIMERS)","int","int","FAR struct itimerval *" "getpeername","sys/socket.h","defined(CONFIG_NET)","int","int","FAR struct sockaddr *","FAR socklen_t *" "getpid","unistd.h","","pid_t" -"getrandom","sys/random.h","defined(CONFIG_CRYPTO_RANDOM_POOL)","void","FAR void *","size_t","unsigned int" +"getrandom","sys/random.h","defined(CONFIG_CRYPTO_RANDOM_POOL)","ssize_t","void","FAR void *","size_t","unsigned int" "getsockname","sys/socket.h","defined(CONFIG_NET)","int","int","FAR struct sockaddr *","FAR socklen_t *" "getsockopt","sys/socket.h","defined(CONFIG_NET)","int","int","int","int","FAR void *","FAR socklen_t *" "getuid","unistd.h","defined(CONFIG_SCHED_USER_IDENTITY)","uid_t"