diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/random32.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/random32.c b/lib/random32.c index 01e8890d1089..12215df701e8 100644 --- a/lib/random32.c +++ b/lib/random32.c | |||
| @@ -142,6 +142,7 @@ void prandom_seed(u32 entropy) | |||
| 142 | for_each_possible_cpu (i) { | 142 | for_each_possible_cpu (i) { |
| 143 | struct rnd_state *state = &per_cpu(net_rand_state, i); | 143 | struct rnd_state *state = &per_cpu(net_rand_state, i); |
| 144 | state->s1 = __seed(state->s1 ^ entropy, 2); | 144 | state->s1 = __seed(state->s1 ^ entropy, 2); |
| 145 | prandom_u32_state(state); | ||
| 145 | } | 146 | } |
| 146 | } | 147 | } |
| 147 | EXPORT_SYMBOL(prandom_seed); | 148 | EXPORT_SYMBOL(prandom_seed); |
| @@ -174,6 +175,27 @@ static int __init prandom_init(void) | |||
| 174 | } | 175 | } |
| 175 | core_initcall(prandom_init); | 176 | core_initcall(prandom_init); |
| 176 | 177 | ||
| 178 | static void __prandom_timer(unsigned long dontcare); | ||
| 179 | static DEFINE_TIMER(seed_timer, __prandom_timer, 0, 0); | ||
| 180 | |||
| 181 | static void __prandom_timer(unsigned long dontcare) | ||
| 182 | { | ||
| 183 | u32 entropy; | ||
| 184 | |||
| 185 | get_random_bytes(&entropy, sizeof(entropy)); | ||
| 186 | prandom_seed(entropy); | ||
| 187 | /* reseed every ~60 seconds, in [40 .. 80) interval with slack */ | ||
| 188 | seed_timer.expires = jiffies + (40 * HZ + (prandom_u32() % (40 * HZ))); | ||
| 189 | add_timer(&seed_timer); | ||
| 190 | } | ||
| 191 | |||
| 192 | static void prandom_start_seed_timer(void) | ||
| 193 | { | ||
| 194 | set_timer_slack(&seed_timer, HZ); | ||
| 195 | seed_timer.expires = jiffies + 40 * HZ; | ||
| 196 | add_timer(&seed_timer); | ||
| 197 | } | ||
| 198 | |||
| 177 | /* | 199 | /* |
| 178 | * Generate better values after random number generator | 200 | * Generate better values after random number generator |
| 179 | * is fully initialized. | 201 | * is fully initialized. |
| @@ -194,6 +216,7 @@ static int __init prandom_reseed(void) | |||
| 194 | /* mix it in */ | 216 | /* mix it in */ |
| 195 | prandom_u32_state(state); | 217 | prandom_u32_state(state); |
| 196 | } | 218 | } |
| 219 | prandom_start_seed_timer(); | ||
| 197 | return 0; | 220 | return 0; |
| 198 | } | 221 | } |
| 199 | late_initcall(prandom_reseed); | 222 | late_initcall(prandom_reseed); |
