diff options
author | David Shaw <[email protected]> | 2003-05-24 18:31:33 +0000 |
---|---|---|
committer | David Shaw <[email protected]> | 2003-05-24 18:31:33 +0000 |
commit | 29e6411a7bc1657fab1a3c2b847051a30e2247ea (patch) | |
tree | 62aeaf6d2fb67efd3023169a6d82b085a70c3100 /cipher/random.c | |
parent | * mpicoder.c, mpi-inline.h, mpi-inv.c, mpiutil.c, mpih-div.c, (diff) | |
download | gnupg-29e6411a7bc1657fab1a3c2b847051a30e2247ea.tar.gz gnupg-29e6411a7bc1657fab1a3c2b847051a30e2247ea.zip |
* bithelp.h, des.c, random.c, rndlinux.c, sha1.c, blowfish.c, elgamal.c,
rijndael.c, rndunix.c, sha256.c, cast5.c, idea-stub.c, rmd160.c, rndw32.c,
sha512.c, md5.c, rmd160test.c, rsa.c, tiger.c: Edit all preprocessor
instructions to remove whitespace before the '#'. This is not required by
C89, but there are some compilers out there that don't like it.
Diffstat (limited to 'cipher/random.c')
-rw-r--r-- | cipher/random.c | 62 |
1 files changed, 30 insertions, 32 deletions
diff --git a/cipher/random.c b/cipher/random.c index 95d30a77d..c6f748fbb 100644 --- a/cipher/random.c +++ b/cipher/random.c @@ -39,19 +39,19 @@ #include <unistd.h> #include <fcntl.h> #ifdef HAVE_GETHRTIME - #include <sys/times.h> +#include <sys/times.h> #endif #ifdef HAVE_GETTIMEOFDAY - #include <sys/times.h> +#include <sys/times.h> #endif #ifdef HAVE_TIMES - #include <sys/times.h> +#include <sys/times.h> #endif #ifdef HAVE_GETRUSAGE - #include <sys/resource.h> +#include <sys/resource.h> #endif #ifdef __MINGW32__ - #include <process.h> +#include <process.h> #endif #include "util.h" #include "rmd.h" @@ -62,16 +62,16 @@ #include "algorithms.h" #ifndef RAND_MAX /* for SunOS */ - #define RAND_MAX 32767 +#define RAND_MAX 32767 #endif #if SIZEOF_UNSIGNED_LONG == 8 - #define ADD_VALUE 0xa5a5a5a5a5a5a5a5 +#define ADD_VALUE 0xa5a5a5a5a5a5a5a5 #elif SIZEOF_UNSIGNED_LONG == 4 - #define ADD_VALUE 0xa5a5a5a5 +#define ADD_VALUE 0xa5a5a5a5 #else - #error weird size for an unsigned long +#error weird size for an unsigned long #endif #define BLOCKLEN 64 /* hash this amount of bytes */ @@ -84,7 +84,7 @@ #define POOLBLOCKS 30 #define POOLSIZE (POOLBLOCKS*DIGESTLEN) #if (POOLSIZE % SIZEOF_UNSIGNED_LONG) - #error Please make sure that poolsize is a multiple of ulong +#error Please make sure that poolsize is a multiple of ulong #endif #define POOLWORDS (POOLSIZE / SIZEOF_UNSIGNED_LONG) @@ -315,7 +315,7 @@ mix_pool(byte *pool) rmd160_init( &md ); #if DIGESTLEN != 20 - #error must have a digest length of 20 for ripe-md-160 +#error must have a digest length of 20 for ripe-md-160 #endif /* loop over the pool */ pend = pool + POOLSIZE; @@ -632,40 +632,40 @@ fast_random_poll() } /* fall back to the generic function */ - #if defined(HAVE_GETHRTIME) && !defined(HAVE_BROKEN_GETHRTIME) +#if defined(HAVE_GETHRTIME) && !defined(HAVE_BROKEN_GETHRTIME) { hrtime_t tv; /* On some Solaris and HPUX system gethrtime raises an SIGILL, but we * checked this with configure */ tv = gethrtime(); add_randomness( &tv, sizeof(tv), 1 ); } - #elif defined (HAVE_GETTIMEOFDAY) +#elif defined (HAVE_GETTIMEOFDAY) { struct timeval tv; if( gettimeofday( &tv, NULL ) ) BUG(); add_randomness( &tv.tv_sec, sizeof(tv.tv_sec), 1 ); add_randomness( &tv.tv_usec, sizeof(tv.tv_usec), 1 ); } - #elif defined (HAVE_CLOCK_GETTIME) +#elif defined (HAVE_CLOCK_GETTIME) { struct timespec tv; if( clock_gettime( CLOCK_REALTIME, &tv ) == -1 ) BUG(); add_randomness( &tv.tv_sec, sizeof(tv.tv_sec), 1 ); add_randomness( &tv.tv_nsec, sizeof(tv.tv_nsec), 1 ); } - #elif defined (HAVE_TIMES) +#elif defined (HAVE_TIMES) { struct tms buf; if( times( &buf ) == -1 ) BUG(); add_randomness( &buf, sizeof buf, 1 ); } - #endif - #ifdef HAVE_GETRUSAGE - #ifndef RUSAGE_SELF - #ifdef __GCC__ - #warning There is no RUSAGE_SELF on this system - #endif - #else +#endif +#ifdef HAVE_GETRUSAGE +#ifndef RUSAGE_SELF +#ifdef __GCC__ +#warning There is no RUSAGE_SELF on this system +#endif +#else { struct rusage buf; /* QNX/Neutrino does return ENOSYS - so we just ignore it and * add whatever is in buf. In a chroot environment it might not @@ -677,8 +677,8 @@ fast_random_poll() add_randomness( &buf, sizeof buf, 1 ); wipememory( &buf, sizeof buf ); } - #endif - #endif +#endif +#endif /* time and clock are available on all systems - so * we better do it just in case one of the above functions * didn't work */ @@ -727,25 +727,23 @@ gather_faked( void (*add)(const void*, size_t, int), int requester, "it run - it is in no way a strong RNG!\n\n" "DON'T USE ANY DATA GENERATED BY THIS PROGRAM!!\n\n")); initialized=1; - #ifdef HAVE_RAND +#ifdef HAVE_RAND srand(make_timestamp()*getpid()); - #else +#else srandom(make_timestamp()*getpid()); - #endif +#endif } p = buffer = m_alloc( length ); n = length; - #ifdef HAVE_RAND +#ifdef HAVE_RAND while( n-- ) *p++ = ((unsigned)(1 + (int) (256.0*rand()/(RAND_MAX+1.0)))-1); - #else +#else while( n-- ) *p++ = ((unsigned)(1 + (int) (256.0*random()/(RAND_MAX+1.0)))-1); - #endif +#endif add_randomness( buffer, length, requester ); m_free(buffer); return 0; /* okay */ } - - |