security/nss/lib/freebl/sysrand.c

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifdef FREEBL_NO_DEPEND
     6 #include "stubs.h"
     7 #endif
     9 #include "seccomon.h"
    11 #ifndef XP_WIN
    12 static size_t rng_systemFromNoise(unsigned char *dest, size_t maxLen);
    13 #endif
    15 #if defined(XP_UNIX) || defined(XP_BEOS)
    16 #include "unix_rand.c"
    17 #endif
    18 #ifdef XP_WIN
    19 #include "win_rand.c"
    20 #endif
    21 #ifdef XP_OS2
    22 #include "os2_rand.c"
    23 #endif
    25 #ifndef XP_WIN
    26 /*
    27  * Normal RNG_SystemRNG() isn't available, use the system noise to collect
    28  * the required amount of entropy.
    29  */
    30 static size_t 
    31 rng_systemFromNoise(unsigned char *dest, size_t maxLen) 
    32 {
    33    size_t retBytes = maxLen;
    35    while (maxLen) {
    36 	size_t nbytes = RNG_GetNoise(dest, maxLen);
    38 	PORT_Assert(nbytes != 0);
    40 	dest += nbytes;
    41 	maxLen -= nbytes;
    43 	/* some hw op to try to introduce more entropy into the next
    44 	 * RNG_GetNoise call */
    45 	rng_systemJitter();
    46    }
    47    return retBytes;
    48 }
    49 #endif

mercurial