summaryrefslogtreecommitdiff
path: root/util/libreboot-utils/lib/rand.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/libreboot-utils/lib/rand.c')
-rw-r--r--util/libreboot-utils/lib/rand.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/util/libreboot-utils/lib/rand.c b/util/libreboot-utils/lib/rand.c
index 02353560..bf090b43 100644
--- a/util/libreboot-utils/lib/rand.c
+++ b/util/libreboot-utils/lib/rand.c
@@ -4,9 +4,6 @@
* Random number generation
*/
-#ifndef RAND_H
-#define RAND_H
-
#if defined(USE_ARC4) && \
((USE_ARC4) > 0)
#define _DEFAULT_SOURCE 1 /* for arc4random on *linux* */
@@ -159,37 +156,37 @@ retry_rand: {
#if defined(USE_URANDOM) && \
((USE_URANDOM) > 0)
- ssize_t rc;
+ ssize_t rval;
int fd = -1;
open_file_on_eintr("/dev/urandom", &fd, O_RDONLY, 0400, NULL);
while (rw_retry(saved_errno,
- rc = rw(fd, (unsigned char *)buf + off, n - off, 0, IO_READ)));
+ rval = rw(fd, (unsigned char *)buf + off, n - off, 0, IO_READ)));
#elif defined(__linux__)
- long rc;
+ long rval;
while (sys_retry(saved_errno,
- rc = syscall(SYS_getrandom,
+ rval = syscall(SYS_getrandom,
(unsigned char *)buf + off, n - off, 0)));
#else
#error Unsupported operating system (possibly unsecure randomisation)
#endif
- if (rc < 0 || /* syscall fehler */
- rc == 0) { /* prevent infinite loop on fatal err */
+ if (rval < 0 || /* syscall fehler */
+ rval == 0) { /* prevent infinite loop on fatal err */
#if defined(USE_URANDOM) && \
((USE_URANDOM) > 0)
- close_on_eintr(&fd);
+ xclose(&fd);
#endif
goto err;
}
- if ((off += (size_t)rc) < n)
+ if ((off += (size_t)rval) < n)
goto retry_rand;
#if defined(USE_URANDOM) && \
((USE_URANDOM) > 0)
- close_on_eintr(&fd);
+ xclose(&fd);
#endif
}
@@ -201,4 +198,3 @@ err:
exitf("Randomisierungsfehler");
exit(EXIT_FAILURE);
}
-#endif