diff --git a/crypto/random_pool.c b/crypto/random_pool.c index 0794105c152..7fdf7d0ded7 100644 --- a/crypto/random_pool.c +++ b/crypto/random_pool.c @@ -542,7 +542,7 @@ void up_randompool_initialize(void) } /**************************************************************************** - * Name: getrandom + * Name: arc4random_buf * * Description: * Fill a buffer of arbitrary length with randomness. This is the @@ -561,7 +561,7 @@ void up_randompool_initialize(void) * ****************************************************************************/ -void getrandom(FAR void *bytes, size_t nbytes) +void arc4random_buf(FAR void *bytes, size_t nbytes) { int ret; diff --git a/drivers/crypto/dev_urandom.c b/drivers/crypto/dev_urandom.c index 106f7ad527c..0ec2c91de8d 100644 --- a/drivers/crypto/dev_urandom.c +++ b/drivers/crypto/dev_urandom.c @@ -165,7 +165,7 @@ static ssize_t devurand_read(FAR struct file *filep, FAR char *buffer, #ifdef CONFIG_DEV_URANDOM_RANDOM_POOL if (len > 0) { - getrandom(buffer, len); + arc4random_buf(buffer, len); } #else diff --git a/include/nuttx/random.h b/include/nuttx/random.h index a2fee4f4da8..640274959e5 100644 --- a/include/nuttx/random.h +++ b/include/nuttx/random.h @@ -44,8 +44,6 @@ #include #include -#include /* getrandom() */ - /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -98,7 +96,8 @@ enum rnd_source_t #ifdef CONFIG_BOARD_ENTROPY_POOL /* Entropy pool structure can be provided by board source. Use for this is, * for example, allocate entropy pool from special area of RAM which content - * is kept over system reset. */ + * is kept over system reset. + */ extern struct entropy_pool_s board_entropy_pool; #endif diff --git a/include/stdlib.h b/include/stdlib.h index 3eaf0e282ce..740bd06f274 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -121,6 +121,10 @@ int rand(void); #define srandom(s) srand(s) long random(void); +#ifdef CONFIG_CRYPTO_RANDOM_POOL +void arc4random_buf(FAR void *bytes, size_t nbytes); +#endif + /* Environment variable support */ FAR char **get_environ_ptr(void); diff --git a/include/sys/random.h b/include/sys/random.h deleted file mode 100644 index 65a224d0ec2..00000000000 --- a/include/sys/random.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** - * include/sys/random.h - * - * Copyright (C) 2015-2017 Haltian Ltd. All rights reserved. - * Authors: Juha Niskanen - * Jussi Kivilinna - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __INCLUDE_SYS_RANDOM_H -#define __INCLUDE_SYS_RANDOM_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef CONFIG_CRYPTO_RANDOM_POOL - -/**************************************************************************** - * Name: getrandom - * - * Description: - * Fill a buffer of arbitrary length with randomness. This is the - * preferred interface for getting random numbers. The traditional - * /dev/random approach is susceptible for things like the attacker - * exhausting file descriptors on purpose. - * - * Note that this function cannot fail, other than by asserting. - * - * Input Parameters: - * bytes - Buffer for returned random bytes - * nbytes - Number of bytes requested. - * - * Returned Value: - * None - * - ****************************************************************************/ - -void getrandom(FAR void *bytes, size_t nbytes); - -#endif /* CONFIG_CRYPTO_RANDOM_POOL */ - -#endif /* __INCLUDE_SYS_RANDOM_H */ diff --git a/include/sys/syscall_lookup.h b/include/sys/syscall_lookup.h index 235f3068b79..1b3b3727a8f 100644 --- a/include/sys/syscall_lookup.h +++ b/include/sys/syscall_lookup.h @@ -382,5 +382,5 @@ SYSCALL_LOOKUP(telldir, 1) */ #ifdef CONFIG_CRYPTO_RANDOM_POOL - SYSCALL_LOOKUP(getrandom, 2) + SYSCALL_LOOKUP(arc4random_buf, 2) #endif diff --git a/libs/libc/uuid/lib_uuid_create.c b/libs/libc/uuid/lib_uuid_create.c index 29b415f76b4..d2af6e0ca0f 100644 --- a/libs/libc/uuid/lib_uuid_create.c +++ b/libs/libc/uuid/lib_uuid_create.c @@ -22,7 +22,6 @@ * Included Files ****************************************************************************/ -#include #include #include @@ -44,7 +43,7 @@ void uuid_create(uuid_t *u, uint32_t *status) { #ifdef CONFIG_CRYPTO_RANDOM_POOL - getrandom(u, sizeof(uuid_t)); + arc4random_buf(u, sizeof(uuid_t)); #else unsigned long *beg = (unsigned long *)u; unsigned long *end = (unsigned long *)(u + 1); diff --git a/syscall/syscall.csv b/syscall/syscall.csv index 7b727adcf1d..674621c4448 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" +"arc4random_buf","stdlib.h","defined(CONFIG_CRYPTO_RANDOM_POOL)","void","FAR void *","size_t" "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"