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