diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/random32.c | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/lib/random32.c b/lib/random32.c index 217d5c4b666d..870dc3fc0f0f 100644 --- a/lib/random32.c +++ b/lib/random32.c | |||
@@ -39,13 +39,16 @@ | |||
39 | #include <linux/jiffies.h> | 39 | #include <linux/jiffies.h> |
40 | #include <linux/random.h> | 40 | #include <linux/random.h> |
41 | 41 | ||
42 | struct rnd_state { | ||
43 | u32 s1, s2, s3; | ||
44 | }; | ||
45 | |||
46 | static DEFINE_PER_CPU(struct rnd_state, net_rand_state); | 42 | static DEFINE_PER_CPU(struct rnd_state, net_rand_state); |
47 | 43 | ||
48 | static u32 __random32(struct rnd_state *state) | 44 | /** |
45 | * prandom32 - seeded pseudo-random number generator. | ||
46 | * @state: pointer to state structure holding seeded state. | ||
47 | * | ||
48 | * This is used for pseudo-randomness with no outside seeding. | ||
49 | * For more random results, use random32(). | ||
50 | */ | ||
51 | u32 prandom32(struct rnd_state *state) | ||
49 | { | 52 | { |
50 | #define TAUSWORTHE(s,a,b,c,d) ((s&c)<<d) ^ (((s <<a) ^ s)>>b) | 53 | #define TAUSWORTHE(s,a,b,c,d) ((s&c)<<d) ^ (((s <<a) ^ s)>>b) |
51 | 54 | ||
@@ -55,14 +58,7 @@ static u32 __random32(struct rnd_state *state) | |||
55 | 58 | ||
56 | return (state->s1 ^ state->s2 ^ state->s3); | 59 | return (state->s1 ^ state->s2 ^ state->s3); |
57 | } | 60 | } |
58 | 61 | EXPORT_SYMBOL(prandom32); | |
59 | /* | ||
60 | * Handle minimum values for seeds | ||
61 | */ | ||
62 | static inline u32 __seed(u32 x, u32 m) | ||
63 | { | ||
64 | return (x < m) ? x + m : x; | ||
65 | } | ||
66 | 62 | ||
67 | /** | 63 | /** |
68 | * random32 - pseudo random number generator | 64 | * random32 - pseudo random number generator |
@@ -75,7 +71,7 @@ u32 random32(void) | |||
75 | { | 71 | { |
76 | unsigned long r; | 72 | unsigned long r; |
77 | struct rnd_state *state = &get_cpu_var(net_rand_state); | 73 | struct rnd_state *state = &get_cpu_var(net_rand_state); |
78 | r = __random32(state); | 74 | r = prandom32(state); |
79 | put_cpu_var(state); | 75 | put_cpu_var(state); |
80 | return r; | 76 | return r; |
81 | } | 77 | } |
@@ -118,12 +114,12 @@ static int __init random32_init(void) | |||
118 | state->s3 = __seed(LCG(state->s2), 15); | 114 | state->s3 = __seed(LCG(state->s2), 15); |
119 | 115 | ||
120 | /* "warm it up" */ | 116 | /* "warm it up" */ |
121 | __random32(state); | 117 | prandom32(state); |
122 | __random32(state); | 118 | prandom32(state); |
123 | __random32(state); | 119 | prandom32(state); |
124 | __random32(state); | 120 | prandom32(state); |
125 | __random32(state); | 121 | prandom32(state); |
126 | __random32(state); | 122 | prandom32(state); |
127 | } | 123 | } |
128 | return 0; | 124 | return 0; |
129 | } | 125 | } |
@@ -147,7 +143,7 @@ static int __init random32_reseed(void) | |||
147 | state->s3 = __seed(seeds[2], 15); | 143 | state->s3 = __seed(seeds[2], 15); |
148 | 144 | ||
149 | /* mix it in */ | 145 | /* mix it in */ |
150 | __random32(state); | 146 | prandom32(state); |
151 | } | 147 | } |
152 | return 0; | 148 | return 0; |
153 | } | 149 | } |