summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2008-07-22 17:10:18 +0000
committerache <ache@FreeBSD.org>2008-07-22 17:10:18 +0000
commit9ead8ff0881eb8c37191380bb7ea2d0763596ae5 (patch)
tree4aa153376f753537103fb6ab6ff37447160255cb /lib/libc
parent127019df41db848f0e0dd92f3306894536a6a08f (diff)
downloadFreeBSD-src-9ead8ff0881eb8c37191380bb7ea2d0763596ae5.zip
FreeBSD-src-9ead8ff0881eb8c37191380bb7ea2d0763596ae5.tar.gz
Fixes based on bde's feedback.
1) Unindent and sort variables. 2) Indent struct members. 3) Remove _packed, use guaranteed >128 bytes size and only first 128 bytes from the structure. 4) Reword comment. Obtained from: bde
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/gen/arc4random.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/libc/gen/arc4random.c b/lib/libc/gen/arc4random.c
index 6f2dbde..84f70c9 100644
--- a/lib/libc/gen/arc4random.c
+++ b/lib/libc/gen/arc4random.c
@@ -55,6 +55,7 @@ struct arc4_stream {
static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
#define RANDOMDEV "/dev/random"
+#define KEYSIZE 128
#define THREAD_LOCK() \
do { \
if (__isthreaded) \
@@ -106,28 +107,27 @@ arc4_addrandom(u_char *dat, int datlen)
static void
arc4_stir(void)
{
- int fd, n, done;
+ int done, fd, n;
struct {
- struct timeval tv;
- pid_t pid;
- u_int8_t rnd[128 - sizeof(struct timeval) - sizeof(pid_t)];
- } __packed rdat;
+ struct timeval tv;
+ pid_t pid;
+ u_int8_t rnd[KEYSIZE];
+ } rdat;
fd = _open(RANDOMDEV, O_RDONLY, 0);
done = 0;
if (fd >= 0) {
- if (_read(fd, &rdat, sizeof(rdat)) == sizeof(rdat))
+ if (_read(fd, &rdat, KEYSIZE) == KEYSIZE)
done = 1;
(void)_close(fd);
}
- /* !done? Ah, what the heck. We'll just take whatever was on the
- * stack... */
if (!done) {
(void)gettimeofday(&rdat.tv, NULL);
rdat.pid = getpid();
+ /* We'll just take whatever was on the stack too... */
}
- arc4_addrandom((u_char *)&rdat, sizeof(rdat));
+ arc4_addrandom((u_char *)&rdat, KEYSIZE);
/*
* Throw away the first N bytes of output, as suggested in the
OpenPOWER on IntegriCloud