FreeBSD/sys/dev/random/yarrow.c
/* Process a single stochastic event off the harvest queue */
Process a single stochastic event off the harvest queue
Process a single stochastic event off the harvest queue
static void
random_yarrow_process_event(struct harvest_event *event)
{
	u_int pl, overthreshhold[RANDOM_YARROW_NPOOLS];
	enum random_entropy_source src;
	RANDOM_RESEED_LOCK();
	pl = event->he_destination % RANDOM_YARROW_NPOOLS;
	randomdev_hash_iterate(&yarrow_state.ys_pool[pl].ysp_hash, event, sizeof(*event));
	yarrow_state.ys_pool[pl].ysp_source_bits[event->he_source] += event->he_bits;
	for (pl = RANDOM_YARROW_FAST; pl <= RANDOM_YARROW_SLOW; pl++) {
		overthreshhold[pl] = 0;
		for (src = RANDOM_START; src < ENTROPYSOURCE; src++) {
			if (yarrow_state.ys_pool[pl].ysp_source_bits[src] > yarrow_state.ys_pool[pl].ysp_thresh)
				overthreshhold[pl]++;
		}
	}
	if (overthreshhold[RANDOM_YARROW_SLOW] >= yarrow_state.ys_slowoverthresh)
		random_yarrow_reseed_internal(RANDOM_YARROW_SLOW);
	else if (overthreshhold[RANDOM_YARROW_FAST] > 0 && yarrow_state.ys_seeded)
		random_yarrow_reseed_internal(RANDOM_YARROW_FAST);
	explicit_bzero(event, sizeof(*event));
	RANDOM_RESEED_UNLOCK();
}
static void random_yarrow_process_event ( struct harvest_event * event ) { u_int pl , overthreshhold [ RANDOM_YARROW_NPOOLS ] ; enum random_entropy_source src ; RANDOM_RESEED_LOCK ( ) ; pl = event -> he_destination % RANDOM_YARROW_NPOOLS ; randomdev_hash_iterate ( & yarrow_state . ys_pool [ pl ] . ysp_hash , event , sizeof ( * event ) ) ; yarrow_state . ys_pool [ pl ] . ysp_source_bits [ event -> he_source ] += event -> he_bits ; for ( pl = RANDOM_YARROW_FAST ; pl <= RANDOM_YARROW_SLOW ; pl ++ ) { overthreshhold [ pl ] = 0 ; for ( src = RANDOM_START ; src < ENTROPYSOURCE ; src ++ ) { if ( yarrow_state . ys_pool [ pl ] . ysp_source_bits [ src ] > yarrow_state . ys_pool [ pl ] . ysp_thresh ) overthreshhold [ pl ] ++ ; } } if ( overthreshhold [ RANDOM_YARROW_SLOW ] >= yarrow_state . ys_slowoverthresh ) random_yarrow_reseed_internal ( RANDOM_YARROW_SLOW ) ; else if ( overthreshhold [ RANDOM_YARROW_FAST ] > 0 && yarrow_state . ys_seeded ) random_yarrow_reseed_internal ( RANDOM_YARROW_FAST ) ; explicit_bzero ( event , sizeof ( * event ) ) ; RANDOM_RESEED_UNLOCK ( ) ; }
Process a single stochastic event off the harvest queue
Process a single stochastic event off the harvest queue
/*
	 * Accumulate the event into the appropriate pool
	 * where each event carries the destination information.
	 * We lock against pool state modification which can happen
	 * during accumulation/reseeding and reading/regating
	 */ /* Count the over-threshold sources in each pool */ /*
	 * If enough slow sources are over threshold, then slow reseed
	 * else if any fast source over threshold, then fast reseed.
	 */