summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-01-28 12:23:10 +0000
committerLeah Rowe <leah@libreboot.org>2023-01-28 12:24:50 +0000
commitc822033beedc7765947f5e9332ee842778c5a7fb (patch)
tree8b41f454714024bdab2adb827012a00b06204400 /util
parent0f4852450caaee38ccfde2dc1727b0c6cf5f9fbd (diff)
util/nvmutil: simplify rhex()
don't use malloc(). instead, just load random bytes into a uint64_t
Diffstat (limited to 'util')
-rw-r--r--util/nvmutil/nvmutil.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index bc5859f..e7c9f15 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -256,22 +256,19 @@ uint8_t
rhex(void)
{
static int rfd = -1;
- static uint8_t *rbuf = NULL;
- static size_t rindex = 12;
+ static uint64_t rnum = 0;
+ static size_t rindex = 8;
- if (rindex == 12) {
+ if (rindex == 8) {
rindex = 0;
- if (rbuf == NULL)
- if ((rbuf = (uint8_t *) malloc(BUFSIZ)) == NULL)
- err(errno, NULL);
if (rfd == -1)
if ((rfd = open("/dev/urandom", O_RDONLY)) == -1)
err(errno, "/dev/urandom");
- if (read(rfd, rbuf, 12) == -1)
+ if (read(rfd, (uint8_t *) &rnum, 8) == -1)
err(errno, "/dev/urandom");
}
- return rbuf[rindex++] & 0xf;
+ return ((uint8_t *) &rnum)[rindex++] & 0xf;
}
void