Skip to content

Commit

Permalink
Replace getrandom with arc4random_buf to simplify the usage
Browse files Browse the repository at this point in the history
and follow the kernel side change:
apache/nuttx#14509

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
  • Loading branch information
xiaoxiang781216 committed Oct 25, 2024
1 parent 729cc33 commit 82983f6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
8 changes: 1 addition & 7 deletions fsutils/mkgpt/mkgpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,7 @@ static const uint8_t g_partition_type_swap[16] =

static void get_uuid(FAR uint8_t *uuid)
{
/* call getrandom to read /dev/urandom */

if (getrandom(uuid, 16, 0) < 0)
{
fprintf(stderr, "error read primary partition table\n");
return;
}
arc4random_buf(uuid, 16);
}

static void init_mbr(FAR uint8_t *mbr, uint32_t blocks)
Expand Down
18 changes: 1 addition & 17 deletions netutils/dhcpc/dhcpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,6 @@ FAR void *dhcpc_open(FAR const char *interface, FAR const void *macaddr,
struct sockaddr_in addr;
struct timeval tv;
int ret;
const uint8_t default_xid[4] =
{
0xad, 0xde, 0x12, 0x23
};

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

#if defined(CONFIG_DEV_URANDOM) || defined(CONFIG_DEV_RANDOM)
ret = getrandom(pdhcpc->xid, 4, 0);
if (ret != 4)
{
ret = getrandom(pdhcpc->xid, 4, GRND_RANDOM);
if (ret != 4)
{
memcpy(pdhcpc->xid, default_xid, 4);
}
}
#else
memcpy(pdhcpc->xid, default_xid, 4);
#endif
arc4random_buf(pdhcpc->xid, 4);

pdhcpc->interface = interface;
pdhcpc->maclen = maclen;
Expand Down

0 comments on commit 82983f6

Please sign in to comment.