Lines Matching full:ec
183 static void jent_apt_init(struct rand_data *ec, unsigned int osr) in jent_apt_init() argument
190 ec->apt_cutoff = jent_apt_cutoff_lookup[ in jent_apt_init()
192 ec->apt_cutoff_permanent = jent_apt_cutoff_permanent_lookup[ in jent_apt_init()
195 ec->apt_cutoff = jent_apt_cutoff_lookup[osr - 1]; in jent_apt_init()
196 ec->apt_cutoff_permanent = in jent_apt_init()
203 * @ec [in] Reference to entropy collector
205 static void jent_apt_reset(struct rand_data *ec, unsigned int delta_masked) in jent_apt_reset() argument
208 ec->apt_count = 0; in jent_apt_reset()
209 ec->apt_base = delta_masked; in jent_apt_reset()
210 ec->apt_observations = 0; in jent_apt_reset()
216 * @ec [in] Reference to entropy collector
219 static void jent_apt_insert(struct rand_data *ec, unsigned int delta_masked) in jent_apt_insert() argument
222 if (!ec->apt_base_set) { in jent_apt_insert()
223 ec->apt_base = delta_masked; in jent_apt_insert()
224 ec->apt_base_set = 1; in jent_apt_insert()
228 if (delta_masked == ec->apt_base) { in jent_apt_insert()
229 ec->apt_count++; in jent_apt_insert()
231 /* Note, ec->apt_count starts with one. */ in jent_apt_insert()
232 if (ec->apt_count >= ec->apt_cutoff_permanent) in jent_apt_insert()
233 ec->health_failure |= JENT_APT_FAILURE_PERMANENT; in jent_apt_insert()
234 else if (ec->apt_count >= ec->apt_cutoff) in jent_apt_insert()
235 ec->health_failure |= JENT_APT_FAILURE; in jent_apt_insert()
238 ec->apt_observations++; in jent_apt_insert()
240 if (ec->apt_observations >= JENT_APT_WINDOW_SIZE) in jent_apt_insert()
241 jent_apt_reset(ec, delta_masked); in jent_apt_insert()
263 * @ec [in] Reference to entropy collector
266 static void jent_rct_insert(struct rand_data *ec, int stuck) in jent_rct_insert() argument
269 ec->rct_count++; in jent_rct_insert()
281 * Note, ec->rct_count (which equals to value B in the pseudo in jent_rct_insert()
287 if ((unsigned int)ec->rct_count >= (60 * ec->osr)) { in jent_rct_insert()
288 ec->rct_count = -1; in jent_rct_insert()
289 ec->health_failure |= JENT_RCT_FAILURE_PERMANENT; in jent_rct_insert()
290 } else if ((unsigned int)ec->rct_count >= (30 * ec->osr)) { in jent_rct_insert()
291 ec->rct_count = -1; in jent_rct_insert()
292 ec->health_failure |= JENT_RCT_FAILURE; in jent_rct_insert()
296 ec->rct_count = 0; in jent_rct_insert()
315 * @ec [in] Reference to entropy collector
322 static int jent_stuck(struct rand_data *ec, __u64 current_delta) in jent_stuck() argument
324 __u64 delta2 = jent_delta(ec->last_delta, current_delta); in jent_stuck()
325 __u64 delta3 = jent_delta(ec->last_delta2, delta2); in jent_stuck()
327 ec->last_delta = current_delta; in jent_stuck()
328 ec->last_delta2 = delta2; in jent_stuck()
334 jent_apt_insert(ec, current_delta); in jent_stuck()
338 jent_rct_insert(ec, 1); in jent_stuck()
343 jent_rct_insert(ec, 0); in jent_stuck()
351 * @ec [in] Reference to entropy collector
360 static unsigned int jent_health_failure(struct rand_data *ec) in jent_health_failure() argument
366 return ec->health_failure; in jent_health_failure()
416 * ec [in] entropy collector
423 static int jent_condition_data(struct rand_data *ec, __u64 time, int stuck) in jent_condition_data() argument
432 ec->rct_count, in jent_condition_data()
433 ec->apt_observations, in jent_condition_data()
434 ec->apt_count, in jent_condition_data()
435 ec->apt_base in jent_condition_data()
438 return jent_hash_time(ec->hash_state, time, (u8 *)&addtl, sizeof(addtl), in jent_condition_data()
457 * to reliably access either L3 or memory, the ec->mem memory must be quite
460 * @ec [in] Reference to the entropy collector with the memory access data -- if
466 static void jent_memaccess(struct rand_data *ec, __u64 loop_cnt) in jent_memaccess() argument
475 if (NULL == ec || NULL == ec->mem) in jent_memaccess()
477 wrap = ec->memblocksize * ec->memblocks; in jent_memaccess()
486 for (i = 0; i < (ec->memaccessloops + acc_loop_cnt); i++) { in jent_memaccess()
487 unsigned char *tmpval = ec->mem + ec->memlocation; in jent_memaccess()
499 ec->memlocation = ec->memlocation + ec->memblocksize - 1; in jent_memaccess()
500 ec->memlocation = ec->memlocation % wrap; in jent_memaccess()
516 * @ec [in] Reference to entropy collector
520 static int jent_measure_jitter(struct rand_data *ec, __u64 *ret_current_delta) in jent_measure_jitter() argument
527 jent_memaccess(ec, 0); in jent_measure_jitter()
534 current_delta = jent_delta(ec->prev_time, time); in jent_measure_jitter()
535 ec->prev_time = time; in jent_measure_jitter()
538 stuck = jent_stuck(ec, current_delta); in jent_measure_jitter()
541 if (jent_condition_data(ec, current_delta, stuck)) in jent_measure_jitter()
555 * @ec [in] Reference to entropy collector
557 static void jent_gen_entropy(struct rand_data *ec) in jent_gen_entropy() argument
565 jent_measure_jitter(ec, NULL); in jent_gen_entropy()
567 while (!jent_health_failure(ec)) { in jent_gen_entropy()
569 if (jent_measure_jitter(ec, NULL)) in jent_gen_entropy()
576 if (++k >= ((DATA_SIZE_BITS + safety_factor) * ec->osr)) in jent_gen_entropy()
591 * @ec [in] Reference to entropy collector
604 int jent_read_entropy(struct rand_data *ec, unsigned char *data, in jent_read_entropy() argument
609 if (!ec) in jent_read_entropy()
615 jent_gen_entropy(ec); in jent_read_entropy()
617 health_test_result = jent_health_failure(ec); in jent_read_entropy()
631 if (jent_entropy_init(0, 0, NULL, ec)) { in jent_read_entropy()
633 ec->health_failure &= in jent_read_entropy()
643 if (jent_read_random_block(ec->hash_state, p, tocopy)) in jent_read_entropy()
711 * If caller provides an allocated ec, reuse it which implies that the in jent_entropy_init()
715 struct rand_data *ec = p_ec; in jent_entropy_init() local
719 if (!ec) { in jent_entropy_init()
720 ec = jent_entropy_collector_alloc(osr, flags, hash_state); in jent_entropy_init()
721 if (!ec) in jent_entropy_init()
726 jent_apt_reset(ec, 0); in jent_entropy_init()
728 ec->apt_base_set = 0; in jent_entropy_init()
730 ec->rct_count = 0; in jent_entropy_init()
732 ec->health_failure &= (~JENT_RCT_FAILURE); in jent_entropy_init()
733 ec->health_failure &= (~JENT_APT_FAILURE); in jent_entropy_init()
766 jent_measure_jitter(ec, &delta); in jent_entropy_init()
767 end_time = ec->prev_time; in jent_entropy_init()
768 start_time = ec->prev_time - delta; in jent_entropy_init()
814 health_test_result = jent_health_failure(ec); in jent_entropy_init()
823 jent_entropy_collector_free(ec); in jent_entropy_init()