CVS commit: src/sbin/rndctl

2021-04-06 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Apr  6 22:02:40 UTC 2021

Modified Files:
src/sbin/rndctl: rndctl.8

Log Message:
Clarify wording further based on private feedback.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sbin/rndctl/rndctl.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.8
diff -u src/sbin/rndctl/rndctl.8:1.28 src/sbin/rndctl/rndctl.8:1.29
--- src/sbin/rndctl/rndctl.8:1.28	Tue Apr  6 12:32:39 2021
+++ src/sbin/rndctl/rndctl.8	Tue Apr  6 22:02:40 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: rndctl.8,v 1.28 2021/04/06 12:32:39 riastradh Exp $
+.\"	$NetBSD: rndctl.8,v 1.29 2021/04/06 22:02:40 riastradh Exp $
 .\"
 .\" Copyright (c) 1997 Michael Graff
 .\" All rights reserved.
@@ -66,15 +66,23 @@ is altered or displayed.
 This is mutually exclusive with
 .Fl t .
 .It Fl E
-Disable entropy estimation for the given device name or device type.
+Ignore estimates of entropy from the drivers for the given device name
+or type.
+.Pp
 If collection is still enabled, data is still collected and mixed into
-the internal entropy pool, but no entropy is assumed to be present.
+the internal entropy pool, but no entropy is assumed to be present and
+data from the selected devices will not unblock
+.Pa /dev/random .
 .It Fl e
-Re-enable entropy estimation for the given device name or device type.
-If the kernel's estimate for the given device is zero, as it is for
-devices of types other than
+Accept estimates of entropy from the drivers for the given device name
+or type.
+.Pp
+.Cm "rndctl -e"
+does not change the estimate provided by the driver; if the driver's
+estimate is zero, as it generally is for devices of types other than
 .Ic rng ,
-this does not increase the estimate.
+it remains zero after
+.Cm "rndctl -e" .
 .It Fl i
 With the
 .Fl L
@@ -86,9 +94,11 @@ even if the file claims to have adequate
 This is useful if the file is on a medium, such as an NFS share, that
 the operator does not know to be secret.
 .It Fl L
-Load saved entropy from file
+Load a seed from
 .Ar save-file
-and overwrite it with a seed derived by hashing it together with output
+generated by
+.Cm "rndctl -S" .
+Overwrite it with a seed derived by hashing it together with output
 from
 .Pa /dev/urandom
 so that the new seed has at least as much entropy as either the old
@@ -105,7 +115,7 @@ or
 .Ar devname
 specified.
 .It Fl S
-Save entropy to file
+Generate a seed from the system entropy pool and save it to
 .Ar save-file
 for later use with
 .Cm "rndctl -L" .



CVS commit: src/sbin/rndctl

2021-04-06 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Apr  6 12:32:39 UTC 2021

Modified Files:
src/sbin/rndctl: rndctl.8

Log Message:
Clarify security model of rndctl -S files.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sbin/rndctl/rndctl.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.8
diff -u src/sbin/rndctl/rndctl.8:1.27 src/sbin/rndctl/rndctl.8:1.28
--- src/sbin/rndctl/rndctl.8:1.27	Fri Apr  2 07:04:05 2021
+++ src/sbin/rndctl/rndctl.8	Tue Apr  6 12:32:39 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: rndctl.8,v 1.27 2021/04/02 07:04:05 nia Exp $
+.\"	$NetBSD: rndctl.8,v 1.28 2021/04/06 12:32:39 riastradh Exp $
 .\"
 .\" Copyright (c) 1997 Michael Graff
 .\" All rights reserved.
@@ -105,11 +105,22 @@ or
 .Ar devname
 specified.
 .It Fl S
-Save entropy pool to file
-.Ar save-file .
+Save entropy to file
+.Ar save-file
+for later use with
+.Cm "rndctl -L" .
+.Pp
 The file format is specific to
 .Nm
 and includes an estimate of the amount of saved entropy and a checksum.
+The prior internal state of the system entropy pool cannot be recovered
+from
+.Ar save-file ,
+so disclosure of
+.Ar save-file
+does not compromise past secrets drawn from
+.Pa /dev/urandom
+or equivalent.
 .It Fl s
 Display statistics on the current state of the entropy pool.
 .It Fl t



CVS commit: src/sbin/rndctl

2021-04-04 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Sun Apr  4 13:37:17 UTC 2021

Modified Files:
src/sbin/rndctl: rndctl.c

Log Message:
rndctl(8): to -l, add a "samples" column separate to "bits"

rename the "bits" column to "estimated bits".

this provides a clear indication when a source is being used, but
not increasing the entropy counter.

this commit fixes an unrelated bug where verbose output functioned
incorrectly when a class of device was specified with -t.

while here, reduce code duplication.

