diff options
Diffstat (limited to 'openssl/crypto/rand/rand_nw.c')
-rw-r--r-- | openssl/crypto/rand/rand_nw.c | 110 |
1 files changed, 53 insertions, 57 deletions
diff --git a/openssl/crypto/rand/rand_nw.c b/openssl/crypto/rand/rand_nw.c index 8d5b8d2e3..55ffe9ad5 100644 --- a/openssl/crypto/rand/rand_nw.c +++ b/openssl/crypto/rand/rand_nw.c @@ -5,21 +5,21 @@ * This package is an SSL implementation written * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. - * + * * This library is free for commercial and non-commercial use as long as * the following conditions are aheared to. The following conditions * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * + * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -34,10 +34,10 @@ * Eric Young (eay@cryptsoft.com)" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from + * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * + * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -49,7 +49,7 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * + * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence @@ -63,7 +63,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -115,69 +115,65 @@ #if defined (OPENSSL_SYS_NETWARE) -#if defined(NETWARE_LIBC) -#include <nks/thread.h> -#else -#include <nwthread.h> -#endif +# if defined(NETWARE_LIBC) +# include <nks/thread.h> +# else +# include <nwthread.h> +# endif extern int GetProcessSwitchCount(void); -#if !defined(NETWARE_LIBC) || (CURRENT_NDK_THRESHOLD < 509220000) -extern void *RunningProcess; /* declare here same as found in newer NDKs */ +# if !defined(NETWARE_LIBC) || (CURRENT_NDK_THRESHOLD < 509220000) +extern void *RunningProcess; /* declare here same as found in newer NDKs */ extern unsigned long GetSuperHighResolutionTimer(void); -#endif +# endif - /* the FAQ indicates we need to provide at least 20 bytes (160 bits) of seed - */ + /* + * the FAQ indicates we need to provide at least 20 bytes (160 bits) of + * seed + */ int RAND_poll(void) { - unsigned long l; - unsigned long tsc; - int i; + unsigned long l; + unsigned long tsc; + int i; - /* There are several options to gather miscellaneous data - * but for now we will loop checking the time stamp counter (rdtsc) and - * the SuperHighResolutionTimer. Each iteration will collect 8 bytes - * of data but it is treated as only 1 byte of entropy. The call to - * ThreadSwitchWithDelay() will introduce additional variability into - * the data returned by rdtsc. - * - * Applications can agument the seed material by adding additional - * stuff with RAND_add() and should probably do so. - */ - l = GetProcessSwitchCount(); - RAND_add(&l,sizeof(l),1); - - /* need to cast the void* to unsigned long here */ - l = (unsigned long)RunningProcess; - RAND_add(&l,sizeof(l),1); + /* + * There are several options to gather miscellaneous data but for now we + * will loop checking the time stamp counter (rdtsc) and the + * SuperHighResolutionTimer. Each iteration will collect 8 bytes of data + * but it is treated as only 1 byte of entropy. The call to + * ThreadSwitchWithDelay() will introduce additional variability into the + * data returned by rdtsc. Applications can agument the seed material by + * adding additional stuff with RAND_add() and should probably do so. + */ + l = GetProcessSwitchCount(); + RAND_add(&l, sizeof(l), 1); - for( i=2; i<ENTROPY_NEEDED; i++) - { -#ifdef __MWERKS__ - asm - { - rdtsc - mov tsc, eax - } -#elif defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) - asm volatile("rdtsc":"=a"(tsc)::"edx"); -#endif + /* need to cast the void* to unsigned long here */ + l = (unsigned long)RunningProcess; + RAND_add(&l, sizeof(l), 1); - RAND_add(&tsc, sizeof(tsc), 1); + for (i = 2; i < ENTROPY_NEEDED; i++) { +# ifdef __MWERKS__ + asm { + rdtsc mov tsc, eax} +# elif defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) + asm volatile ("rdtsc":"=a" (tsc)::"edx"); +# endif + + RAND_add(&tsc, sizeof(tsc), 1); - l = GetSuperHighResolutionTimer(); - RAND_add(&l, sizeof(l), 0); + l = GetSuperHighResolutionTimer(); + RAND_add(&l, sizeof(l), 0); # if defined(NETWARE_LIBC) - NXThreadYield(); -# else /* NETWARE_CLIB */ - ThreadSwitchWithDelay(); + NXThreadYield(); +# else /* NETWARE_CLIB */ + ThreadSwitchWithDelay(); # endif - } + } - return 1; + return 1; } -#endif - +#endif |