Source-Changes-HG archive

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

[src/trunk]: src/sys/crypto/cprng_fast Tweak cprng_fast_buf to use 32-bit una...



details:   https://anonhg.NetBSD.org/src/rev/0ab9cc7edbb0
branches:  trunk
changeset: 331473:0ab9cc7edbb0
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Aug 11 13:22:16 2014 +0000

description:
Tweak cprng_fast_buf to use 32-bit unaligned writes if possible.

diffstat:

 sys/crypto/cprng_fast/cprng_fast.c |  18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

diffs (40 lines):

diff -r 4ecf4c7d8635 -r 0ab9cc7edbb0 sys/crypto/cprng_fast/cprng_fast.c
--- a/sys/crypto/cprng_fast/cprng_fast.c        Mon Aug 11 13:12:53 2014 +0000
+++ b/sys/crypto/cprng_fast/cprng_fast.c        Mon Aug 11 13:22:16 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cprng_fast.c,v 1.9 2014/08/11 13:12:53 riastradh Exp $ */
+/*     $NetBSD: cprng_fast.c,v 1.10 2014/08/11 13:22:16 riastradh Exp $        */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cprng_fast.c,v 1.9 2014/08/11 13:12:53 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cprng_fast.c,v 1.10 2014/08/11 13:22:16 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -338,11 +338,17 @@
 {
        uint8_t *p = buf;
        uint32_t v;
-       unsigned r;
+       unsigned w, r;
 
-       while (n) {
-               r = MIN(n, 4);
-               n -= r;
+       w = n / sizeof(uint32_t);
+       while (w--) {
+               v = cprng_fast_word(cprng);
+               (void)memcpy(p, &v, 4);
+               p += 4;
+       }
+
+       r = n % sizeof(uint32_t);
+       if (r) {
                v = cprng_fast_word(cprng);
                while (r--) {
                        *p++ = (v & 0xff);



Home | Main Index | Thread Index | Old Index