Skip to content

Commit f8341ab

Browse files
xiaoxiang781216GUIDINGLI
authored andcommitted
Replace getrandom with arc4random_buf to simplify the usage
and follow the kernel side change: apache/nuttx#14509 Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
1 parent e8497e5 commit f8341ab

File tree

2 files changed

+2
-26
lines changed

2 files changed

+2
-26
lines changed

fsutils/mkgpt/mkgpt.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <string.h>
3333
#include <debug.h>
3434

35-
#include <sys/random.h>
3635
#include <sys/stat.h>
3736
#include <sys/ioctl.h>
3837

@@ -130,13 +129,7 @@ static const uint8_t g_partition_type_swap[16] =
130129

131130
static void get_uuid(FAR uint8_t *uuid)
132131
{
133-
/* call getrandom to read /dev/urandom */
134-
135-
if (getrandom(uuid, 16, 0) < 0)
136-
{
137-
fprintf(stderr, "error read primary partition table\n");
138-
return;
139-
}
132+
arc4random_buf(uuid, 16);
140133
}
141134

142135
static void init_mbr(FAR uint8_t *mbr, uint32_t blocks)

netutils/dhcpc/dhcpc.c

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
#include <sys/types.h>
4545
#include <sys/socket.h>
4646
#include <sys/time.h>
47-
#include <sys/random.h>
4847

4948
#include <inttypes.h>
5049
#include <stdlib.h>
@@ -520,10 +519,6 @@ FAR void *dhcpc_open(FAR const char *interface, FAR const void *macaddr,
520519
struct sockaddr_in addr;
521520
struct timeval tv;
522521
int ret;
523-
const uint8_t default_xid[4] =
524-
{
525-
0xad, 0xde, 0x12, 0x23
526-
};
527522

528523
ninfo("MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
529524
((uint8_t *)macaddr)[0], ((uint8_t *)macaddr)[1],
@@ -544,19 +539,7 @@ FAR void *dhcpc_open(FAR const char *interface, FAR const void *macaddr,
544539
* used by another client.
545540
*/
546541

547-
#if defined(CONFIG_DEV_URANDOM) || defined(CONFIG_DEV_RANDOM)
548-
ret = getrandom(pdhcpc->xid, 4, 0);
549-
if (ret != 4)
550-
{
551-
ret = getrandom(pdhcpc->xid, 4, GRND_RANDOM);
552-
if (ret != 4)
553-
{
554-
memcpy(pdhcpc->xid, default_xid, 4);
555-
}
556-
}
557-
#else
558-
memcpy(pdhcpc->xid, default_xid, 4);
559-
#endif
542+
arc4random_buf(pdhcpc->xid, 4);
560543

561544
pdhcpc->interface = interface;
562545
pdhcpc->maclen = maclen;

0 commit comments

Comments
 (0)