kernel, random: adaptive entropy gathering

kernel: stop gathering timestamps once the bin is full per interrupt

random: once seeded, retrieve new entropy at a lower rate

Change-Id: I4ce6081d39274728d82c6889686d1650cfd5fc2e
This commit is contained in:
Ben Gras 2013-05-05 23:52:34 +00:00
parent 4ebb889e7a
commit 717425320f
2 changed files with 3 additions and 1 deletions

View File

@ -273,6 +273,7 @@ static void r_random(message *UNUSED(m_ptr))
static struct k_randomness_bin krandom_bin;
u32_t hi, lo;
rand_t r;
int nextperiod = random_isseeded() ? KRANDOM_PERIOD*500 : KRANDOM_PERIOD;
bin = (bin+1) % RANDOM_SOURCES;
@ -285,7 +286,7 @@ static void r_random(message *UNUSED(m_ptr))
random_update(RND_TIMING, &r, 1);
/* Schedule new alarm for next m_random call. */
if (OK != (s=sys_setalarm(KRANDOM_PERIOD, 0)))
if (OK != (s=sys_setalarm(nextperiod, 0)))
printf("RANDOM: sys_setalarm failed: %d\n", s);
}

View File

@ -22,6 +22,7 @@ int source;
unsigned long tsc_high, tsc_low;
source %= RANDOM_SOURCES;
if (rand->bin[source].r_size >= RANDOM_ELEMENTS) return;
r_next= rand->bin[source].r_next;
read_tsc((u32_t *) &tsc_high, (u32_t *) &tsc_low);
rand->bin[source].r_buf[r_next] = tsc_low;