On Mon, Jun 13, 2011 at 3:06 PM, Jarod Wilson <jarod@xxxxxxxxxx> wrote: > TSC is high enough resolution that we can use its low-order byte to > stir new data into the random number generator entropy pool. >From what I vaguely remember from years past, rdtsc, especially last few bits of it are not very good as random number source. As they are based on lower bus frequency and a multiplier. May be things have changed these days. Adding Peter and Suresh for comments. Thanks, Venki > > CC: Matt Mackall <mpm@xxxxxxxxxxx> > CC: "Venkatesh Pallipadi (Venki)" <venki@xxxxxxxxxx> > CC: Thomas Gleixner <tglx@xxxxxxxxxxxxx> > CC: Ingo Molnar <mingo@xxxxxxx> > CC: John Stultz <johnstul@xxxxxxxxxx> > CC: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx> > CC: "David S. Miller" <davem@xxxxxxxxxxxxx> > Signed-off-by: Jarod Wilson <jarod@xxxxxxxxxx> > --- > arch/x86/kernel/tsc.c | 18 ++++++++++++++++++ > 1 files changed, 18 insertions(+), 0 deletions(-) > > diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c > index 6cc6922..d206ec3 100644 > --- a/arch/x86/kernel/tsc.c > +++ b/arch/x86/kernel/tsc.c > @@ -10,6 +10,7 @@ > #include <linux/clocksource.h> > #include <linux/percpu.h> > #include <linux/timex.h> > +#include <linux/random.h> > > #include <asm/hpet.h> > #include <asm/timer.h> > @@ -768,11 +769,28 @@ static void resume_tsc(struct clocksource *cs) > clocksource_tsc.cycle_last = 0; > } > > +static void tsc_add_entropy(void) > +{ > + static u64 last; > + u64 counter; > + int delta; > + > + rdtscll(counter); > + delta = (int)(counter - last); > + last = counter; > + > + if (delta == counter) > + return; > + > + add_clocksource_randomness(delta); > +} > + > static struct clocksource clocksource_tsc = { > .name = "tsc", > .rating = 300, > .read = read_tsc, > .resume = resume_tsc, > + .entropy = tsc_add_entropy, > .mask = CLOCKSOURCE_MASK(64), > .flags = CLOCK_SOURCE_IS_CONTINUOUS | > CLOCK_SOURCE_MUST_VERIFY, > -- > 1.7.1 > > -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html