You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2020/12/13 14:50:00 UTC
[incubator-nuttx] 01/02: crypto/arc4random: rename getrandom to
arc4random_buf
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 859e1ce63a458b206623d8e41cd93588af61b62f
Author: chao.an <an...@xiaomi.com>
AuthorDate: Sat Dec 12 14:16:07 2020 +0800
crypto/arc4random: rename getrandom to arc4random_buf
Change-Id: I5c9f0c9acf5af71f01beceaf06ebe0a2c87676bc
Signed-off-by: chao.an <an...@xiaomi.com>
---
crypto/random_pool.c | 4 +--
drivers/crypto/dev_urandom.c | 2 +-
include/nuttx/random.h | 5 ++-
include/stdlib.h | 4 +++
include/sys/random.h | 77 ----------------------------------------
include/sys/syscall_lookup.h | 2 +-
libs/libc/uuid/lib_uuid_create.c | 3 +-
syscall/syscall.csv | 2 +-
8 files changed, 12 insertions(+), 87 deletions(-)
diff --git a/crypto/random_pool.c b/crypto/random_pool.c
index 0794105..7fdf7d0 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 106f7ad..0ec2c91 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 a2fee4f..6402749 100644
--- a/include/nuttx/random.h
+++ b/include/nuttx/random.h
@@ -44,8 +44,6 @@
#include <nuttx/config.h>
#include <stddef.h>
-#include <sys/random.h> /* 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 3eaf0e2..740bd06 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 65a224d..0000000
--- 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 <ju...@haltian.com>
- * Jussi Kivilinna <ju...@haltian.com>
- *
- * 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 <nuttx/config.h>
-#include <stddef.h>
-
-/****************************************************************************
- * 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 235f306..1b3b372 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 29b415f..d2af6e0 100644
--- a/libs/libc/uuid/lib_uuid_create.c
+++ b/libs/libc/uuid/lib_uuid_create.c
@@ -22,7 +22,6 @@
* Included Files
****************************************************************************/
-#include <sys/random.h>
#include <stdlib.h>
#include <uuid.h>
@@ -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 7b727ad..674621c 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"