"gofer it" riastradh@


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sbin/rndctl/rndctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.c
diff -u src/sbin/rndctl/rndctl.c:1.39 src/sbin/rndctl/rndctl.c:1.40
--- src/sbin/rndctl/rndctl.c:1.39	Sun Apr  4 12:50:31 2021
+++ src/sbin/rndctl/rndctl.c	Sun Apr  4 13:37:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: rndctl.c,v 1.39 2021/04/04 12:50:31 nia Exp $	*/
+/*	$NetBSD: rndctl.c,v 1.40 2021/04/04 13:37:17 nia Exp $	*/
 
 /*-
  * Copyright (c) 1997 Michael Graff.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rndctl.c,v 1.39 2021/04/04 12:50:31 nia Exp $");
+__RCSID("$NetBSD: rndctl.c,v 1.40 2021/04/04 13:37:17 nia Exp $");
 #endif
 
 #include 
@@ -77,6 +77,8 @@ static const char *find_name(u_int32_t);
 static void do_ioctl(rndctl_t *);
 static char * strflags(uint32_t, u_int32_t);
 static void do_list(int, u_int32_t, char *);
+static void do_print_source(rndsource_est_t *);
+static void do_print_source_verbose(rndsource_est_t *);
 static void do_stats(void);
 
 static int iflag;
@@ -466,7 +468,26 @@ strflags(uint32_t totalbits, u_int32_t f
 	return (str);
 }
 
-#define HEADER "Source Bits Type  Flags\n"
+#define HEADER "Source   Estimated bitsSamples Type   Flags\n"
+
+static void
+do_print_source(rndsource_est_t *source)
+{
+	printf("%-16s ", source->rt.name);
+	printf("%10" PRIu32 " ", source->rt.total);
+	printf("%10" PRIu32 " ", source->dt_samples + source->dv_samples);
+	printf("%-6s ", find_name(source->rt.type));
+	printf("%s\n", strflags(source->rt.total, source->rt.flags));
+}
+
+static void
+do_print_source_verbose(rndsource_est_t *source)
+{
+	printf("\tDt samples = %d\n", source->dt_samples);
+	printf("\tDt bits = %d\n", source->dt_total);
+	printf("\tDv samples = %d\n", source->dv_samples);
+	printf("\tDv bits = %d\n", source->dv_total);
+}
 
 static void
 do_list(int all, u_int32_t type, char *name)
@@ -482,28 +503,15 @@ do_list(int all, u_int32_t type, char *n
 	if (fd < 0)
 		err(1, "open");
 
-	if (all == 0 && type == 0xff) {
+	if (!all && type == 0xff) {
 		strncpy(rstat_name.name, name, sizeof(rstat_name.name));
 		res = ioctl(fd, RNDGETESTNAME, _name);
 		if (res < 0)
 			err(1, "ioctl(RNDGETESTNAME)");
 		printf(HEADER);
-		printf("%-16s %10u %-4s %s\n",
-		rstat_name.source.rt.name,
-		rstat_name.source.rt.total,
-		find_name(rstat_name.source.rt.type),
-		strflags(rstat_name.source.rt.total,
-			rstat_name.source.rt.flags));
-		if (vflag) {
-			printf("\tDt samples = %d\n",
-			   rstat_name.source.dt_samples);
-			printf("\tDt bits = %d\n",
-			   rstat_name.source.dt_total);
-			printf("\tDv samples = %d\n",
-rstat_name.source.dv_samples);
-			printf("\tDv bits = %d\n",
-			   rstat_name.source.dv_total);
-		}
+		do_print_source(_name.source);
+		if (vflag)
+			do_print_source_verbose(_name.source);
 		close(fd);
 		return;
 	}
@@ -525,23 +533,10 @@ do_list(int all, u_int32_t type, char *n
 			break;
 
 		for (i = 0; i < rstat.count; i++) {
-			if (all != 0 ||
-			type == rstat.source[i].rt.type)
-printf("%-16s %10u %-4s %s\n",
-rstat.source[i].rt.name,
-rstat.source[i].rt.total,
-find_name(rstat.source[i].rt.type),
-strflags(rstat.source[i].rt.total,
-	rstat.source[i].rt.flags));
-			if (vflag) {
-printf("\tDt samples = %d\n",
-   rstat.source[i].dt_samples);
-printf("\tDt bits = %d\n",
-   rstat.source[i].dt_total);
-printf("\tDv samples = %d\n",
-   rstat.source[i].dv_samples);
-printf("\tDv bits = %d\n",
-   rstat.source[i].dv_total);
+			if (all || type == rstat.source[i].rt.type) {
+do_print_source([i]);
+if (vflag)
+	do_print_source_verbose([i]);
 			}
 }
 		start += rstat.count;



CVS commit: src/sbin/rndctl

2021-04-04 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Sun Apr  4 12:50:31 UTC 2021

Modified Files:
src/sbin/rndctl: rndctl.c

Log Message:
rndctl(8): remove no-longer-useful stats from -s

these are always 0 now.

"gofer it" riastradh@


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sbin/rndctl/rndctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.c
diff -u src/sbin/rndctl/rndctl.c:1.38 src/sbin/rndctl/rndctl.c:1.39
--- src/sbin/rndctl/rndctl.c:1.38	Fri Apr  2 07:17:56 2021
+++ src/sbin/rndctl/rndctl.c	Sun Apr  4 12:50:31 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: rndctl.c,v 1.38 2021/04/02 07:17:56 nia Exp $	*/
+/*	$NetBSD: rndctl.c,v 1.39 2021/04/04 12:50:31 nia Exp $	*/
 
 /*-
  * Copyright (c) 1997 Michael Graff.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rndctl.c,v 1.38 2021/04/02 07:17:56 nia Exp $");
+__RCSID("$NetBSD: rndctl.c,v 1.39 2021/04/04 12:50:31 nia Exp $");
 #endif
 
 #include 
@@ -563,13 +563,8 @@ do_stats(void)
 	if (ioctl(fd, RNDGETPOOLSTAT, ) < 0)
 		err(1, "ioctl(RNDGETPOOLSTAT)");
 
-	printf("\t%9u bits mixed into pool\n", rs.added);
 	printf("\t%9u bits currently stored in pool (max %u)\n",
 	rs.curentropy, rs.maxentropy);
-	printf("\t%9u bits of entropy discarded due to full pool\n",
-	rs.discarded);
-	printf("\t%9u hard-random bits generated\n", rs.removed);
-	printf("\t%9u pseudo-random bits generated\n", rs.generated);
 
 	close(fd);
 }



CVS commit: src/sbin/rndctl

2021-04-02 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Apr  2 07:17:56 UTC 2021

Modified Files:
src/sbin/rndctl: rndctl.c

Log Message:
rndctl: make -l's "Flags" field reflect current reality

don't print "legacy options" RND_FLAG_ESTIMATE_TIME and
"RND_FLAG_ESTIMATE_VALUE"

only print "estimate" if we have actually counted any bits from
something, since it's no longer really possible to "enable estimation".

ideally, there should also be a "samples" field so it's clear
collected bits are not being counted.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sbin/rndctl/rndctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.c
diff -u src/sbin/rndctl/rndctl.c:1.37 src/sbin/rndctl/rndctl.c:1.38
--- src/sbin/rndctl/rndctl.c:1.37	Tue May 12 09:48:44 2020
+++ src/sbin/rndctl/rndctl.c	Fri Apr  2 07:17:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: rndctl.c,v 1.37 2020/05/12 09:48:44 simonb Exp $	*/
+/*	$NetBSD: rndctl.c,v 1.38 2021/04/02 07:17:56 nia Exp $	*/
 
 /*-
  * Copyright (c) 1997 Michael Graff.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rndctl.c,v 1.37 2020/05/12 09:48:44 simonb Exp $");
+__RCSID("$NetBSD: rndctl.c,v 1.38 2021/04/02 07:17:56 nia Exp $");
 #endif
 
 #include 
@@ -75,7 +75,7 @@ __dead static void usage(void);
 static u_int32_t find_type(const char *name);
 static const char *find_name(u_int32_t);
 static void do_ioctl(rndctl_t *);
-static char * strflags(u_int32_t);
+static char * strflags(uint32_t, u_int32_t);
 static void do_list(int, u_int32_t, char *);
 static void do_stats(void);
 
@@ -444,29 +444,21 @@ do_ioctl(rndctl_t *rctl)
 }
 
 static char *
-strflags(u_int32_t fl)
+strflags(uint32_t totalbits, u_int32_t fl)
 {
 	static char str[512];
 
 	str[0] = '\0';
-	if (fl & RND_FLAG_NO_ESTIMATE)
-		;
-	else
+	if (totalbits > 0 && (fl & RND_FLAG_NO_ESTIMATE) == 0)
 		strlcat(str, "estimate, ", sizeof(str));
 
-	if (fl & RND_FLAG_NO_COLLECT)
-		;
-	else
+	if ((fl & RND_FLAG_NO_COLLECT) == 0)
 		strlcat(str, "collect, ", sizeof(str));
 
 	if (fl & RND_FLAG_COLLECT_VALUE)
 		strlcat(str, "v, ", sizeof(str));
 	if (fl & RND_FLAG_COLLECT_TIME)
 		strlcat(str, "t, ", sizeof(str));
-	if (fl & RND_FLAG_ESTIMATE_VALUE)
-		strlcat(str, "dv, ", sizeof(str));
-	if (fl & RND_FLAG_ESTIMATE_TIME)
-		strlcat(str, "dt, ", sizeof(str));
 
 	if (str[strlen(str) - 2] == ',')
 		str[strlen(str) - 2] = '\0';
@@ -500,7 +492,8 @@ do_list(int all, u_int32_t type, char *n
 		rstat_name.source.rt.name,
 		rstat_name.source.rt.total,
 		find_name(rstat_name.source.rt.type),
-		strflags(rstat_name.source.rt.flags));
+		strflags(rstat_name.source.rt.total,
+			rstat_name.source.rt.flags));
 		if (vflag) {
 			printf("\tDt samples = %d\n",
 			   rstat_name.source.dt_samples);
@@ -538,7 +531,8 @@ do_list(int all, u_int32_t type, char *n
 rstat.source[i].rt.name,
 rstat.source[i].rt.total,
 find_name(rstat.source[i].rt.type),
-strflags(rstat.source[i].rt.flags));
+strflags(rstat.source[i].rt.total,
+	rstat.source[i].rt.flags));
 			if (vflag) {
 printf("\tDt samples = %d\n",
    rstat.source[i].dt_samples);



CVS commit: src/sbin/rndctl

2021-04-02 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Fri Apr  2 07:04:05 UTC 2021

Modified Files:
src/sbin/rndctl: rndctl.8

Log Message:
rndctl.8: reflect current reality


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sbin/rndctl/rndctl.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.8
diff -u src/sbin/rndctl/rndctl.8:1.26 src/sbin/rndctl/rndctl.8:1.27
--- src/sbin/rndctl/rndctl.8:1.26	Thu May  7 19:09:26 2020
+++ src/sbin/rndctl/rndctl.8	Fri Apr  2 07:04:05 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: rndctl.8,v 1.26 2020/05/07 19:09:26 riastradh Exp $
+.\"	$NetBSD: rndctl.8,v 1.27 2021/04/02 07:04:05 nia Exp $
 .\"
 .\" Copyright (c) 1997 Michael Graff
 .\" All rights reserved.
@@ -26,7 +26,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd August 10, 2014
+.Dd April 2, 2021
 .Dt RNDCTL 8
 .Os
 .Sh NAME
@@ -56,11 +56,9 @@ entropy pool maintained by
 The following options are available:
 .Bl -tag -width 123456
 .It Fl C
-Disable collection of timing information for the given
-device name or device type.
+Disable collection of data for the given device name or device type.
 .It Fl c
-Enable collection of timing information for the given
-device name or device type.
+Enable collection of data for the given device name or device type.
 .It Fl d
 Only the device named
 .Ar devname
@@ -68,14 +66,15 @@ is altered or displayed.
 This is mutually exclusive with
 .Fl t .
 .It Fl E
-Disable entropy estimation from the collected timing information for
-the given device name or device type.
-If collection is still enabled, timing information is still
-collected and mixed into the internal entropy pool,
-but no entropy is assumed to be present.
+Disable entropy estimation for the given device name or device type.
+If collection is still enabled, data is still collected and mixed into
+the internal entropy pool, but no entropy is assumed to be present.
 .It Fl e
-Enable entropy estimation using the collected timing information
-for the given device name or device type.
+Re-enable entropy estimation for the given device name or device type.
+If the kernel's estimate for the given device is zero, as it is for
+devices of types other than
+.Ic rng ,
+this does not increase the estimate.
 .It Fl i
 With the
 .Fl L
@@ -138,6 +137,7 @@ Verbose output.
 .El
 .Sh SEE ALSO
 .Xr rnd 4 ,
+.Xr entropy 7 ,
 .Xr rnd 9
 .Sh HISTORY
 The



CVS commit: src/sbin/rndctl

2020-05-12 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Tue May 12 09:48:44 UTC 2020

Modified Files:
src/sbin/rndctl: rndctl.c

Log Message:
Whitespace alignment nits.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sbin/rndctl/rndctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.c
diff -u src/sbin/rndctl/rndctl.c:1.36 src/sbin/rndctl/rndctl.c:1.37
--- src/sbin/rndctl/rndctl.c:1.36	Thu May  7 19:13:38 2020
+++ src/sbin/rndctl/rndctl.c	Tue May 12 09:48:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: rndctl.c,v 1.36 2020/05/07 19:13:38 riastradh Exp $	*/
+/*	$NetBSD: rndctl.c,v 1.37 2020/05/12 09:48:44 simonb Exp $	*/
 
 /*-
  * Copyright (c) 1997 Michael Graff.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rndctl.c,v 1.36 2020/05/07 19:13:38 riastradh Exp $");
+__RCSID("$NetBSD: rndctl.c,v 1.37 2020/05/12 09:48:44 simonb Exp $");
 #endif
 
 #include 
@@ -90,8 +90,8 @@ usage(void)
 	getprogname());
 	fprintf(stderr, "   %s [-lsv] [-d devname | -t devtype]\n",
 	getprogname());
-	fprintf(stderr, "	%s [-i] -L save-file\n", getprogname());
-	fprintf(stderr, "	%s -S save-file\n", getprogname());
+	fprintf(stderr, "   %s [-i] -L save-file\n", getprogname());
+	fprintf(stderr, "   %s -S save-file\n", getprogname());
 	exit(1);
 }
 



CVS commit: src/sbin/rndctl

2020-05-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu May  7 19:13:38 UTC 2020

Modified Files:
src/sbin/rndctl: rndctl.c

Log Message:
Trigger entropy consolidation before saving seed.

This way, whenever /etc/security runs infrequently (daily), or the
operator manually issues rndctl -S, we ensure that all samples taken
during the entire boot are hashed together in the seed for the next
boot.

This should be infrequent enough that it's unlikely to enable the
iterative-guessing attacks that we try to mitigate by not frequently
consolidating entropy.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sbin/rndctl/rndctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.c
diff -u src/sbin/rndctl/rndctl.c:1.35 src/sbin/rndctl/rndctl.c:1.36
--- src/sbin/rndctl/rndctl.c:1.35	Thu May  7 19:12:45 2020
+++ src/sbin/rndctl/rndctl.c	Thu May  7 19:13:38 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: rndctl.c,v 1.35 2020/05/07 19:12:45 riastradh Exp $	*/
+/*	$NetBSD: rndctl.c,v 1.36 2020/05/07 19:13:38 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1997 Michael Graff.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rndctl.c,v 1.35 2020/05/07 19:12:45 riastradh Exp $");
+__RCSID("$NetBSD: rndctl.c,v 1.36 2020/05/07 19:13:38 riastradh Exp $");
 #endif
 
 #include 
@@ -40,6 +40,7 @@ __RCSID("$NetBSD: rndctl.c,v 1.35 2020/0
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -251,6 +252,11 @@ do_save(const char *filename)
 	char tmp[PATH_MAX];
 	int fd_seed;
 
+	/* Consolidate any pending samples.  */
+	if (sysctlbyname("kern.entropy.consolidate", NULL, NULL,
+		(const int[]){1}, sizeof(int)) == -1)
+		warn("consolidate entropy");
+
 	/* Format the temporary file name.  */
 	if (snprintf(tmp, sizeof tmp, "%s.tmp", filename) >= PATH_MAX)
 		errx(1, "path too long");
