-/* Used to detect whether we've already been initialized */
-static int gRandomInstalled = 0;
-static PrngRef gPrngRef;
-static int gRandomError = 1;
-static mutex_t *gYarrowMutex = 0;
-
-#define RESEED_TICKS 50 /* how long a reseed operation can take */
-
-
-/*
- *Initialize ONLY the Yarrow generator.
- */
-void PreliminarySetup( void )
-{
- prng_error_status perr;
- struct timeval tt;
- char buffer [16];
-
- /* create a Yarrow object */
- perr = prngInitialize(&gPrngRef);
- if (perr != 0) {
- printf ("Couldn't initialize Yarrow, /dev/random will not work.\n");
- return;
- }
-
- /* clear the error flag, reads and write should then work */
- gRandomError = 0;
-
- /* get a little non-deterministic data as an initial seed. */
- microtime(&tt);
-
- /*
- * So how much of the system clock is entropic?
- * It's hard to say, but assume that at least the
- * least significant byte of a 64 bit structure
- * is entropic. It's probably more, how can you figure
- * the exact time the user turned the computer on, for example.
- */
- perr = prngInput(gPrngRef, (BYTE*) &tt, sizeof (tt), SYSTEM_SOURCE, 8);
- if (perr != 0) {
- /* an error, complain */
- printf ("Couldn't seed Yarrow.\n");
- return;
- }
-
- /* turn the data around */
- perr = prngOutput(gPrngRef, (BYTE*) buffer, sizeof (buffer));
-
- /* and scramble it some more */
- perr = prngForceReseed(gPrngRef, RESEED_TICKS);
-
- /* make a mutex to control access */
- gYarrowMutex = mutex_alloc(0);
-}