From: Ben Gras Date: Sun, 5 May 2013 23:52:34 +0000 (+0000) Subject: kernel, random: adaptive entropy gathering X-Git-Tag: v3.3.0~993 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=717425320fdbeac66e46b7248c0c452f184d621e;p=minix.git 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 --- diff --git a/drivers/random/main.c b/drivers/random/main.c index f2a65db8c..18ed36d34 100644 --- a/drivers/random/main.c +++ b/drivers/random/main.c @@ -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); } diff --git a/lib/libsys/arch/i386/get_randomness.c b/lib/libsys/arch/i386/get_randomness.c index 720f67472..0a7f9e9d5 100644 --- a/lib/libsys/arch/i386/get_randomness.c +++ b/lib/libsys/arch/i386/get_randomness.c @@ -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;