@@ -367,6 +373,11 @@ do_load(const char *filename)
 
 	/*
 	 * 2. Feed the old seed into the kernel.
+	 *
+	 * This also has the effect of consolidating pending samples,
+	 * whether or not there are enough samples from sources deemed
+	 * to have full entropy, so that the updated seed will
+	 * incorporate them.
 	 */
 	rd.len = MIN(sizeof(rd.data), sizeof(rs.data));
 	rd.entropy = rs.entropy;



CVS commit: src/sbin/rndctl

2020-05-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu May  7 19:12:45 UTC 2020

Modified Files:
src/sbin/rndctl: rndctl.c

Log Message:
Rework rndctl seed load sequence again.

Go back to the book's order, now that writing to /dev/random
guarantees to consolidate entropy -- this way the _next_ boot is no
less secure than the current boot, in the event that entropy sources
like interrupt timings provided any security that we just don't know
how to measure honestly.

Make sure to open the old seed to overwrite and the new seed to write
anew first so that we can determine whether the medium is read-only
before accepting the file's entropy estimate.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sbin/rndctl/rndctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.c
diff -u src/sbin/rndctl/rndctl.c:1.34 src/sbin/rndctl/rndctl.c:1.35
--- src/sbin/rndctl/rndctl.c:1.34	Wed May  6 18:49:26 2020
+++ src/sbin/rndctl/rndctl.c	Thu May  7 19:12:45 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: rndctl.c,v 1.34 2020/05/06 18:49:26 riastradh Exp $	*/
+/*	$NetBSD: rndctl.c,v 1.35 2020/05/07 19:12:45 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1997 Michael Graff.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rndctl.c,v 1.34 2020/05/06 18:49:26 riastradh Exp $");
+__RCSID("$NetBSD: rndctl.c,v 1.35 2020/05/07 19:12:45 riastradh Exp $");
 #endif
 
 #include 
@@ -129,41 +129,34 @@ find_name(u_int32_t type)
 }
 
 static int
-update_seed(const char *filename, const void *extra, size_t nextra,
-uint32_t extraentropy)
+update_seed(const char *filename, int fd_seed, const char *tmp,
+const void *extra, size_t nextra, uint32_t extraentropy)
 {
-	char tmp[PATH_MAX];
 	uint32_t systementropy;
 	uint8_t buf[32];
 	SHAKE128_CTX shake128;
 	rndsave_t rs;
 	SHA1_CTX s;
 	ssize_t nread, nwrit;
-	int fd;
+	int fd_random;
 
 	/* Paranoia: Avoid stack memory disclosure.  */
 	memset(, 0, sizeof rs);
 
