Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Akinobu Mita and committed by
Linus Torvalds
496f2f93 31279b14

+45 -37
+2 -2
drivers/scsi/fcoe/fcoe_ctlr.c
··· 2144 2144 */ 2145 2145 port_id = fip->port_id; 2146 2146 if (fip->probe_tries) 2147 - port_id = prandom32(&fip->rnd_state) & 0xffff; 2147 + port_id = prandom_u32_state(&fip->rnd_state) & 0xffff; 2148 2148 else if (!port_id) 2149 2149 port_id = fip->lp->wwpn & 0xffff; 2150 2150 if (!port_id || port_id == 0xffff) ··· 2169 2169 static void fcoe_ctlr_vn_start(struct fcoe_ctlr *fip) 2170 2170 { 2171 2171 fip->probe_tries = 0; 2172 - prandom32_seed(&fip->rnd_state, fip->lp->wwpn); 2172 + prandom_seed_state(&fip->rnd_state, fip->lp->wwpn); 2173 2173 fcoe_ctlr_vn_restart(fip); 2174 2174 } 2175 2175
+12 -5
include/linux/random.h
··· 25 25 unsigned int get_random_int(void); 26 26 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len); 27 27 28 - u32 random32(void); 29 - void srandom32(u32 seed); 28 + u32 prandom_u32(void); 29 + void prandom_seed(u32 seed); 30 30 31 - u32 prandom32(struct rnd_state *); 31 + /* 32 + * These macros are preserved for backward compatibility and should be 33 + * removed as soon as a transition is finished. 34 + */ 35 + #define random32() prandom_u32() 36 + #define srandom32(seed) prandom_seed(seed) 37 + 38 + u32 prandom_u32_state(struct rnd_state *); 32 39 33 40 /* 34 41 * Handle minimum values for seeds ··· 46 39 } 47 40 48 41 /** 49 - * prandom32_seed - set seed for prandom32(). 42 + * prandom_seed_state - set seed for prandom_u32_state(). 50 43 * @state: pointer to state structure to receive the seed. 51 44 * @seed: arbitrary 64-bit value to use as a seed. 52 45 */ 53 - static inline void prandom32_seed(struct rnd_state *state, u64 seed) 46 + static inline void prandom_seed_state(struct rnd_state *state, u64 seed) 54 47 { 55 48 u32 i = (seed >> 32) ^ (seed << 10) ^ seed; 56 49
+4 -3
lib/interval_tree_test_main.c
··· 30 30 { 31 31 int i; 32 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 35 if (a <= b) { 35 36 nodes[i].start = a; 36 37 nodes[i].last = b; ··· 41 40 } 42 41 } 43 42 for (i = 0; i < SEARCHES; i++) 44 - queries[i] = prandom32(&rnd); 43 + queries[i] = prandom_u32_state(&rnd); 45 44 } 46 45 47 46 static int interval_tree_test_init(void) ··· 52 51 53 52 printk(KERN_ALERT "interval tree insert/remove"); 54 53 55 - prandom32_seed(&rnd, 3141592653589793238ULL); 54 + prandom_seed_state(&rnd, 3141592653589793238ULL); 56 55 init(); 57 56 58 57 time1 = get_cycles();
+24 -24
lib/random32.c
··· 42 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 46 * @state: pointer to state structure holding seeded state. 47 47 * 48 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 53 #define TAUSWORTHE(s,a,b,c,d) ((s&c)<<d) ^ (((s <<a) ^ s)>>b) 54 54 ··· 58 58 59 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 66 * A 32 bit pseudo-random number is generated using a fast 67 67 * algorithm suitable for simulation. This algorithm is NOT 68 68 * considered safe for cryptographic use. 69 69 */ 70 - u32 random32(void) 70 + u32 prandom_u32(void) 71 71 { 72 72 unsigned long r; 73 73 struct rnd_state *state = &get_cpu_var(net_rand_state); 74 - r = prandom32(state); 74 + r = prandom_u32_state(state); 75 75 put_cpu_var(state); 76 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 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 88 int i; 89 89 /* ··· 95 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 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 106 int i; 107 107 ··· 114 114 state->s3 = __seed(LCG(state->s2), 15); 115 115 116 116 /* "warm it up" */ 117 - prandom32(state); 118 - prandom32(state); 119 - prandom32(state); 120 - prandom32(state); 121 - prandom32(state); 122 - prandom32(state); 117 + prandom_u32_state(state); 118 + prandom_u32_state(state); 119 + prandom_u32_state(state); 120 + prandom_u32_state(state); 121 + prandom_u32_state(state); 122 + prandom_u32_state(state); 123 123 } 124 124 return 0; 125 125 } 126 - core_initcall(random32_init); 126 + core_initcall(prandom_init); 127 127 128 128 /* 129 129 * Generate better values after random number generator 130 130 * is fully initialized. 131 131 */ 132 - static int __init random32_reseed(void) 132 + static int __init prandom_reseed(void) 133 133 { 134 134 int i; 135 135 ··· 143 143 state->s3 = __seed(seeds[2], 15); 144 144 145 145 /* mix it in */ 146 - prandom32(state); 146 + prandom_u32_state(state); 147 147 } 148 148 return 0; 149 149 } 150 - late_initcall(random32_reseed); 150 + late_initcall(prandom_reseed);
+3 -3
lib/rbtree_test.c
··· 96 96 { 97 97 int i; 98 98 for (i = 0; i < NODES; i++) { 99 - nodes[i].key = prandom32(&rnd); 100 - nodes[i].val = prandom32(&rnd); 99 + nodes[i].key = prandom_u32_state(&rnd); 100 + nodes[i].val = prandom_u32_state(&rnd); 101 101 } 102 102 } 103 103 ··· 155 155 156 156 printk(KERN_ALERT "rbtree testing"); 157 157 158 - prandom32_seed(&rnd, 3141592653589793238ULL); 158 + prandom_seed_state(&rnd, 3141592653589793238ULL); 159 159 init(); 160 160 161 161 time1 = get_cycles();