Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-9]: src/sbin/rndctl Pull up following revision(s) (requested by r...



details:   https://anonhg.NetBSD.org/src/rev/57173c163e72
branches:  netbsd-9
changeset: 936000:57173c163e72
user:      martin <martin%NetBSD.org@localhost>
date:      Wed Jul 15 13:44:08 2020 +0000

description:
Pull up following revision(s) (requested by riastradh in ticket #1006):

        sbin/rndctl/rndctl.c: revision 1.32
        sbin/rndctl/rndctl.c: revision 1.33

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.

Sort includes.

diffstat:

 sbin/rndctl/rndctl.c |  39 ++++++++++++++++++++++++---------------
 1 files changed, 24 insertions(+), 15 deletions(-)

diffs (79 lines):

diff -r d59cb37cd3ac -r 57173c163e72 sbin/rndctl/rndctl.c
--- a/sbin/rndctl/rndctl.c      Wed Jul 15 13:30:20 2020 +0000
+++ b/sbin/rndctl/rndctl.c      Wed Jul 15 13:44:08 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rndctl.c,v 1.30.18.1 2019/12/17 12:45:30 martin Exp $  */
+/*     $NetBSD: rndctl.c,v 1.30.18.2 2020/07/15 13:44:08 martin Exp $  */
 
 /*-
  * Copyright (c) 1997 Michael Graff.
@@ -28,29 +28,28 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #include <sys/cdefs.h>
-#include <sys/types.h>
-#include <sha1.h>
-
 #ifndef lint
-__RCSID("$NetBSD: rndctl.c,v 1.30.18.1 2019/12/17 12:45:30 martin Exp $");
+__RCSID("$NetBSD: rndctl.c,v 1.30.18.2 2020/07/15 13:44:08 martin Exp $");
 #endif
 
-
+#include <sys/param.h>
 #include <sys/types.h>
+#include <sys/endian.h>
 #include <sys/ioctl.h>
-#include <sys/param.h>
 #include <sys/rndio.h>
 #include <sys/sha3.h>
 
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <paths.h>
+#include <sha1.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <err.h>
-#include <paths.h>
-#include <string.h>
 
 typedef struct {
        const char *a_name;
@@ -192,9 +191,8 @@
            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(&s);
        SHA1Update(&s, (const uint8_t *)&rs.entropy, sizeof(rs.entropy));
@@ -309,6 +307,17 @@
                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;



Home | Main Index | Thread Index | Old Index