--- pgp/src/random.c 2018/04/24 16:39:11 1.1.1.4 +++ pgp/src/random.c 2018/04/24 16:40:01 1.1.1.5 @@ -35,6 +35,11 @@ #include #include +#if defined(linux) +/* linux >= 0.99.9 has microsecond resolution gettimeofday() */ +#define USE_GETTIMEOFDAY +#endif + #ifdef NO_ITIMER /* Some systems lie about itimer */ #undef ITIMER_REAL #endif @@ -118,17 +123,18 @@ static long pseudorand(void) /* Prototypes for kbhit() (whether the keyboard has been hit) and getch() (like getchar() but no echo, no buffering). Not available under some implementations */ -#ifdef MSDOS +#if defined(MSDOS) && !defined(__GO32__) #include typedef word16 fastcnt_t; #else typedef word32 fastcnt_t; +#endif /* !MSDOS || __GO32__ */ + #ifdef VMS int putch(int); #else #define putch(c) putc(c, stderr) #endif -#endif /* !MSDOS */ #ifdef DEBUG #define DEBUGprintf1(x) fprintf(stderr,x) @@ -310,6 +316,15 @@ static void capturecounter(void) #ifdef UNIX #define HW_TIMER 1 /* using hardware timer */ +#ifdef USE_GETTIMEOFDAY + { static struct timeval tv; + gettimeofday(&tv, NULL); + /* divide by 64 (we can at least expect a 60Hz clock) */ + fastcounter = tv.tv_usec / (1000000/64) + tv.tv_sec * 64; + random_xtra = (byte *) &tv; +#define XTRA_BYTES (sizeof(struct timeval)) + } +#else /* !USE_GETTIMEOFDAY */ #ifdef ITIMER_REAL { static struct itimerval it; getitimer(ITIMER_REAL, &it); @@ -336,6 +351,7 @@ static void capturecounter(void) #define XTRA_BYTES (sizeof(struct tms)) } #endif /* !ITIMER_REAL */ +#endif /* !USE_GETTIMEOFDAY */ #endif /* UNIX */ dt = fastcounter - lastcounter; @@ -383,9 +399,11 @@ static void capturecounter(void) seedBuffer[ 3 ] = accum1 & 0xFF; seedBuffer[ 4 ] = accum1 >> 8; #endif +#ifndef USE_GETTIMEOFDAY accum1 = ( int ) time(NULL); /* seconds */ seedBuffer[ 5 ] = accum1 & 0xFF; seedBuffer[ 6 ] = accum1 >> 8; +#endif /* !USE_GETTIMEOFDAY */ #ifdef XTRA_BYTES /* add some extra "random" stuff */ memcpy(seedBuffer+16, random_xtra, XTRA_BYTES); #endif @@ -436,7 +454,7 @@ static void randstir(byte *pool) with MD5 as the block cipher */ for(i = 0; i < POOLSIZE; i += 16) { - Transform((unsigned long *) iv, (unsigned long *) seedBuffer); + Transform((UINT4 *) iv, (UINT4 *) seedBuffer); for(j = 0; j < 16; j++) pool[i+j] ^= iv[j]; memcpy(iv, pool+i, 16);