Lines Matching refs:ec

182 static void jent_apt_init(struct rand_data *ec, unsigned int osr)
189 ec->apt_cutoff = jent_apt_cutoff_lookup[
191 ec->apt_cutoff_permanent = jent_apt_cutoff_permanent_lookup[
194 ec->apt_cutoff = jent_apt_cutoff_lookup[osr - 1];
195 ec->apt_cutoff_permanent =
202 * @ec [in] Reference to entropy collector
204 static void jent_apt_reset(struct rand_data *ec, unsigned int delta_masked)
207 ec->apt_count = 0;
208 ec->apt_base = delta_masked;
209 ec->apt_observations = 0;
215 * @ec [in] Reference to entropy collector
218 static void jent_apt_insert(struct rand_data *ec, unsigned int delta_masked)
221 if (!ec->apt_base_set) {
222 ec->apt_base = delta_masked;
223 ec->apt_base_set = 1;
227 if (delta_masked == ec->apt_base) {
228 ec->apt_count++;
230 /* Note, ec->apt_count starts with one. */
231 if (ec->apt_count >= ec->apt_cutoff_permanent)
232 ec->health_failure |= JENT_APT_FAILURE_PERMANENT;
233 else if (ec->apt_count >= ec->apt_cutoff)
234 ec->health_failure |= JENT_APT_FAILURE;
237 ec->apt_observations++;
239 if (ec->apt_observations >= JENT_APT_WINDOW_SIZE)
240 jent_apt_reset(ec, delta_masked);
262 * @ec [in] Reference to entropy collector
265 static void jent_rct_insert(struct rand_data *ec, int stuck)
268 ec->rct_count++;
280 * Note, ec->rct_count (which equals to value B in the pseudo
286 if ((unsigned int)ec->rct_count >= (60 * ec->osr)) {
287 ec->rct_count = -1;
288 ec->health_failure |= JENT_RCT_FAILURE_PERMANENT;
289 } else if ((unsigned int)ec->rct_count >= (30 * ec->osr)) {
290 ec->rct_count = -1;
291 ec->health_failure |= JENT_RCT_FAILURE;
295 ec->rct_count = 0;
314 * @ec [in] Reference to entropy collector
321 static int jent_stuck(struct rand_data *ec, __u64 current_delta)
323 __u64 delta2 = jent_delta(ec->last_delta, current_delta);
324 __u64 delta3 = jent_delta(ec->last_delta2, delta2);
326 ec->last_delta = current_delta;
327 ec->last_delta2 = delta2;
333 jent_apt_insert(ec, current_delta);
337 jent_rct_insert(ec, 1);
342 jent_rct_insert(ec, 0);
350 * @ec [in] Reference to entropy collector
359 static unsigned int jent_health_failure(struct rand_data *ec)
365 return ec->health_failure;
415 * ec [in] entropy collector
422 static int jent_condition_data(struct rand_data *ec, __u64 time, int stuck)
431 ec->rct_count,
432 ec->apt_observations,
433 ec->apt_count,
434 ec->apt_base
437 return jent_hash_time(ec->hash_state, time, (u8 *)&addtl, sizeof(addtl),
456 * to reliably access either L3 or memory, the ec->mem memory must be quite
459 * @ec [in] Reference to the entropy collector with the memory access data -- if
465 static void jent_memaccess(struct rand_data *ec, __u64 loop_cnt)
474 if (NULL == ec || NULL == ec->mem)
476 wrap = ec->memblocksize * ec->memblocks;
485 for (i = 0; i < (ec->memaccessloops + acc_loop_cnt); i++) {
486 unsigned char *tmpval = ec->mem + ec->memlocation;
498 ec->memlocation = ec->memlocation + ec->memblocksize - 1;
499 ec->memlocation = ec->memlocation % wrap;
515 * @ec [in] Reference to entropy collector
519 static int jent_measure_jitter(struct rand_data *ec, __u64 *ret_current_delta)
526 jent_memaccess(ec, 0);
533 current_delta = jent_delta(ec->prev_time, time);
534 ec->prev_time = time;
537 stuck = jent_stuck(ec, current_delta);
540 if (jent_condition_data(ec, current_delta, stuck))
554 * @ec [in] Reference to entropy collector
556 static void jent_gen_entropy(struct rand_data *ec)
564 jent_measure_jitter(ec, NULL);
566 while (!jent_health_failure(ec)) {
568 if (jent_measure_jitter(ec, NULL))
575 if (++k >= ((DATA_SIZE_BITS + safety_factor) * ec->osr))
590 * @ec [in] Reference to entropy collector
603 int jent_read_entropy(struct rand_data *ec, unsigned char *data,
608 if (!ec)
614 jent_gen_entropy(ec);
616 health_test_result = jent_health_failure(ec);
630 if (jent_entropy_init(0, 0, NULL, ec)) {
632 ec->health_failure &=
645 if (jent_read_random_block(ec->hash_state, p, tocopy))
713 * If caller provides an allocated ec, reuse it which implies that the
717 struct rand_data *ec = p_ec;
721 if (!ec) {
722 ec = jent_entropy_collector_alloc(osr, flags, hash_state);
723 if (!ec)
728 jent_apt_reset(ec, 0);
730 ec->apt_base_set = 0;
732 ec->rct_count = 0;
734 ec->health_failure &= (~JENT_RCT_FAILURE);
735 ec->health_failure &= (~JENT_APT_FAILURE);
768 jent_measure_jitter(ec, &delta);
769 end_time = ec->prev_time;
770 start_time = ec->prev_time - delta;
816 health_test_result = jent_health_failure(ec);
825 jent_entropy_collector_free(ec);