Source-Changes-HG archive

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

[src/trunk]: src/sys Fix rnd_add_* to conform to manual page: allow addition ...



details:   https://anonhg.NetBSD.org/src/rev/f0d85541fd7f
branches:  trunk
changeset: 789636:f0d85541fd7f
user:      tls <tls%NetBSD.org@localhost>
date:      Thu Aug 29 01:04:49 2013 +0000

description:
Fix rnd_add_* to conform to manual page: allow addition of entropy
with NULL source.

diffstat:

 sys/kern/kern_rndpool.c |  11 ++++++-----
 sys/kern/kern_rndq.c    |  12 +++++++++---
 sys/sys/rnd.h           |   9 ++++++---
 3 files changed, 21 insertions(+), 11 deletions(-)

diffs (102 lines):

diff -r ba82f524ebe5 -r f0d85541fd7f sys/kern/kern_rndpool.c
--- a/sys/kern/kern_rndpool.c   Wed Aug 28 23:40:43 2013 +0000
+++ b/sys/kern/kern_rndpool.c   Thu Aug 29 01:04:49 2013 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: kern_rndpool.c,v 1.4 2013/06/13 19:18:00 tls Exp $        */
+/*      $NetBSD: kern_rndpool.c,v 1.5 2013/08/29 01:04:49 tls Exp $        */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_rndpool.c,v 1.4 2013/06/13 19:18:00 tls Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rndpool.c,v 1.5 2013/08/29 01:04:49 tls Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -187,15 +187,16 @@
  * Add a buffer's worth of data to the pool.
  */
 void
-rndpool_add_data(rndpool_t *rp, void *p, u_int32_t len, u_int32_t entropy)
+rndpool_add_data(rndpool_t *rp,
+                const void * const p, u_int32_t len, u_int32_t entropy)
 {
        u_int32_t val;
-       u_int8_t *buf;
+       const u_int8_t * buf;
 
        buf = p;
 
        for (; len > 3; len -= 4) {
-               val = *((u_int32_t *)buf);
+               val = *((const u_int32_t *)buf);
 
                rndpool_add_one_word(rp, val);
                buf += 4;
diff -r ba82f524ebe5 -r f0d85541fd7f sys/kern/kern_rndq.c
--- a/sys/kern/kern_rndq.c      Wed Aug 28 23:40:43 2013 +0000
+++ b/sys/kern/kern_rndq.c      Thu Aug 29 01:04:49 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_rndq.c,v 1.20 2013/08/28 23:40:43 tls Exp $       */
+/*     $NetBSD: kern_rndq.c,v 1.21 2013/08/29 01:04:49 tls Exp $       */
 
 /*-
  * Copyright (c) 1997-2013 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.20 2013/08/28 23:40:43 tls Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.21 2013/08/29 01:04:49 tls Exp $");
 
 #include <sys/param.h>
 #include <sys/ioctl.h>
@@ -651,7 +651,13 @@
         * itself, random.  Don't estimate entropy based on
         * timestamp, just directly add the data.
         */
-       rnd_add_data_ts(rs, data, len, entropy, rnd_counter());
+       if (__predict_false(rs == NULL)) {
+               mutex_spin_enter(&rndpool_mtx);
+               rndpool_add_data(&rnd_pool, data, len, entropy);
+               mutex_spin_exit(&rndpool_mtx);
+       } else {
+               rnd_add_data_ts(rs, data, len, entropy, rnd_counter());
+       }
 }
 
 static void
diff -r ba82f524ebe5 -r f0d85541fd7f sys/sys/rnd.h
--- a/sys/sys/rnd.h     Wed Aug 28 23:40:43 2013 +0000
+++ b/sys/sys/rnd.h     Thu Aug 29 01:04:49 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rnd.h,v 1.39 2013/07/01 15:22:00 riastradh Exp $       */
+/*     $NetBSD: rnd.h,v 1.40 2013/08/29 01:04:49 tls Exp $     */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -155,7 +155,8 @@
 void           rndpool_increment_entropy_count(rndpool_t *, uint32_t);
 uint32_t       *rndpool_get_pool(rndpool_t *);
 uint32_t       rndpool_get_poolsize(void);
-void           rndpool_add_data(rndpool_t *, void *, uint32_t, uint32_t);
+void           rndpool_add_data(rndpool_t *,
+                                const void *const , uint32_t, uint32_t);
 uint32_t       rndpool_extract_data(rndpool_t *, void *, uint32_t, uint32_t);
 void           rnd_init(void);
 void           rnd_init_softint(void);
@@ -173,8 +174,10 @@
 static inline void
 rnd_add_uint32(krndsource_t *kr, uint32_t val)
 {
-       if (RND_ENABLED(kr)) {
+       if (__predict_true(kr) && RND_ENABLED(kr)) {
                _rnd_add_uint32(kr, val);
+       } else {
+               rnd_add_data(NULL, &val, sizeof(val), 0);
        }
 }
 



Home | Main Index | Thread Index | Old Index