aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2013-11-11 06:20:32 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-12-08 10:29:24 -0500
commite29507fecb79c00ae76f9ef626d282af8b1f4225 (patch)
tree8317f8069bf13d75975db813c577debf12da1cb5 /lib
parente688cd4d32cfbf0b5198ba95da428038e907e633 (diff)
random32: fix off-by-one in seeding requirement
[ Upstream commit 51c37a70aaa3f95773af560e6db3073520513912 ] For properly initialising the Tausworthe generator [1], we have a strict seeding requirement, that is, s1 > 1, s2 > 7, s3 > 15. Commit 697f8d0348 ("random32: seeding improvement") introduced a __seed() function that imposes boundary checks proposed by the errata paper [2] to properly ensure above conditions. However, we're off by one, as the function is implemented as: "return (x < m) ? x + m : x;", and called with __seed(X, 1), __seed(X, 7), __seed(X, 15). Thus, an unwanted seed of 1, 7, 15 would be possible, whereas the lower boundary should actually be of at least 2, 8, 16, just as GSL does. Fix this, as otherwise an initialization with an unwanted seed could have the effect that Tausworthe's PRNG properties cannot not be ensured. Note that this PRNG is *not* used for cryptography in the kernel. [1] http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme.ps [2] http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme2.ps Joint work with Hannes Frederic Sowa. Fixes: 697f8d0348a6 ("random32: seeding improvement") Cc: Stephen Hemminger <stephen@networkplumber.org> Cc: Florian Weimer <fweimer@redhat.com> Cc: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Daniel Borkmann <dborkman@redhat.com> Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/random32.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/random32.c b/lib/random32.c
index 52280d5526be..01e8890d1089 100644
--- a/lib/random32.c
+++ b/lib/random32.c
@@ -141,7 +141,7 @@ void prandom_seed(u32 entropy)
141 */ 141 */
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, 1); 144 state->s1 = __seed(state->s1 ^ entropy, 2);
145 } 145 }
146} 146}
147EXPORT_SYMBOL(prandom_seed); 147EXPORT_SYMBOL(prandom_seed);
@@ -158,9 +158,9 @@ static int __init prandom_init(void)
158 struct rnd_state *state = &per_cpu(net_rand_state,i); 158 struct rnd_state *state = &per_cpu(net_rand_state,i);
159 159
160#define LCG(x) ((x) * 69069) /* super-duper LCG */ 160#define LCG(x) ((x) * 69069) /* super-duper LCG */
161 state->s1 = __seed(LCG(i + jiffies), 1); 161 state->s1 = __seed(LCG(i + jiffies), 2);
162 state->s2 = __seed(LCG(state->s1), 7); 162 state->s2 = __seed(LCG(state->s1), 8);
163 state->s3 = __seed(LCG(state->s2), 15); 163 state->s3 = __seed(LCG(state->s2), 16);
164 164
165 /* "warm it up" */ 165 /* "warm it up" */
166 prandom_u32_state(state); 166 prandom_u32_state(state);
@@ -187,9 +187,9 @@ static int __init prandom_reseed(void)
187 u32 seeds[3]; 187 u32 seeds[3];
188 188
189 get_random_bytes(&seeds, sizeof(seeds)); 189 get_random_bytes(&seeds, sizeof(seeds));
190 state->s1 = __seed(seeds[0], 1); 190 state->s1 = __seed(seeds[0], 2);
191 state->s2 = __seed(seeds[1], 7); 191 state->s2 = __seed(seeds[1], 8);
192 state->s3 = __seed(seeds[2], 15); 192 state->s3 = __seed(seeds[2], 16);
193 193
194 /* mix it in */ 194 /* mix it in */
195 prandom_u32_state(state); 195 prandom_u32_state(state);