random32: add noise from network and scheduling activity
[sfrench/cifs-2.6.git] / lib / random32.c
index be9f242a420754c44c7788178ad4ae023a0fbf99..7f047844e494aafd4cbdb42b905e0554b32aad52 100644 (file)
@@ -337,6 +337,8 @@ struct siprand_state {
 };
 
 static DEFINE_PER_CPU(struct siprand_state, net_rand_state) __latent_entropy;
+DEFINE_PER_CPU(unsigned long, net_rand_noise);
+EXPORT_PER_CPU_SYMBOL(net_rand_noise);
 
 /*
  * This is the core CPRNG function.  As "pseudorandom", this is not used
@@ -360,9 +362,12 @@ static DEFINE_PER_CPU(struct siprand_state, net_rand_state) __latent_entropy;
 static inline u32 siprand_u32(struct siprand_state *s)
 {
        unsigned long v0 = s->v0, v1 = s->v1, v2 = s->v2, v3 = s->v3;
+       unsigned long n = raw_cpu_read(net_rand_noise);
 
+       v3 ^= n;
        PRND_SIPROUND(v0, v1, v2, v3);
        PRND_SIPROUND(v0, v1, v2, v3);
+       v0 ^= n;
        s->v0 = v0;  s->v1 = v1;  s->v2 = v2;  s->v3 = v3;
        return v1 + v3;
 }