-	/* Format the temporary file name.  */
-	if (snprintf(tmp, sizeof tmp, "%s.tmp", filename) >= PATH_MAX) {
-		warnx("path too long");
-		return -1;
-	}
-
-	/* Open /dev/urandom.  */
-	if ((fd = open(_PATH_URANDOM, O_RDONLY)) == -1) {
-		warn("device open");
+	/* Open /dev/urandom to read data from the system.  */
+	if ((fd_random = open(_PATH_URANDOM, O_RDONLY)) == -1) {
+		warn("open /dev/urandom");
 		return -1;
 	}
 
 	/* Find how much entropy is in the pool.  */
-	if (ioctl(fd, RNDGETENTCNT, ) == -1) {
+	if (ioctl(fd_random, RNDGETENTCNT, ) == -1) {
 		warn("ioctl(RNDGETENTCNT)");
 		systementropy = 0;
 	}
 
 	/* Read some data from /dev/urandom.  */
-	if ((size_t)(nread = read(fd, buf, sizeof buf)) != sizeof buf) {
+	if ((size_t)(nread = read(fd_random, buf, sizeof buf)) != sizeof buf) {
 		if (nread == -1)
 			warn("read");
 		else
@@ -172,9 +165,9 @@ update_seed(const char *filename, const 
 	}
 
 	/* Close /dev/urandom; we're done with it.  */
-	if (close(fd) == -1)
+	if (close(fd_random) == -1)
 		warn("close");
-	fd = -1;		/* paranoia */
+	fd_random = -1;		/* paranoia */
 
 	/*
 	 * Hash what we read together with the extra input to generate
@@ -221,11 +214,7 @@ update_seed(const char *filename, const 
 	 * begin with in which case we're hosed either way, or we've
 	 * just revealed some output which is not a problem.
 	 */
-	if ((fd = open(tmp, O_CREAT|O_TRUNC|O_WRONLY, 0600)) == -1) {
-		warn("open seed file to save");
-		return -1;
-	}
-	if ((size_t)(nwrit = write(fd, , sizeof rs)) != sizeof rs) {
+	if ((size_t)(nwrit = write(fd_seed, , sizeof rs)) != sizeof rs) {
 		int error = errno;
 		if (unlink(tmp) == -1)
 			warn("unlink");
@@ -236,14 +225,14 @@ update_seed(const char *filename, const 
 		return -1;
 	}
 	explicit_memset(, 0, sizeof rs); /* paranoia */
-	if (fsync_range(fd, FDATASYNC|FDISKSYNC, 0, 0) == -1) {
+	if (fsync_range(fd_seed, FDATASYNC|FDISKSYNC, 0, 0) == -1) {
 		int error = errno;
 		if (unlink(tmp) == -1)
 			warn("unlink");
 		warnc(error, "fsync_range");
 		return -1;
 	}
-	if (close(fd) == -1)
+	if (close(fd_seed) == -1)
 		warn("close");
 
 	/* Rename it over the original file to commit.  */
@@ -259,8 +248,19 @@ update_seed(const char *filename, const 
 static void
 do_save(const char *filename)
 {
+	char tmp[PATH_MAX];
+	int fd_seed;
+
+	/* Format the temporary file name.  */
+	if (snprintf(tmp, sizeof tmp, "%s.tmp", filename) >= PATH_MAX)
+		errx(1, "path too long");
 
-	if (update_seed(filename, NULL, 0, 0) == -1)
+	/* Create a temporary seed file.  */
+	if ((fd_seed = open(tmp, O_CREAT|O_TRUNC|O_WRONLY, 0600)) == -1)
+		err(1, "open seed file to save");
+
+	/* Update the seed.  Abort on failure.  */
+	if (update_seed(filename, fd_seed, tmp, NULL, 0, 0) == -1)
 		exit(1);
 }
 
@@ -268,7 +268,7 @@ static void
 do_load(const char *filename)
 {
 	char tmp[PATH_MAX];
-	int fd_seed, fd_random;
+	int fd_new, fd_old, fd_random;
 	rndsave_t rs;
 	

CVS commit: src/sbin/rndctl

2020-05-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu May  7 19:09:26 UTC 2020

Modified Files:
src/sbin/rndctl: rndctl.8

Log Message:
Touch up rndctl(8) a bit.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sbin/rndctl/rndctl.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.8
diff -u src/sbin/rndctl/rndctl.8:1.25 src/sbin/rndctl/rndctl.8:1.26
--- src/sbin/rndctl/rndctl.8:1.25	Thu May  7 12:58:09 2020
+++ src/sbin/rndctl/rndctl.8	Thu May  7 19:09:26 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: rndctl.8,v 1.25 2020/05/07 12:58:09 wiz Exp $
+.\"	$NetBSD: rndctl.8,v 1.26 2020/05/07 19:09:26 riastradh Exp $
 .\"
 .\" Copyright (c) 1997 Michael Graff
 .\" All rights reserved.
@@ -31,7 +31,7 @@
 .Os
 .Sh NAME
 .Nm rndctl
-.Nd in-kernel random number generator management tool
+.Nd kernel entropy pool management tool
 .Sh SYNOPSIS
 .Nm
 .Op Fl CcEe
@@ -49,10 +49,9 @@ The
 .Nm
 program displays statistics on the current state of the
 .Xr rnd 4
-pseudo-driver, and allows the administrator to control which sources
-are allowed to contribute to the randomness pool maintained by
-.Xr rnd 4 ,
-as well as whether a given source counts as strongly random.
+device, and controls which sources are allowed to contribute to the
+entropy pool maintained by
+.Xr rnd 4 .
 .Pp
 The following options are available:
 .Bl -tag -width 123456
@@ -113,7 +112,7 @@ The file format is specific to
 .Nm
 and includes an estimate of the amount of saved entropy and a checksum.
 .It Fl s
-Display statistics on the current state of the random collection pool.
+Display statistics on the current state of the entropy pool.
 .It Fl t
 All devices of type
 .Ar devtype
@@ -132,19 +131,10 @@ Tape devices.
 .It Ic tty
 Terminal, mouse, or other user input devices.
 .It Ic rng
-Random number generators.
+Hardware random number generators.
 .El
 .It Fl v
-Verbose output: show entropy estimation statistics for each source.
-.El
-.Sh FILES
-.Bl -tag -width /dev/urandomx -compact
-.It Pa /dev/random
-Returns
-.Dq good
-values only.
-.It Pa /dev/urandom
-Always returns data, degenerates to a pseudo-random generator.
+Verbose output.
 .El
 .Sh SEE ALSO
 .Xr rnd 4 ,
@@ -160,9 +150,3 @@ The
 program was written by
 .An Michael Graff
 .Aq explo...@flame.org .
-.Sh BUGS
-Turning on entropy estimation from unsafe or predictable sources will
-weaken system security, while turning on entropy collection from such
-sources may weaken system security.
-.Pp
-Care should be taken when using this command.



CVS commit: src/sbin/rndctl

2020-05-07 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Thu May  7 12:58:09 UTC 2020

Modified Files:
src/sbin/rndctl: rndctl.8

Log Message:
Add -i to SYNOPSIS.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sbin/rndctl/rndctl.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.8
diff -u src/sbin/rndctl/rndctl.8:1.24 src/sbin/rndctl/rndctl.8:1.25
--- src/sbin/rndctl/rndctl.8:1.24	Wed May  6 18:49:26 2020
+++ src/sbin/rndctl/rndctl.8	Thu May  7 12:58:09 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: rndctl.8,v 1.24 2020/05/06 18:49:26 riastradh Exp $
+.\"	$NetBSD: rndctl.8,v 1.25 2020/05/07 12:58:09 wiz Exp $
 .\"
 .\" Copyright (c) 1997 Michael Graff
 .\" All rights reserved.
@@ -40,6 +40,7 @@
 .Op Fl lsv
 .Op Fl d Ar devname | Fl t Ar devtype
 .Nm
+.Op Fl i
 .Fl L Ar save-file
 .Nm
 .Fl S Ar save-file



CVS commit: src/sbin/rndctl

2020-04-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Apr 30 03:27:15 UTC 2020

Modified Files:
src/sbin/rndctl: rndctl.c

Log Message:
Sort includes.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sbin/rndctl/rndctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.c
diff -u src/sbin/rndctl/rndctl.c:1.32 src/sbin/rndctl/rndctl.c:1.33
--- src/sbin/rndctl/rndctl.c:1.32	Thu Apr 30 03:24:48 2020
+++ src/sbin/rndctl/rndctl.c	Thu Apr 30 03:27:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: rndctl.c,v 1.32 2020/04/30 03:24:48 riastradh Exp $	*/
+/*	$NetBSD: rndctl.c,v 1.33 2020/04/30 03:27:15 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1997 Michael Graff.
@@ -28,30 +28,28 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-#include 
-#include 
-#include 
 
+#include 
 #ifndef lint
-__RCSID("$NetBSD: rndctl.c,v 1.32 2020/04/30 03:24:48 riastradh Exp $");
+__RCSID("$NetBSD: rndctl.c,v 1.33 2020/04/30 03:27:15 riastradh Exp $");
 #endif
 
-
-#include 
-#include 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 
-#include 
-#include 
-#include 
-#include 
-#include 
 #include 
+#include 
+#include 
 #include 
+#include 
+#include 
+#include 
 #include 
+#include 
 
 typedef struct {
 	const char *a_name;



CVS commit: src/sbin/rndctl

2020-04-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Apr 30 03:24:48 UTC 2020

Modified Files:
src/sbin/rndctl: rndctl.c

Log Message:
Accept both byte orders for random seed in `rndctl -L'.

The file format was defined with a machine-dependent 32-bit integer
field (the estimated number of bits of entropy in the process that
generated it).  Take whichever byte order gives a number that is
reasonable, i.e. lower than the number of bits in the buffer.

Continue to have `rndctl -S' generate it in machine-dependent byte
order for now, so that if you roll back to an older rndctl(8) then
`rndctl -L' on the same machine will still be able to load it with
the right entropy estimate.  In a future revision, perhaps we can
change it to be little-endian.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sbin/rndctl/rndctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.c
diff -u src/sbin/rndctl/rndctl.c:1.31 src/sbin/rndctl/rndctl.c:1.32
--- src/sbin/rndctl/rndctl.c:1.31	Fri Dec  6 14:43:18 2019
+++ src/sbin/rndctl/rndctl.c	Thu Apr 30 03:24:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: rndctl.c,v 1.31 2019/12/06 14:43:18 riastradh Exp $	*/
+/*	$NetBSD: rndctl.c,v 1.32 2020/04/30 03:24:48 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1997 Michael Graff.
@@ -33,13 +33,14 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: rndctl.c,v 1.31 2019/12/06 14:43:18 riastradh Exp $");
+__RCSID("$NetBSD: rndctl.c,v 1.32 2020/04/30 03:24:48 riastradh Exp $");
 #endif
 
 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -192,9 +193,8 @@ do_save(const char *filename, const void
 	MIN(sizeof(rs.data), UINT32_MAX/NBBY)*NBBY);
 
 	/*
-	 * Compute the checksum on the 32-bit entropy count, in host
-	 * byte order (XXX this means it is not portable across
-	 * different-endian platforms!), followed by the seed data.
+	 * Compute the checksum on the 32-bit entropy count, followed
+	 * by the seed data.
 	 */
 	SHA1Init();
 	SHA1Update(, (const uint8_t *), sizeof(rs.entropy));
@@ -309,6 +309,17 @@ do_load(const char *filename)
 		rs.entropy = 0;
 	}
 
+	/*
+	 * If the entropy is insensibly large, try byte-swapping.
+	 * Otherwise assume the file is corrupted and act as though it
+	 * has zero entropy.
+	 */
+	if (howmany(rs.entropy, NBBY) > sizeof(rs.data)) {
+		rs.entropy = bswap32(rs.entropy);
+		if (howmany(rs.entropy, NBBY) > sizeof(rs.data))
+			rs.entropy = 0;
+	}
+
 	/* Format the ioctl request.  */
 	rd.len = MIN(sizeof(rd.data), sizeof(rs.data));
 	rd.entropy = rs.entropy;



CVS commit: src/sbin/rndctl

2020-01-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Jan 14 23:13:36 UTC 2020

Modified Files:
src/sbin/rndctl: Makefile

Log Message:
.include bsd.own.mk for ${NETBSDSRCDIR}


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sbin/rndctl/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/Makefile
diff -u src/sbin/rndctl/Makefile:1.4 src/sbin/rndctl/Makefile:1.5
--- src/sbin/rndctl/Makefile:1.4	Fri Dec  6 09:43:18 2019
+++ src/sbin/rndctl/Makefile	Tue Jan 14 18:13:36 2020
@@ -1,4 +1,6 @@
-#	$NetBSD: Makefile,v 1.4 2019/12/06 14:43:18 riastradh Exp $
+#	$NetBSD: Makefile,v 1.5 2020/01/14 23:13:36 christos Exp $
+
+.include 
 
 PROG=	rndctl
 MAN=	rndctl.8



CVS commit: src/sbin/rndctl

2019-12-06 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Dec  6 14:43:18 UTC 2019

Modified Files:
src/sbin/rndctl: Makefile rndctl.8 rndctl.c
Added Files:
src/sbin/rndctl: namespace.h

Log Message:
Teach `rndctl -L' to update the seed file, not just delete it.

The seed file is updated by entering the old seed into the system and
then hashing the old seed together with data from /dev/urandom, and
writing it atomically with write-to-temporary/rename-to-permanent.

This way, interruption by crash or power loss does not obliterate
your persistent entropy (unless it causes file system corruption).


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sbin/rndctl/Makefile
cvs rdiff -u -r0 -r1.1 src/sbin/rndctl/namespace.h
cvs rdiff -u -r1.22 -r1.23 src/sbin/rndctl/rndctl.8
cvs rdiff -u -r1.30 -r1.31 src/sbin/rndctl/rndctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/Makefile
diff -u src/sbin/rndctl/Makefile:1.3 src/sbin/rndctl/Makefile:1.4
--- src/sbin/rndctl/Makefile:1.3	Sun Oct 13 07:28:13 2019
+++ src/sbin/rndctl/Makefile	Fri Dec  6 14:43:18 2019
@@ -1,8 +1,20 @@
-#	$NetBSD: Makefile,v 1.3 2019/10/13 07:28:13 mrg Exp $
+#	$NetBSD: Makefile,v 1.4 2019/12/06 14:43:18 riastradh Exp $
 
 PROG=	rndctl
 MAN=	rndctl.8
 
 COPTS.rndctl.c+=	${GCC_NO_STRINGOP_TRUNCATION}
 
+SRCS+=	rndctl.c
+
+# Hack: libc does not export public SHA-3 symbols, so we'll just copy
+# them here statically.
+.PATH:	${NETBSDSRCDIR}/common/lib/libc/hash/sha3
+
+# Hack for namespace.h in sha3.c.
+CPPFLAGS+=	-I${.CURDIR}
+
+SRCS+=	sha3.c
+SRCS+=	keccak.c
+
 .include 

Index: src/sbin/rndctl/rndctl.8
diff -u src/sbin/rndctl/rndctl.8:1.22 src/sbin/rndctl/rndctl.8:1.23
--- src/sbin/rndctl/rndctl.8:1.22	Sun Aug 10 17:13:02 2014
+++ src/sbin/rndctl/rndctl.8	Fri Dec  6 14:43:18 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: rndctl.8,v 1.22 2014/08/10 17:13:02 wiz Exp $
+.\"	$NetBSD: rndctl.8,v 1.23 2019/12/06 14:43:18 riastradh Exp $
 .\"
 .\" Copyright (c) 1997 Michael Graff
 .\" All rights reserved.
@@ -78,9 +78,13 @@ Enable entropy estimation using the coll
 for the given device name or device type.
 .It Fl L
 Load saved entropy from file
-.Ar save-file ,
-which will be overwritten and deleted before the entropy is loaded into
-the kernel.
+.Ar save-file
+and overwrite it with a seed derived by hashing it together with output
+from
+.Pa /dev/urandom
+so that the new seed has at least as much entropy as either the old
+seed had or the system already has.
+If interrupted, either the old seed or the new seed will be in place.
 .It Fl l
 List all sources, or, if the
 .Fl t

Index: src/sbin/rndctl/rndctl.c
diff -u src/sbin/rndctl/rndctl.c:1.30 src/sbin/rndctl/rndctl.c:1.31
--- src/sbin/rndctl/rndctl.c:1.30	Mon Apr 13 22:18:50 2015
+++ src/sbin/rndctl/rndctl.c	Fri Dec  6 14:43:18 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: rndctl.c,v 1.30 2015/04/13 22:18:50 riastradh Exp $	*/
+/*	$NetBSD: rndctl.c,v 1.31 2019/12/06 14:43:18 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1997 Michael Graff.
@@ -33,7 +33,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: rndctl.c,v 1.30 2015/04/13 22:18:50 riastradh Exp $");
+__RCSID("$NetBSD: rndctl.c,v 1.31 2019/12/06 14:43:18 riastradh Exp $");
 #endif
 
 
@@ -41,6 +41,7 @@ __RCSID("$NetBSD: rndctl.c,v 1.30 2015/0
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -127,111 +128,227 @@ find_name(u_int32_t type)
 }
 
 static void
-do_save(const char *const filename)
+do_save(const char *filename, const void *extra, size_t nextra,
+uint32_t extraentropy)
 {
-	int est1, est2;
-	rndpoolstat_t rp;
+	char tmp[PATH_MAX];
+	uint32_t systementropy;
+	uint8_t buf[32];
+	SHAKE128_CTX shake128;
 	rndsave_t rs;
 	SHA1_CTX s;
-
+	ssize_t nread, nwrit;
 	int fd;
 
-	fd = open(_PATH_URANDOM, O_RDONLY, 0644);
-	if (fd < 0) {
-		err(1, "device open");
-	}
-
-	if (ioctl(fd, RNDGETPOOLSTAT, ) < 0) {
-		err(1, "ioctl(RNDGETPOOLSTAT)");
-	}
+	/* Paranoia: Avoid stack memory disclosure.  */
+	memset(, 0, sizeof rs);
 
-	est1 = rp.curentropy;
+	/* Format the temporary file name.  */
+	if (snprintf(tmp, sizeof tmp, "%s.tmp", filename) >= PATH_MAX)
+		errx(1, "path too long");
 
-	if (read(fd, rs.data, sizeof(rs.data)) != sizeof(rs.data)) {
-		err(1, "entropy read");
-	}
+	/* Open /dev/urandom.  */
+	if ((fd = open(_PATH_URANDOM, O_RDONLY)) == -1)
+		err(1, "device open");
 
-	if (ioctl(fd, RNDGETPOOLSTAT, ) < 0) {
-		err(1, "ioctl(RNDGETPOOLSTAT)");
-	}
+	/* Find how much entropy is in the pool.  */
+	if (ioctl(fd, RNDGETENTCNT, ) == -1)
+		err(1, "ioctl(RNDGETENTCNT)");
+
+	/* Read some data from /dev/urandom.  */
+	if ((size_t)(nread = read(fd, buf, sizeof buf)) != sizeof buf) {
+		if (nread == -1)
+			err(1, "read");
+		else
+			errx(1, "truncated read");
+	}
+
+	/* Close /dev/urandom; we're done with it.  */
+	if (close(fd) == -1)
+		warn("close");
+	fd = -1;		/* paranoia */
 
-	est2 = 

CVS commit: src/sbin/rndctl

2015-04-13 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Apr 13 22:18:50 UTC 2015

Modified Files:
src/sbin/rndctl: rndctl.c

Log Message:
Use sys/rndio.h instead of sys/rnd.h.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sbin/rndctl/rndctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.c
diff -u src/sbin/rndctl/rndctl.c:1.29 src/sbin/rndctl/rndctl.c:1.30
--- src/sbin/rndctl/rndctl.c:1.29	Sun Aug 10 17:13:14 2014
+++ src/sbin/rndctl/rndctl.c	Mon Apr 13 22:18:50 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: rndctl.c,v 1.29 2014/08/10 17:13:14 wiz Exp $	*/
+/*	$NetBSD: rndctl.c,v 1.30 2015/04/13 22:18:50 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1997 Michael Graff.
@@ -33,14 +33,14 @@
 #include sha1.h
 
 #ifndef lint
-__RCSID($NetBSD: rndctl.c,v 1.29 2014/08/10 17:13:14 wiz Exp $);
+__RCSID($NetBSD: rndctl.c,v 1.30 2015/04/13 22:18:50 riastradh Exp $);
 #endif
 
 
 #include sys/types.h
 #include sys/ioctl.h
 #include sys/param.h
-#include sys/rnd.h
+#include sys/rndio.h
 
 #include stdio.h
 #include stdlib.h



CVS commit: src/sbin/rndctl

2014-08-10 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Aug 10 17:13:02 UTC 2014

Modified Files:
src/sbin/rndctl: rndctl.8

Log Message:
Sort options and mark them as optional.
Bump date for previous.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sbin/rndctl/rndctl.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.8
diff -u src/sbin/rndctl/rndctl.8:1.21 src/sbin/rndctl/rndctl.8:1.22
--- src/sbin/rndctl/rndctl.8:1.21	Sun Aug 10 16:44:32 2014
+++ src/sbin/rndctl/rndctl.8	Sun Aug 10 17:13:02 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: rndctl.8,v 1.21 2014/08/10 16:44:32 tls Exp $
+.\	$NetBSD: rndctl.8,v 1.22 2014/08/10 17:13:02 wiz Exp $
 .\
 .\ Copyright (c) 1997 Michael Graff
 .\ All rights reserved.
@@ -26,7 +26,7 @@
 .\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\ SUCH DAMAGE.
 .\
-.Dd November 23, 2011
+.Dd August 10, 2014
 .Dt RNDCTL 8
 .Os
 .Sh NAME
@@ -34,12 +34,11 @@
 .Nd in-kernel random number generator management tool
 .Sh SYNOPSIS
 .Nm
-.Fl CcEe
+.Op Fl CcEe
 .Op Fl d Ar devname | Fl t Ar devtype
 .Nm
-.Fl ls
+.Op Fl lsv
 .Op Fl d Ar devname | Fl t Ar devtype
-.Op Fl v
 .Nm
 .Fl L Ar save-file
 .Nm



CVS commit: src/sbin/rndctl

2014-08-10 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Aug 10 17:13:14 UTC 2014

Modified Files:
src/sbin/rndctl: rndctl.c

Log Message:
Sync usage with manpage a bit more.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sbin/rndctl/rndctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.c
diff -u src/sbin/rndctl/rndctl.c:1.28 src/sbin/rndctl/rndctl.c:1.29
--- src/sbin/rndctl/rndctl.c:1.28	Sun Aug 10 16:44:32 2014
+++ src/sbin/rndctl/rndctl.c	Sun Aug 10 17:13:14 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: rndctl.c,v 1.28 2014/08/10 16:44:32 tls Exp $	*/
+/*	$NetBSD: rndctl.c,v 1.29 2014/08/10 17:13:14 wiz Exp $	*/
 
 /*-
  * Copyright (c) 1997 Michael Graff.
@@ -33,7 +33,7 @@
 #include sha1.h
 
 #ifndef lint
-__RCSID($NetBSD: rndctl.c,v 1.28 2014/08/10 16:44:32 tls Exp $);
+__RCSID($NetBSD: rndctl.c,v 1.29 2014/08/10 17:13:14 wiz Exp $);
 #endif
 
 
@@ -84,9 +84,9 @@ static void
 usage(void)
 {
 
-	fprintf(stderr, usage: %s -CEce [-d devname | -t devtype]\n,
+	fprintf(stderr, usage: %s [-CEce] [-d devname | -t devtype]\n,
 	getprogname());
-	fprintf(stderr,%s -ls [-d devname | -t devtype]\n,
+	fprintf(stderr,%s [-lsv] [-d devname | -t devtype]\n,
 	getprogname());
 	fprintf(stderr, 	%s -[L|S] save-file\n, getprogname());
 	exit(1);



CVS commit: src/sbin/rndctl

2014-01-15 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Wed Jan 15 10:13:25 UTC 2014

Modified Files:
src/sbin/rndctl: rndctl.c

Log Message:
Fix arguments for write.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sbin/rndctl/rndctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.c
diff -u src/sbin/rndctl/rndctl.c:1.25 src/sbin/rndctl/rndctl.c:1.26
--- src/sbin/rndctl/rndctl.c:1.25	Tue Aug 14 14:41:07 2012
+++ src/sbin/rndctl/rndctl.c	Wed Jan 15 10:13:25 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: rndctl.c,v 1.25 2012/08/14 14:41:07 jruoho Exp $	*/
+/*	$NetBSD: rndctl.c,v 1.26 2014/01/15 10:13:25 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1997 Michael Graff.
@@ -33,7 +33,7 @@
 #include sha1.h
 
 #ifndef lint
-__RCSID($NetBSD: rndctl.c,v 1.25 2012/08/14 14:41:07 jruoho Exp $);
+__RCSID($NetBSD: rndctl.c,v 1.26 2014/01/15 10:13:25 joerg Exp $);
 #endif
 
 
@@ -203,9 +203,8 @@ do_load(const char *const filename)
 	}
 
 	memset(rszero, 0, sizeof(rszero));
-	if (write(fd, rszero, sizeof(rszero) != sizeof(rszero))) {
+	if (write(fd, rszero, sizeof(rszero)) != sizeof(rszero))
 		err(1, overwrite);
-	}
 	fsync_range(fd, FDATASYNC|FDISKSYNC, (off_t)0, (off_t)0);
 	close(fd);
 



CVS commit: src/sbin/rndctl

2014-01-15 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Wed Jan 15 15:05:27 UTC 2014

Modified Files:
src/sbin/rndctl: rndctl.c

Log Message:
Overwrite the seed file from the beginning, using pwrite(2).


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sbin/rndctl/rndctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.c
diff -u src/sbin/rndctl/rndctl.c:1.26 src/sbin/rndctl/rndctl.c:1.27
--- src/sbin/rndctl/rndctl.c:1.26	Wed Jan 15 10:13:25 2014
+++ src/sbin/rndctl/rndctl.c	Wed Jan 15 15:05:27 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: rndctl.c,v 1.26 2014/01/15 10:13:25 joerg Exp $	*/
+/*	$NetBSD: rndctl.c,v 1.27 2014/01/15 15:05:27 apb Exp $	*/
 
 /*-
  * Copyright (c) 1997 Michael Graff.
@@ -33,7 +33,7 @@
 #include sha1.h
 
 #ifndef lint
-__RCSID($NetBSD: rndctl.c,v 1.26 2014/01/15 10:13:25 joerg Exp $);
+__RCSID($NetBSD: rndctl.c,v 1.27 2014/01/15 15:05:27 apb Exp $);
 #endif
 
 
@@ -203,7 +203,7 @@ do_load(const char *const filename)
 	}
 
 	memset(rszero, 0, sizeof(rszero));
-	if (write(fd, rszero, sizeof(rszero)) != sizeof(rszero))
+	if (pwrite(fd, rszero, sizeof(rszero), (off_t)0) != sizeof(rszero))
 		err(1, overwrite);
 	fsync_range(fd, FDATASYNC|FDISKSYNC, (off_t)0, (off_t)0);
 	close(fd);



CVS commit: src/sbin/rndctl

2012-08-14 Thread Jukka Ruohonen
Module Name:src
Committed By:   jruoho
Date:   Tue Aug 14 14:41:07 UTC 2012

Modified Files:
src/sbin/rndctl: rndctl.c

Log Message:
Use _PATH_URANDOM from paths(3).


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sbin/rndctl/rndctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.c
diff -u src/sbin/rndctl/rndctl.c:1.24 src/sbin/rndctl/rndctl.c:1.25
--- src/sbin/rndctl/rndctl.c:1.24	Thu Feb  2 19:42:57 2012
+++ src/sbin/rndctl/rndctl.c	Tue Aug 14 14:41:07 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: rndctl.c,v 1.24 2012/02/02 19:42:57 tls Exp $	*/
+/*	$NetBSD: rndctl.c,v 1.25 2012/08/14 14:41:07 jruoho Exp $	*/
 
 /*-
  * Copyright (c) 1997 Michael Graff.
@@ -33,7 +33,7 @@
 #include sha1.h
 
 #ifndef lint
-__RCSID($NetBSD: rndctl.c,v 1.24 2012/02/02 19:42:57 tls Exp $);
+__RCSID($NetBSD: rndctl.c,v 1.25 2012/08/14 14:41:07 jruoho Exp $);
 #endif
 
 
@@ -48,6 +48,7 @@ __RCSID($NetBSD: rndctl.c,v 1.24 2012/0
 #include fcntl.h
 #include errno.h
 #include err.h
+#include paths.h
 #include string.h
 
 typedef struct {
@@ -133,11 +134,11 @@ do_save(const char *const filename)
 
 	int fd;
 
-	fd = open(/dev/urandom, O_RDONLY, 0644);
+	fd = open(_PATH_URANDOM, O_RDONLY, 0644);
 	if (fd  0) {
 		err(1, device open);
 	}
-	
+
 	if (ioctl(fd, RNDGETPOOLSTAT, rp)  0) {
 		err(1, ioctl(RNDGETPOOLSTAT));
 	}
@@ -171,7 +172,7 @@ do_save(const char *const filename)
 	if (fd  0) {
 		err(1, output open);
 	}
-	
+
 	if (write(fd, rs, sizeof(rs)) != sizeof(rs)) {
 		unlink(filename);
 		fsync_range(fd, FDATASYNC|FDISKSYNC, (off_t)0, (off_t)0);
@@ -221,7 +222,7 @@ do_load(const char *const filename)
 	rd.entropy = rs.entropy;
 	memcpy(rd.data, rs.data, MIN(sizeof(rd.data), sizeof(rs.data)));
 
-	fd = open(/dev/urandom, O_RDWR, 0644);
+	fd = open(_PATH_URANDOM, O_RDWR, 0644);
 	if (fd  0) {
 		err(1, device open);
 	}
@@ -238,7 +239,7 @@ do_ioctl(rndctl_t *rctl)
 	int fd;
 	int res;
 
-	fd = open(/dev/urandom, O_RDONLY, 0644);
+	fd = open(_PATH_URANDOM, O_RDONLY, 0644);
 	if (fd  0)
 		err(1, open);
 
@@ -283,7 +284,7 @@ do_list(int all, u_int32_t type, char *n
 	uint32_t i;
 	u_int32_t start;
 
-	fd = open(/dev/urandom, O_RDONLY, 0644);
+	fd = open(_PATH_URANDOM, O_RDONLY, 0644);
 	if (fd  0)
 		err(1, open);
 
@@ -339,7 +340,7 @@ do_stats(void)
 	rndpoolstat_t rs;
 	int fd;
 
-	fd = open(/dev/urandom, O_RDONLY, 0644);
+	fd = open(_PATH_URANDOM, O_RDONLY, 0644);
 	if (fd  0)
 		err(1, open);
 



CVS commit: src/sbin/rndctl

2011-12-17 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Sat Dec 17 13:18:21 UTC 2011

Modified Files:
src/sbin/rndctl: rndctl.c

Log Message:
Make rndctl -L overwrite the file with zeros, not with the
same data that was just read from the file.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sbin/rndctl/rndctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.c
diff -u src/sbin/rndctl/rndctl.c:1.22 src/sbin/rndctl/rndctl.c:1.23
--- src/sbin/rndctl/rndctl.c:1.22	Sat Nov 26 01:17:17 2011
+++ src/sbin/rndctl/rndctl.c	Sat Dec 17 13:18:20 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rndctl.c,v 1.22 2011/11/26 01:17:17 tls Exp $	*/
+/*	$NetBSD: rndctl.c,v 1.23 2011/12/17 13:18:20 apb Exp $	*/
 
 /*-
  * Copyright (c) 1997 Michael Graff.
@@ -33,7 +33,7 @@
 #include sha1.h
 
 #ifndef lint
-__RCSID($NetBSD: rndctl.c,v 1.22 2011/11/26 01:17:17 tls Exp $);
+__RCSID($NetBSD: rndctl.c,v 1.23 2011/12/17 13:18:20 apb Exp $);
 #endif
 
 
@@ -181,7 +181,7 @@ static void
 do_load(const char *const filename)
 {
 	int fd;
-	rndsave_t rs;
+	rndsave_t rs, rszero;
 	rnddata_t rd;
 	SHA1_CTX s;
 	uint8_t digest[SHA1_DIGEST_LENGTH];
@@ -197,7 +197,8 @@ do_load(const char *const filename)
 		err(1, read);
 	}
 
-	if (write(fd, rs, sizeof(rs) != sizeof(rs))) {
+	memset(rszero, 0, sizeof(rszero));
+	if (write(fd, rszero, sizeof(rszero) != sizeof(rszero))) {
 		err(1, overwrite);
 	}
 	fsync_range(fd, FDATASYNC|FDISKSYNC, (off_t)0, (off_t)0);



CVS commit: src/sbin/rndctl

2011-11-23 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Nov 23 12:15:30 UTC 2011

Modified Files:
src/sbin/rndctl: rndctl.8

Log Message:
Sort option descriptions, bump date for previous.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sbin/rndctl/rndctl.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.8
diff -u src/sbin/rndctl/rndctl.8:1.19 src/sbin/rndctl/rndctl.8:1.20
--- src/sbin/rndctl/rndctl.8:1.19	Wed Nov 23 10:47:49 2011
+++ src/sbin/rndctl/rndctl.8	Wed Nov 23 12:15:30 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: rndctl.8,v 1.19 2011/11/23 10:47:49 tls Exp $
+.\	$NetBSD: rndctl.8,v 1.20 2011/11/23 12:15:30 wiz Exp $
 .\
 .\ Copyright (c) 1997 Michael Graff
 .\ All rights reserved.
@@ -26,7 +26,7 @@
 .\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\ SUCH DAMAGE.
 .\
-.Dd January 4, 2009
+.Dd November 23, 2011
 .Dt RNDCTL 8
 .Os
 .Sh NAME
@@ -76,6 +76,11 @@ but no entropy is assumed to be present.
 .It Fl e
 Enable entropy estimation using the collected timing information
 for the given device name or device type.
+.It Fl L
+Load saved entropy from file
+.Ar save-file ,
+which will be overwritten and deleted before the entropy is loaded into
+the kernel.
 .It Fl l
 List all sources, or, if the
 .Fl t
@@ -86,6 +91,12 @@ flags are specified, only those specifie
 or
 .Ar devname
 specified.
+.It Fl S
+Save entropy pool to file
+.Ar save-file .
+The file format is specific to
+.Nm
+and includes an estimate of the amount of saved entropy and a checksum.
 .It Fl s
 Display statistics on the current state of the random collection pool.
 .It Fl t
@@ -108,17 +119,6 @@ Terminal, mouse, or other user input dev
 .It Ic rng
 Random number generators.
 .El
-.It Fl L
-Load saved entropy from file
-.Ar save-file ,
-which will be overwritten and deleted before the entropy is loaded into
-the kernel.
-.It Fl S
-Save entropy pool to file
-.Ar save-file .
-The file format is specific to
-.Nm
-and includes an estimate of the amount of saved entropy and a checksum.
 .El
 .Sh FILES
 .Bl -tag -width /dev/urandomx -compact



CVS commit: src/sbin/rndctl

2011-09-30 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sat Oct  1 02:55:00 UTC 2011

Modified Files:
src/sbin/rndctl: rndctl.8

Log Message:
Fix typo


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sbin/rndctl/rndctl.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.8
diff -u src/sbin/rndctl/rndctl.8:1.17 src/sbin/rndctl/rndctl.8:1.18
--- src/sbin/rndctl/rndctl.8:1.17	Sun Jan  4 12:01:43 2009
+++ src/sbin/rndctl/rndctl.8	Sat Oct  1 02:55:00 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: rndctl.8,v 1.17 2009/01/04 12:01:43 apb Exp $
+.\	$NetBSD: rndctl.8,v 1.18 2011/10/01 02:55:00 pgoyette Exp $
 .\
 .\ Copyright (c) 1997 Michael Graff
 .\ All rights reserved.
@@ -56,7 +56,7 @@ Disable collection of timing information
 device name or device type.
 .It Fl c
 Enable collection of timing information for the given
-device name of device type.
+device name or device type.
 .It Fl d
 Only the device named
 .Ar devname



CVS commit: src/sbin/rndctl

2011-08-27 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat Aug 27 18:49:00 UTC 2011

Modified Files:
src/sbin/rndctl: rndctl.c

Log Message:
static + const + __dead


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sbin/rndctl/rndctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.c
diff -u src/sbin/rndctl/rndctl.c:1.19 src/sbin/rndctl/rndctl.c:1.20
--- src/sbin/rndctl/rndctl.c:1.19	Sun Apr  5 12:06:33 2009
+++ src/sbin/rndctl/rndctl.c	Sat Aug 27 18:48:59 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rndctl.c,v 1.19 2009/04/05 12:06:33 lukem Exp $	*/
+/*	$NetBSD: rndctl.c,v 1.20 2011/08/27 18:48:59 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1997 Michael Graff.
@@ -31,7 +31,7 @@
 #include sys/cdefs.h
 
 #ifndef lint
-__RCSID($NetBSD: rndctl.c,v 1.19 2009/04/05 12:06:33 lukem Exp $);
+__RCSID($NetBSD: rndctl.c,v 1.20 2011/08/27 18:48:59 joerg Exp $);
 #endif
 
 
@@ -52,7 +52,7 @@
 	u_int32_t a_type;
 } arg_t;
 
-arg_t source_types[] = {
+static const arg_t source_types[] = {
 	{ ???, RND_TYPE_UNKNOWN },
 	{ disk,RND_TYPE_DISK },
 	{ net, RND_TYPE_NET },
@@ -62,13 +62,13 @@
 	{ NULL,  0 }
 };
 
-static void usage(void);
-u_int32_t find_type(char *name);
-const char *find_name(u_int32_t);
-void do_ioctl(rndctl_t *);
-char * strflags(u_int32_t);
-void do_list(int, u_int32_t, char *);
-void do_stats(void);
+__dead static void usage(void);
+static u_int32_t find_type(const char *name);
+static const char *find_name(u_int32_t);
+static void do_ioctl(rndctl_t *);
+static char * strflags(u_int32_t);
+static void do_list(int, u_int32_t, char *);
+static void do_stats(void);
 
 static void
 usage(void)
@@ -81,10 +81,10 @@
 	exit(1);
 }
 
-u_int32_t
-find_type(char *name)
+static u_int32_t
+find_type(const char *name)
 {
-	arg_t *a;
+	const arg_t *a;
 
 	a = source_types;
 
@@ -98,10 +98,10 @@
 	return (0);
 }
 
-const char *
+static const char *
 find_name(u_int32_t type)
 {
-	arg_t *a;
+	const arg_t *a;
 
 	a = source_types;
 
@@ -115,7 +115,7 @@
 	return (???);
 }
 
-void
+static void
 do_ioctl(rndctl_t *rctl)
 {
 	int fd;
@@ -132,7 +132,7 @@
 	close(fd);
 }
 
-char *
+static char *
 strflags(u_int32_t fl)
 {
 	static char str[512];
@@ -156,7 +156,7 @@
 
 #define HEADER Source Bits Type  Flags\n
 
-void
+static void
 do_list(int all, u_int32_t type, char *name)
 {
 	rndstat_t rstat;
@@ -216,8 +216,8 @@
 	close(fd);
 }
 
-void
-do_stats()
+static void
+do_stats(void)
 {
 	rndpoolstat_t rs;
 	int fd;



CVS commit: src/sbin/rndctl

2009-04-05 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sun Apr  5 12:06:33 UTC 2009

Modified Files:
src/sbin/rndctl: rndctl.c

Log Message:
fix sign-compare issues


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sbin/rndctl/rndctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/rndctl/rndctl.c
diff -u src/sbin/rndctl/rndctl.c:1.18 src/sbin/rndctl/rndctl.c:1.19
--- src/sbin/rndctl/rndctl.c:1.18	Thu Nov  6 16:01:54 2008
+++ src/sbin/rndctl/rndctl.c	Sun Apr  5 12:06:33 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: rndctl.c,v 1.18 2008/11/06 16:01:54 apb Exp $	*/
+/*	$NetBSD: rndctl.c,v 1.19 2009/04/05 12:06:33 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1997 Michael Graff.
@@ -31,7 +31,7 @@
 #include sys/cdefs.h
 
 #ifndef lint
-__RCSID($NetBSD: rndctl.c,v 1.18 2008/11/06 16:01:54 apb Exp $);
+__RCSID($NetBSD: rndctl.c,v 1.19 2009/04/05 12:06:33 lukem Exp $);
 #endif
 
 
@@ -163,6 +163,7 @@
 	rndstat_name_t rstat_name;
 	int fd;
 	int res;
+	uint32_t i;
 	u_int32_t start;
 
 	fd = open(/dev/urandom, O_RDONLY, 0644);
@@ -200,14 +201,14 @@
 		if (rstat.count == 0)
 			break;
 
-		for (res = 0; res  rstat.count; res++) {
+		for (i = 0; i  rstat.count; i++) {
 			if (all != 0 ||
-			type == rstat.source[res].type)
+			type == rstat.source[i].type)
 printf(%-16s %10u %-4s %s\n,
-rstat.source[res].name,
-rstat.source[res].total,
-find_name(rstat.source[res].type),
-strflags(rstat.source[res].flags));
+rstat.source[i].name,
+rstat.source[i].total,
+find_name(rstat.source[i].type),
+strflags(rstat.source[i].flags));
 		}
 		start += rstat.count;
 	}