Lines Matching refs:ec

133 static void jent_apt_reset(struct rand_data *ec, unsigned int delta_masked)  in jent_apt_reset()  argument
136 ec->apt_count = 0; in jent_apt_reset()
137 ec->apt_base = delta_masked; in jent_apt_reset()
138 ec->apt_observations = 0; in jent_apt_reset()
147 static void jent_apt_insert(struct rand_data *ec, unsigned int delta_masked) in jent_apt_insert() argument
150 if (!ec->apt_base_set) { in jent_apt_insert()
151 ec->apt_base = delta_masked; in jent_apt_insert()
152 ec->apt_base_set = 1; in jent_apt_insert()
156 if (delta_masked == ec->apt_base) { in jent_apt_insert()
157 ec->apt_count++; in jent_apt_insert()
159 if (ec->apt_count >= JENT_APT_CUTOFF) in jent_apt_insert()
160 ec->health_failure = 1; in jent_apt_insert()
163 ec->apt_observations++; in jent_apt_insert()
165 if (ec->apt_observations >= JENT_APT_WINDOW_SIZE) in jent_apt_insert()
166 jent_apt_reset(ec, delta_masked); in jent_apt_insert()
191 static void jent_rct_insert(struct rand_data *ec, int stuck) in jent_rct_insert() argument
197 if (ec->rct_count < 0) in jent_rct_insert()
201 ec->rct_count++; in jent_rct_insert()
217 if ((unsigned int)ec->rct_count >= (31 * ec->osr)) { in jent_rct_insert()
218 ec->rct_count = -1; in jent_rct_insert()
219 ec->health_failure = 1; in jent_rct_insert()
222 ec->rct_count = 0; in jent_rct_insert()
235 static int jent_rct_failure(struct rand_data *ec) in jent_rct_failure() argument
237 if (ec->rct_count < 0) in jent_rct_failure()
264 static int jent_stuck(struct rand_data *ec, __u64 current_delta) in jent_stuck() argument
266 __u64 delta2 = jent_delta(ec->last_delta, current_delta); in jent_stuck()
267 __u64 delta3 = jent_delta(ec->last_delta2, delta2); in jent_stuck()
270 ec->last_delta = current_delta; in jent_stuck()
271 ec->last_delta2 = delta2; in jent_stuck()
277 jent_apt_insert(ec, delta_masked); in jent_stuck()
281 jent_rct_insert(ec, 1); in jent_stuck()
286 jent_rct_insert(ec, 0); in jent_stuck()
300 static int jent_health_failure(struct rand_data *ec) in jent_health_failure() argument
306 return ec->health_failure; in jent_health_failure()
325 static __u64 jent_loop_shuffle(struct rand_data *ec, in jent_loop_shuffle() argument
338 if (ec) in jent_loop_shuffle()
339 time ^= ec->data; in jent_loop_shuffle()
381 static void jent_lfsr_time(struct rand_data *ec, __u64 time, __u64 loop_cnt, in jent_lfsr_time() argument
390 jent_loop_shuffle(ec, MAX_FOLD_LOOP_BIT, MIN_FOLD_LOOP_BIT); in jent_lfsr_time()
399 new = ec->data; in jent_lfsr_time()
435 ec->data = new; in jent_lfsr_time()
462 static void jent_memaccess(struct rand_data *ec, __u64 loop_cnt) in jent_memaccess() argument
469 jent_loop_shuffle(ec, MAX_ACC_LOOP_BIT, MIN_ACC_LOOP_BIT); in jent_memaccess()
471 if (NULL == ec || NULL == ec->mem) in jent_memaccess()
473 wrap = ec->memblocksize * ec->memblocks; in jent_memaccess()
482 for (i = 0; i < (ec->memaccessloops + acc_loop_cnt); i++) { in jent_memaccess()
483 unsigned char *tmpval = ec->mem + ec->memlocation; in jent_memaccess()
495 ec->memlocation = ec->memlocation + ec->memblocksize - 1; in jent_memaccess()
496 ec->memlocation = ec->memlocation % wrap; in jent_memaccess()
516 static int jent_measure_jitter(struct rand_data *ec) in jent_measure_jitter() argument
523 jent_memaccess(ec, 0); in jent_measure_jitter()
530 current_delta = jent_delta(ec->prev_time, time); in jent_measure_jitter()
531 ec->prev_time = time; in jent_measure_jitter()
534 stuck = jent_stuck(ec, current_delta); in jent_measure_jitter()
537 jent_lfsr_time(ec, current_delta, 0, stuck); in jent_measure_jitter()
548 static void jent_gen_entropy(struct rand_data *ec) in jent_gen_entropy() argument
553 jent_measure_jitter(ec); in jent_gen_entropy()
557 if (jent_measure_jitter(ec)) in jent_gen_entropy()
564 if (++k >= (DATA_SIZE_BITS * ec->osr)) in jent_gen_entropy()
592 int jent_read_entropy(struct rand_data *ec, unsigned char *data, in jent_read_entropy() argument
597 if (!ec) in jent_read_entropy()
603 jent_gen_entropy(ec); in jent_read_entropy()
605 if (jent_health_failure(ec)) { in jent_read_entropy()
608 if (jent_rct_failure(ec)) in jent_read_entropy()
624 jent_apt_reset(ec, 0); in jent_read_entropy()
625 ec->apt_base_set = 0; in jent_read_entropy()
628 ec->rct_count = 0; in jent_read_entropy()
631 ec->health_failure = 0; in jent_read_entropy()
644 jent_memcpy(p, &ec->data, tocopy); in jent_read_entropy()
707 struct rand_data ec = { 0 }; in jent_entropy_init() local
710 ec.osr = 1; in jent_entropy_init()
747 ec.prev_time = time; in jent_entropy_init()
748 jent_lfsr_time(&ec, time, 0, 0); in jent_entropy_init()
763 stuck = jent_stuck(&ec, delta); in jent_entropy_init()
789 jent_apt_reset(&ec, in jent_entropy_init()
791 if (jent_health_failure(&ec)) in jent_entropy_init()
797 if (jent_rct_failure(&ec)) in jent_entropy_init()