Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/x86/x86 Count down bits of entropy, not bits of dat...



details:   https://anonhg.NetBSD.org/src/rev/9d717769d8e9
branches:  trunk
changeset: 934646:9d717769d8e9
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Jun 15 01:24:20 2020 +0000

description:
Count down bits of entropy, not bits of data, in x86 cpu_rng.

Fixes logic in this loop for XSTORERNG on VIA CPUs, which are deemed
to have half the entropy per bit of data as RDSEED on Intel CPUs, so
that it gathers enough entropy on the first request, not on the
second request.

diffstat:

 sys/arch/x86/x86/cpu_rng.c |  5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diffs (26 lines):

diff -r 0148300f78a5 -r 9d717769d8e9 sys/arch/x86/x86/cpu_rng.c
--- a/sys/arch/x86/x86/cpu_rng.c        Mon Jun 15 01:23:44 2020 +0000
+++ b/sys/arch/x86/x86/cpu_rng.c        Mon Jun 15 01:24:20 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_rng.c,v 1.16 2020/06/15 01:23:44 riastradh Exp $ */
+/* $NetBSD: cpu_rng.c,v 1.17 2020/06/15 01:24:20 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -254,7 +254,7 @@
        uint64_t buf[2*N];
        unsigned i, nbits = 0;
 
-       for (; nbytes; nbytes -= MIN(nbytes, sizeof buf)) {
+       while (nbytes) {
                /*
                 * The fraction of outputs this rejects in correct
                 * operation is 1/2^256, which is close enough to zero
@@ -269,6 +269,7 @@
                        nbits = 0;
                }
                rnd_add_data_sync(&cpu_rng_source, buf, sizeof buf, nbits);
+               nbytes -= MIN(MIN(nbytes, sizeof buf), MAX(1, 8*nbits));
        }
 #undef N
 }



Home | Main Index | Thread Index | Old Index