1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/lib/freebl/sysrand.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,49 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifdef FREEBL_NO_DEPEND 1.9 +#include "stubs.h" 1.10 +#endif 1.11 + 1.12 +#include "seccomon.h" 1.13 + 1.14 +#ifndef XP_WIN 1.15 +static size_t rng_systemFromNoise(unsigned char *dest, size_t maxLen); 1.16 +#endif 1.17 + 1.18 +#if defined(XP_UNIX) || defined(XP_BEOS) 1.19 +#include "unix_rand.c" 1.20 +#endif 1.21 +#ifdef XP_WIN 1.22 +#include "win_rand.c" 1.23 +#endif 1.24 +#ifdef XP_OS2 1.25 +#include "os2_rand.c" 1.26 +#endif 1.27 + 1.28 +#ifndef XP_WIN 1.29 +/* 1.30 + * Normal RNG_SystemRNG() isn't available, use the system noise to collect 1.31 + * the required amount of entropy. 1.32 + */ 1.33 +static size_t 1.34 +rng_systemFromNoise(unsigned char *dest, size_t maxLen) 1.35 +{ 1.36 + size_t retBytes = maxLen; 1.37 + 1.38 + while (maxLen) { 1.39 + size_t nbytes = RNG_GetNoise(dest, maxLen); 1.40 + 1.41 + PORT_Assert(nbytes != 0); 1.42 + 1.43 + dest += nbytes; 1.44 + maxLen -= nbytes; 1.45 + 1.46 + /* some hw op to try to introduce more entropy into the next 1.47 + * RNG_GetNoise call */ 1.48 + rng_systemJitter(); 1.49 + } 1.50 + return retBytes; 1.51 +} 1.52 +#endif