diff options
author | Akinobu Mita <akinobu.mita@gmail.com> | 2012-12-17 19:04:23 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-12-17 20:15:26 -0500 |
commit | 496f2f93b1cc286f5a4f4f9acdc1e5314978683f (patch) | |
tree | 464fa6bd115ad4e3bedc02a0b0796a9f9e055ccc /lib | |
parent | 31279b1457f992f24eee8d45ddd647f5fce42cf6 (diff) |
random32: rename random32 to prandom
This renames all random32 functions to have 'prandom_' prefix as follows:
void prandom_seed(u32 seed); /* rename from srandom32() */
u32 prandom_u32(void); /* rename from random32() */
void prandom_seed_state(struct rnd_state *state, u64 seed);
/* rename from prandom32_seed() */
u32 prandom_u32_state(struct rnd_state *state);
/* rename from prandom32() */
The purpose of this renaming is to prevent some kernel developers from
assuming that prandom32() and random32() might imply that only
prandom32() was the one using a pseudo-random number generator by
prandom32's "p", and the result may be a very embarassing security
exposure. This concern was expressed by Theodore Ts'o.
And furthermore, I'm going to introduce new functions for getting the
requested number of pseudo-random bytes. If I continue to use both
prandom32 and random32 prefixes for these functions, the confusion
is getting worse.
As a result of this renaming, "prandom_" is the common prefix for
pseudo-random number library.
Currently, srandom32() and random32() are preserved because it is
difficult to rename too many users at once.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Robert Love <robert.w.love@intel.com>
Cc: Michel Lespinasse <walken@google.com>
Cc: Valdis Kletnieks <valdis.kletnieks@vt.edu>
Cc: David Laight <david.laight@aculab.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Artem Bityutskiy <dedekind1@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Eilon Greenstein <eilong@broadcom.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/interval_tree_test_main.c | 7 | ||||
-rw-r--r-- | lib/random32.c | 48 | ||||
-rw-r--r-- | lib/rbtree_test.c | 6 |
3 files changed, 31 insertions, 30 deletions
diff --git a/lib/interval_tree_test_main.c b/lib/interval_tree_test_main.c index b25903987f7a..245900b98c8e 100644 --- a/lib/interval_tree_test_main.c +++ b/lib/interval_tree_test_main.c | |||
@@ -30,7 +30,8 @@ static void init(void) | |||
30 | { | 30 | { |
31 | int i; | 31 | int i; |
32 | for (i = 0; i < NODES; i++) { | 32 | for (i = 0; i < NODES; i++) { |
33 | u32 a = prandom32(&rnd), b = prandom32(&rnd); | 33 | u32 a = prandom_u32_state(&rnd); |
34 | u32 b = prandom_u32_state(&rnd); | ||
34 | if (a <= b) { | 35 | if (a <= b) { |
35 | nodes[i].start = a; | 36 | nodes[i].start = a; |
36 | nodes[i].last = b; | 37 | nodes[i].last = b; |
@@ -40,7 +41,7 @@ static void init(void) | |||
40 | } | 41 | } |
41 | } | 42 | } |
42 | for (i = 0; i < SEARCHES; i++) | 43 | for (i = 0; i < SEARCHES; i++) |
43 | queries[i] = prandom32(&rnd); | 44 | queries[i] = prandom_u32_state(&rnd); |
44 | } | 45 | } |
45 | 46 | ||
46 | static int interval_tree_test_init(void) | 47 | static int interval_tree_test_init(void) |
@@ -51,7 +52,7 @@ static int interval_tree_test_init(void) | |||
51 | 52 | ||
52 | printk(KERN_ALERT "interval tree insert/remove"); | 53 | printk(KERN_ALERT "interval tree insert/remove"); |
53 | 54 | ||
54 | prandom32_seed(&rnd, 3141592653589793238ULL); | 55 | prandom_seed_state(&rnd, 3141592653589793238ULL); |
55 | init(); | 56 | init(); |
56 | 57 | ||
57 | time1 = get_cycles(); | 58 | time1 = get_cycles(); |
diff --git a/lib/random32.c b/lib/random32.c index 938bde5876ac..d1830fade915 100644 --- a/lib/random32.c +++ b/lib/random32.c | |||
@@ -42,13 +42,13 @@ | |||
42 | static DEFINE_PER_CPU(struct rnd_state, net_rand_state); | 42 | static DEFINE_PER_CPU(struct rnd_state, net_rand_state); |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * prandom32 - seeded pseudo-random number generator. | 45 | * prandom_u32_state - seeded pseudo-random number generator. |
46 | * @state: pointer to state structure holding seeded state. | 46 | * @state: pointer to state structure holding seeded state. |
47 | * | 47 | * |
48 | * This is used for pseudo-randomness with no outside seeding. | 48 | * This is used for pseudo-randomness with no outside seeding. |
49 | * For more random results, use random32(). | 49 | * For more random results, use prandom_u32(). |
50 | */ | 50 | */ |
51 | u32 prandom32(struct rnd_state *state) | 51 | u32 prandom_u32_state(struct rnd_state *state) |
52 | { | 52 | { |
53 | #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) |
54 | 54 | ||
@@ -58,32 +58,32 @@ u32 prandom32(struct rnd_state *state) | |||
58 | 58 | ||
59 | return (state->s1 ^ state->s2 ^ state->s3); | 59 | return (state->s1 ^ state->s2 ^ state->s3); |
60 | } | 60 | } |
61 | EXPORT_SYMBOL(prandom32); | 61 | EXPORT_SYMBOL(prandom_u32_state); |
62 | 62 | ||
63 | /** | 63 | /** |
64 | * random32 - pseudo random number generator | 64 | * prandom_u32 - pseudo random number generator |
65 | * | 65 | * |
66 | * A 32 bit pseudo-random number is generated using a fast | 66 | * A 32 bit pseudo-random number is generated using a fast |
67 | * algorithm suitable for simulation. This algorithm is NOT | 67 | * algorithm suitable for simulation. This algorithm is NOT |
68 | * considered safe for cryptographic use. | 68 | * considered safe for cryptographic use. |
69 | */ | 69 | */ |
70 | u32 random32(void) | 70 | u32 prandom_u32(void) |
71 | { | 71 | { |
72 | unsigned long r; | 72 | unsigned long r; |
73 | struct rnd_state *state = &get_cpu_var(net_rand_state); | 73 | struct rnd_state *state = &get_cpu_var(net_rand_state); |
74 | r = prandom32(state); | 74 | r = prandom_u32_state(state); |
75 | put_cpu_var(state); | 75 | put_cpu_var(state); |
76 | return r; | 76 | return r; |
77 | } | 77 | } |
78 | EXPORT_SYMBOL(random32); | 78 | EXPORT_SYMBOL(prandom_u32); |
79 | 79 | ||
80 | /** | 80 | /** |
81 | * srandom32 - add entropy to pseudo random number generator | 81 | * prandom_seed - add entropy to pseudo random number generator |
82 | * @seed: seed value | 82 | * @seed: seed value |
83 | * | 83 | * |
84 | * Add some additional seeding to the random32() pool. | 84 | * Add some additional seeding to the prandom pool. |
85 | */ | 85 | */ |
86 | void srandom32(u32 entropy) | 86 | void prandom_seed(u32 entropy) |
87 | { | 87 | { |
88 | int i; | 88 | int i; |
89 | /* | 89 | /* |
@@ -95,13 +95,13 @@ void srandom32(u32 entropy) | |||
95 | state->s1 = __seed(state->s1 ^ entropy, 1); | 95 | state->s1 = __seed(state->s1 ^ entropy, 1); |
96 | } | 96 | } |
97 | } | 97 | } |
98 | EXPORT_SYMBOL(srandom32); | 98 | EXPORT_SYMBOL(prandom_seed); |
99 | 99 | ||
100 | /* | 100 | /* |
101 | * Generate some initially weak seeding values to allow | 101 | * Generate some initially weak seeding values to allow |
102 | * to start the random32() engine. | 102 | * to start the prandom_u32() engine. |
103 | */ | 103 | */ |
104 | static int __init random32_init(void) | 104 | static int __init prandom_init(void) |
105 | { | 105 | { |
106 | int i; | 106 | int i; |
107 | 107 | ||
@@ -114,22 +114,22 @@ static int __init random32_init(void) | |||
114 | state->s3 = __seed(LCG(state->s2), 15); | 114 | state->s3 = __seed(LCG(state->s2), 15); |
115 | 115 | ||
116 | /* "warm it up" */ | 116 | /* "warm it up" */ |
117 | prandom32(state); | 117 | prandom_u32_state(state); |
118 | prandom32(state); | 118 | prandom_u32_state(state); |
119 | prandom32(state); | 119 | prandom_u32_state(state); |
120 | prandom32(state); | 120 | prandom_u32_state(state); |
121 | prandom32(state); | 121 | prandom_u32_state(state); |
122 | prandom32(state); | 122 | prandom_u32_state(state); |
123 | } | 123 | } |
124 | return 0; | 124 | return 0; |
125 | } | 125 | } |
126 | core_initcall(random32_init); | 126 | core_initcall(prandom_init); |
127 | 127 | ||
128 | /* | 128 | /* |
129 | * Generate better values after random number generator | 129 | * Generate better values after random number generator |
130 | * is fully initialized. | 130 | * is fully initialized. |
131 | */ | 131 | */ |
132 | static int __init random32_reseed(void) | 132 | static int __init prandom_reseed(void) |
133 | { | 133 | { |
134 | int i; | 134 | int i; |
135 | 135 | ||
@@ -143,8 +143,8 @@ static int __init random32_reseed(void) | |||
143 | state->s3 = __seed(seeds[2], 15); | 143 | state->s3 = __seed(seeds[2], 15); |
144 | 144 | ||
145 | /* mix it in */ | 145 | /* mix it in */ |
146 | prandom32(state); | 146 | prandom_u32_state(state); |
147 | } | 147 | } |
148 | return 0; | 148 | return 0; |
149 | } | 149 | } |
150 | late_initcall(random32_reseed); | 150 | late_initcall(prandom_reseed); |
diff --git a/lib/rbtree_test.c b/lib/rbtree_test.c index d7f491a54579..af38aedbd874 100644 --- a/lib/rbtree_test.c +++ b/lib/rbtree_test.c | |||
@@ -96,8 +96,8 @@ static void init(void) | |||
96 | { | 96 | { |
97 | int i; | 97 | int i; |
98 | for (i = 0; i < NODES; i++) { | 98 | for (i = 0; i < NODES; i++) { |
99 | nodes[i].key = prandom32(&rnd); | 99 | nodes[i].key = prandom_u32_state(&rnd); |
100 | nodes[i].val = prandom32(&rnd); | 100 | nodes[i].val = prandom_u32_state(&rnd); |
101 | } | 101 | } |
102 | } | 102 | } |
103 | 103 | ||
@@ -155,7 +155,7 @@ static int rbtree_test_init(void) | |||
155 | 155 | ||
156 | printk(KERN_ALERT "rbtree testing"); | 156 | printk(KERN_ALERT "rbtree testing"); |
157 | 157 | ||
158 | prandom32_seed(&rnd, 3141592653589793238ULL); | 158 | prandom_seed_state(&rnd, 3141592653589793238ULL); |
159 | init(); | 159 | init(); |
160 | 160 | ||
161 | time1 = get_cycles(); | 161 | time1 = get_cycles(); |