sys/kern/kern_nrandom.c
static void
NANOUP_EVENT(void)
{
	static struct timespec	ACCUM = { 0, 0 };
	static struct timespec	NEXT  = { 0, 0 };
	struct timespec		now;

	nanouptime(&now);
	spin_lock(&rand_spin);
	if ((now.tv_nsec > NEXT.tv_nsec) || (now.tv_sec != NEXT.tv_sec)) {
		/* 
		 * Randomised time-delay: 200e6 - 350e6 ns; 5 - 2.86 Hz. 
		 */
		unsigned long one_mil;
		unsigned long timeDelay;

		one_mil = 1000000UL;	/* 0.001 s */
		timeDelay = (one_mil * 200) + 
			    (((unsigned long)ACCUM.tv_nsec % 151) * one_mil);
		NEXT.tv_nsec = now.tv_nsec + timeDelay;
		NEXT.tv_sec = now.tv_sec;
		ACCUM.tv_nsec += now.tv_nsec;

		/*
		 * The TSC, if present, generally has an even higher
		 * resolution.  Integrate a portion of it into our seed.
		 */
		if (tsc_present)
			ACCUM.tv_nsec ^= rdtsc() & 255;

		IBAA_Seed(ACCUM.tv_nsec);
		L15_Vector((const LByteType *)&ACCUM.tv_nsec,
			   sizeof(ACCUM.tv_nsec));
		++nrandevents;
	}
	spin_unlock(&rand_spin);
}
/*
 * Time-buffered event time-stamping. This is necessary to cutoff higher
 * event frequencies, e.g. an interrupt occuring at 25Hz. In such cases
 * the CPU is being chewed and the timestamps are skewed (minimal variation).
 * Use a nano-second time-delay to limit how many times an Event can occur
 * in one second; <= 5Hz. Note that this doesn't prevent time-stamp skewing.
 * This implementation randmoises the time-delay between events, which adds
 * a layer of security/unpredictability with regard to read-events (a user
 * controlled input).
 *
 * Note: now.tv_nsec should range [ 0 - 1000,000,000 ].
 * Note: "ACCUM" is a security measure (result = capped-unknown + unknown),
 *       and also produces an uncapped (>=32-bit) value.
 */
Time-buffered event time-stamping. This is necessary to cutoff higher
event frequencies, e.g. an interrupt occuring at 25Hz. In such cases
the CPU is being chewed and the timestamps are skewed (minimal variation).
Use a nano-second time-delay to limit how many times an Event can occur
in one second; <= 5Hz. Note that this doesn't prevent time-stamp skewing.
This implementation randmoises the time-delay between events, which adds
a layer of security/unpredictability with regard to read-events (a user
controlled input).


Time - buffered event time - stamping . This is necessary to cutoff higher event frequencies e . g . an interrupt occuring at 25Hz . In such cases the CPU is being chewed and the timestamps are skewed ( minimal variation ) . Use a nano - second time - delay to limit how many times an Event can occur in one second ; < = 5Hz . Note that this doesn ' t prevent time - stamp skewing . This implementation randmoises the time - delay between events which adds a layer of security / unpredictability with regard to read - events ( a user controlled input ) .
static void
NANOUP_EVENT(void)
{
	static struct timespec	ACCUM = { 0, 0 };
	static struct timespec	NEXT  = { 0, 0 };
	struct timespec		now;
	nanouptime(&now);
	spin_lock(&rand_spin);
	if ((now.tv_nsec > NEXT.tv_nsec) || (now.tv_sec != NEXT.tv_sec)) {
		unsigned long one_mil;
		unsigned long timeDelay;
		one_mil = 1000000UL;	
		timeDelay = (one_mil * 200) + 
			    (((unsigned long)ACCUM.tv_nsec % 151) * one_mil);
		NEXT.tv_nsec = now.tv_nsec + timeDelay;
		NEXT.tv_sec = now.tv_sec;
		ACCUM.tv_nsec += now.tv_nsec;
		if (tsc_present)
			ACCUM.tv_nsec ^= rdtsc() & 255;
		IBAA_Seed(ACCUM.tv_nsec);
		L15_Vector((const LByteType *)&ACCUM.tv_nsec,
			   sizeof(ACCUM.tv_nsec));
		++nrandevents;
	}
	spin_unlock(&rand_spin);
}
static void NANOUP_EVENT ( void ) { static struct timespec ACCUM = { 0 , 0 } ; static struct timespec NEXT = { 0 , 0 } ; struct timespec now ; nanouptime ( & now ) ; spin_lock ( & rand_spin ) ; if ( ( now . tv_nsec > NEXT . tv_nsec ) || ( now . tv_sec != NEXT . tv_sec ) ) { unsigned long one_mil ; unsigned long timeDelay ; one_mil = 1000000UL ; timeDelay = ( one_mil * 200 ) + ( ( ( unsigned long ) ACCUM . tv_nsec % 151 ) * one_mil ) ; NEXT . tv_nsec = now . tv_nsec + timeDelay ; NEXT . tv_sec = now . tv_sec ; ACCUM . tv_nsec += now . tv_nsec ; if ( tsc_present ) ACCUM . tv_nsec ^= rdtsc ( ) & 255 ; IBAA_Seed ( ACCUM . tv_nsec ) ; L15_Vector ( ( const LByteType * ) & ACCUM . tv_nsec , sizeof ( ACCUM . tv_nsec ) ) ; ++ nrandevents ; } spin_unlock ( & rand_spin ) ; }
Time-buffered event time-stamping.
Time - buffered event time - stamping .
/* 
		 * Randomised time-delay: 200e6 - 350e6 ns; 5 - 2.86 Hz. 
		 */ /* 0.001 s */ /*
		 * The TSC, if present, generally has an even higher
		 * resolution.  Integrate a portion of it into our seed.
		 */