* [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes()
@ 2012-11-13 13:36 Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 01/11] random32: rename random32 to prandom Akinobu Mita
` (11 more replies)
0 siblings, 12 replies; 13+ messages in thread
From: Akinobu Mita @ 2012-11-13 13:36 UTC (permalink / raw)
To: linux-kernel, akpm
Cc: Akinobu Mita, Theodore Ts'o, Artem Bityutskiy, Adrian Hunter,
David Woodhouse, linux-mtd, Eilon Greenstein, netdev,
Robert Love, devel, Michel Lespinasse
This patchset introduces new functions into random32 library for
getting the requested number of pseudo-random bytes.
Before introducing these new functions into random32 library,
rename all random32 functions to have 'prandom_' prefix. As a result
the function prototypes are as follows:
void prandom_seed(u32 seed); /* rename from srandom32() */
u32 prandom_u32(void); /* rename from random32() */
void prandom_bytes(void *buf, int nbytes);
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() */
void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
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.
Changelog
* v3
- change common prefix from 'random32_' to 'prandom_'
- ensure prandom_bytes_state() generates same bytes with same rnd_state
* v2
- rename prandom32 to random32_state
- dropped lib/uuid.c patch
- add bnx2 and mtd_stresstest patches
Akinobu Mita (11):
random32: rename random32 to prandom
prandom: introduce prandom_bytes() and prandom_bytes_state()
bnx2x: use prandom_bytes()
mtd: nandsim: use prandom_bytes
ubifs: use prandom_bytes
mtd: mtd_nandecctest: use prandom_bytes instead of get_random_bytes()
mtd: mtd_oobtest: convert to use prandom library
mtd: mtd_pagetest: convert to use prandom library
mtd: mtd_speedtest: use prandom_bytes
mtd: mtd_subpagetest: convert to use prandom library
mtd: mtd_stresstest: use prandom_bytes()
drivers/mtd/nand/nandsim.c | 5 +-
drivers/mtd/tests/mtd_nandecctest.c | 2 +-
drivers/mtd/tests/mtd_oobtest.c | 49 ++++---------
drivers/mtd/tests/mtd_pagetest.c | 43 ++++-------
drivers/mtd/tests/mtd_speedtest.c | 9 +--
drivers/mtd/tests/mtd_stresstest.c | 3 +-
drivers/mtd/tests/mtd_subpagetest.c | 42 +++--------
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 5 +-
drivers/scsi/fcoe/fcoe_ctlr.c | 4 +-
fs/ubifs/debug.c | 8 +-
include/linux/random.h | 19 +++--
lib/interval_tree_test_main.c | 7 +-
lib/random32.c | 97 +++++++++++++++++++------
lib/rbtree_test.c | 6 +-
14 files changed, 145 insertions(+), 154 deletions(-)
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Artem Bityutskiy <dedekind1@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
Cc: Eilon Greenstein <eilong@broadcom.com>
Cc: netdev@vger.kernel.org
Cc: Robert Love <robert.w.love@intel.com>
Cc: devel@open-fcoe.org
Cc: Michel Lespinasse <walken@google.com>
--
1.7.11.7
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v3 01/11] random32: rename random32 to prandom
2012-11-13 13:36 [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Akinobu Mita
@ 2012-11-13 13:37 ` Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 02/11] prandom: introduce prandom_bytes() and prandom_bytes_state() Akinobu Mita
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Akinobu Mita @ 2012-11-13 13:37 UTC (permalink / raw)
To: linux-kernel, akpm
Cc: Akinobu Mita, Theodore Ts'o, Robert Love, devel,
Michel Lespinasse, Valdis Kletnieks, David Laight
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: devel@open-fcoe.org
Cc: Michel Lespinasse <walken@google.com>
Cc: Valdis Kletnieks <valdis.kletnieks@vt.edu>
Cc: David Laight <david.laight@aculab.com>
---
* v3
- change common prefix from 'random32_' to 'prandom_'
drivers/scsi/fcoe/fcoe_ctlr.c | 4 ++--
include/linux/random.h | 17 ++++++++++-----
lib/interval_tree_test_main.c | 7 ++++---
lib/random32.c | 48 +++++++++++++++++++++----------------------
lib/rbtree_test.c | 6 +++---
5 files changed, 45 insertions(+), 37 deletions(-)
diff --git a/drivers/scsi/fcoe/fcoe_ctlr.c b/drivers/scsi/fcoe/fcoe_ctlr.c
index 2ebe03a..4a909d7 100644
--- a/drivers/scsi/fcoe/fcoe_ctlr.c
+++ b/drivers/scsi/fcoe/fcoe_ctlr.c
@@ -2144,7 +2144,7 @@ static void fcoe_ctlr_vn_restart(struct fcoe_ctlr *fip)
*/
port_id = fip->port_id;
if (fip->probe_tries)
- port_id = prandom32(&fip->rnd_state) & 0xffff;
+ port_id = prandom_u32_state(&fip->rnd_state) & 0xffff;
else if (!port_id)
port_id = fip->lp->wwpn & 0xffff;
if (!port_id || port_id == 0xffff)
@@ -2169,7 +2169,7 @@ static void fcoe_ctlr_vn_restart(struct fcoe_ctlr *fip)
static void fcoe_ctlr_vn_start(struct fcoe_ctlr *fip)
{
fip->probe_tries = 0;
- prandom32_seed(&fip->rnd_state, fip->lp->wwpn);
+ prandom_seed_state(&fip->rnd_state, fip->lp->wwpn);
fcoe_ctlr_vn_restart(fip);
}
diff --git a/include/linux/random.h b/include/linux/random.h
index 6330ed4..db6debc 100644
--- a/include/linux/random.h
+++ b/include/linux/random.h
@@ -25,10 +25,17 @@ extern const struct file_operations random_fops, urandom_fops;
unsigned int get_random_int(void);
unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
-u32 random32(void);
-void srandom32(u32 seed);
+u32 prandom_u32(void);
+void prandom_seed(u32 seed);
-u32 prandom32(struct rnd_state *);
+/*
+ * These macros are preserved for backward compatibility and should be
+ * removed as soon as a transition is finished.
+ */
+#define random32() prandom_u32()
+#define srandom32(seed) prandom_seed(seed)
+
+u32 prandom_u32_state(struct rnd_state *);
/*
* Handle minimum values for seeds
@@ -39,11 +46,11 @@ static inline u32 __seed(u32 x, u32 m)
}
/**
- * prandom32_seed - set seed for prandom32().
+ * prandom_seed_state - set seed for prandom_u32_state().
* @state: pointer to state structure to receive the seed.
* @seed: arbitrary 64-bit value to use as a seed.
*/
-static inline void prandom32_seed(struct rnd_state *state, u64 seed)
+static inline void prandom_seed_state(struct rnd_state *state, u64 seed)
{
u32 i = (seed >> 32) ^ (seed << 10) ^ seed;
diff --git a/lib/interval_tree_test_main.c b/lib/interval_tree_test_main.c
index b259039..245900b 100644
--- a/lib/interval_tree_test_main.c
+++ b/lib/interval_tree_test_main.c
@@ -30,7 +30,8 @@ static void init(void)
{
int i;
for (i = 0; i < NODES; i++) {
- u32 a = prandom32(&rnd), b = prandom32(&rnd);
+ u32 a = prandom_u32_state(&rnd);
+ u32 b = prandom_u32_state(&rnd);
if (a <= b) {
nodes[i].start = a;
nodes[i].last = b;
@@ -40,7 +41,7 @@ static void init(void)
}
}
for (i = 0; i < SEARCHES; i++)
- queries[i] = prandom32(&rnd);
+ queries[i] = prandom_u32_state(&rnd);
}
static int interval_tree_test_init(void)
@@ -51,7 +52,7 @@ static int interval_tree_test_init(void)
printk(KERN_ALERT "interval tree insert/remove");
- prandom32_seed(&rnd, 3141592653589793238ULL);
+ prandom_seed_state(&rnd, 3141592653589793238ULL);
init();
time1 = get_cycles();
diff --git a/lib/random32.c b/lib/random32.c
index 938bde5..d1830fa 100644
--- a/lib/random32.c
+++ b/lib/random32.c
@@ -42,13 +42,13 @@
static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
/**
- * prandom32 - seeded pseudo-random number generator.
+ * prandom_u32_state - seeded pseudo-random number generator.
* @state: pointer to state structure holding seeded state.
*
* This is used for pseudo-randomness with no outside seeding.
- * For more random results, use random32().
+ * For more random results, use prandom_u32().
*/
-u32 prandom32(struct rnd_state *state)
+u32 prandom_u32_state(struct rnd_state *state)
{
#define TAUSWORTHE(s,a,b,c,d) ((s&c)<<d) ^ (((s <<a) ^ s)>>b)
@@ -58,32 +58,32 @@ u32 prandom32(struct rnd_state *state)
return (state->s1 ^ state->s2 ^ state->s3);
}
-EXPORT_SYMBOL(prandom32);
+EXPORT_SYMBOL(prandom_u32_state);
/**
- * random32 - pseudo random number generator
+ * prandom_u32 - pseudo random number generator
*
* A 32 bit pseudo-random number is generated using a fast
* algorithm suitable for simulation. This algorithm is NOT
* considered safe for cryptographic use.
*/
-u32 random32(void)
+u32 prandom_u32(void)
{
unsigned long r;
struct rnd_state *state = &get_cpu_var(net_rand_state);
- r = prandom32(state);
+ r = prandom_u32_state(state);
put_cpu_var(state);
return r;
}
-EXPORT_SYMBOL(random32);
+EXPORT_SYMBOL(prandom_u32);
/**
- * srandom32 - add entropy to pseudo random number generator
+ * prandom_seed - add entropy to pseudo random number generator
* @seed: seed value
*
- * Add some additional seeding to the random32() pool.
+ * Add some additional seeding to the prandom pool.
*/
-void srandom32(u32 entropy)
+void prandom_seed(u32 entropy)
{
int i;
/*
@@ -95,13 +95,13 @@ void srandom32(u32 entropy)
state->s1 = __seed(state->s1 ^ entropy, 1);
}
}
-EXPORT_SYMBOL(srandom32);
+EXPORT_SYMBOL(prandom_seed);
/*
* Generate some initially weak seeding values to allow
- * to start the random32() engine.
+ * to start the prandom_u32() engine.
*/
-static int __init random32_init(void)
+static int __init prandom_init(void)
{
int i;
@@ -114,22 +114,22 @@ static int __init random32_init(void)
state->s3 = __seed(LCG(state->s2), 15);
/* "warm it up" */
- prandom32(state);
- prandom32(state);
- prandom32(state);
- prandom32(state);
- prandom32(state);
- prandom32(state);
+ prandom_u32_state(state);
+ prandom_u32_state(state);
+ prandom_u32_state(state);
+ prandom_u32_state(state);
+ prandom_u32_state(state);
+ prandom_u32_state(state);
}
return 0;
}
-core_initcall(random32_init);
+core_initcall(prandom_init);
/*
* Generate better values after random number generator
* is fully initialized.
*/
-static int __init random32_reseed(void)
+static int __init prandom_reseed(void)
{
int i;
@@ -143,8 +143,8 @@ static int __init random32_reseed(void)
state->s3 = __seed(seeds[2], 15);
/* mix it in */
- prandom32(state);
+ prandom_u32_state(state);
}
return 0;
}
-late_initcall(random32_reseed);
+late_initcall(prandom_reseed);
diff --git a/lib/rbtree_test.c b/lib/rbtree_test.c
index 268b239..da96578 100644
--- a/lib/rbtree_test.c
+++ b/lib/rbtree_test.c
@@ -96,8 +96,8 @@ static void init(void)
{
int i;
for (i = 0; i < NODES; i++) {
- nodes[i].key = prandom32(&rnd);
- nodes[i].val = prandom32(&rnd);
+ nodes[i].key = prandom_u32_state(&rnd);
+ nodes[i].val = prandom_u32_state(&rnd);
}
}
@@ -155,7 +155,7 @@ static int rbtree_test_init(void)
printk(KERN_ALERT "rbtree testing");
- prandom32_seed(&rnd, 3141592653589793238ULL);
+ prandom_seed_state(&rnd, 3141592653589793238ULL);
init();
time1 = get_cycles();
--
1.7.11.7
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v3 02/11] prandom: introduce prandom_bytes() and prandom_bytes_state()
2012-11-13 13:36 [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 01/11] random32: rename random32 to prandom Akinobu Mita
@ 2012-11-13 13:37 ` Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 03/11] bnx2x: use prandom_bytes() Akinobu Mita
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Akinobu Mita @ 2012-11-13 13:37 UTC (permalink / raw)
To: linux-kernel, akpm
Cc: Akinobu Mita, Theodore Ts'o, Artem Bityutskiy, Adrian Hunter,
David Woodhouse, linux-mtd, Eilon Greenstein, netdev
Add functions to get the requested number of pseudo-random bytes.
The difference from get_random_bytes() is that it generates pseudo-random
numbers by prandom_u32(). It doesn't consume the entropy pool, and the
sequence is reproducible if the same rnd_state is used. So it is suitable
for generating random bytes for testing.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Artem Bityutskiy <dedekind1@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
Cc: Eilon Greenstein <eilong@broadcom.com>
Cc: netdev@vger.kernel.org
---
* v3
- rename random32_get_bytes_state to prandom_bytes_state
- ensure prandom_bytes_state() generates same bytes with same rnd_state
* v2
- rename prandom32_get_bytes to random32_get_bytes_state
include/linux/random.h | 2 ++
lib/random32.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+)
diff --git a/include/linux/random.h b/include/linux/random.h
index db6debc..d984608 100644
--- a/include/linux/random.h
+++ b/include/linux/random.h
@@ -26,6 +26,7 @@ unsigned int get_random_int(void);
unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
u32 prandom_u32(void);
+void prandom_bytes(void *buf, int nbytes);
void prandom_seed(u32 seed);
/*
@@ -36,6 +37,7 @@ void prandom_seed(u32 seed);
#define srandom32(seed) prandom_seed(seed)
u32 prandom_u32_state(struct rnd_state *);
+void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
/*
* Handle minimum values for seeds
diff --git a/lib/random32.c b/lib/random32.c
index d1830fa..52280d5 100644
--- a/lib/random32.c
+++ b/lib/random32.c
@@ -77,6 +77,55 @@ u32 prandom_u32(void)
}
EXPORT_SYMBOL(prandom_u32);
+/*
+ * prandom_bytes_state - get the requested number of pseudo-random bytes
+ *
+ * @state: pointer to state structure holding seeded state.
+ * @buf: where to copy the pseudo-random bytes to
+ * @bytes: the requested number of bytes
+ *
+ * This is used for pseudo-randomness with no outside seeding.
+ * For more random results, use prandom_bytes().
+ */
+void prandom_bytes_state(struct rnd_state *state, void *buf, int bytes)
+{
+ unsigned char *p = buf;
+ int i;
+
+ for (i = 0; i < round_down(bytes, sizeof(u32)); i += sizeof(u32)) {
+ u32 random = prandom_u32_state(state);
+ int j;
+
+ for (j = 0; j < sizeof(u32); j++) {
+ p[i + j] = random;
+ random >>= BITS_PER_BYTE;
+ }
+ }
+ if (i < bytes) {
+ u32 random = prandom_u32_state(state);
+
+ for (; i < bytes; i++) {
+ p[i] = random;
+ random >>= BITS_PER_BYTE;
+ }
+ }
+}
+EXPORT_SYMBOL(prandom_bytes_state);
+
+/**
+ * prandom_bytes - get the requested number of pseudo-random bytes
+ * @buf: where to copy the pseudo-random bytes to
+ * @bytes: the requested number of bytes
+ */
+void prandom_bytes(void *buf, int bytes)
+{
+ struct rnd_state *state = &get_cpu_var(net_rand_state);
+
+ prandom_bytes_state(state, buf, bytes);
+ put_cpu_var(state);
+}
+EXPORT_SYMBOL(prandom_bytes);
+
/**
* prandom_seed - add entropy to pseudo random number generator
* @seed: seed value
--
1.7.11.7
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v3 03/11] bnx2x: use prandom_bytes()
2012-11-13 13:36 [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 01/11] random32: rename random32 to prandom Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 02/11] prandom: introduce prandom_bytes() and prandom_bytes_state() Akinobu Mita
@ 2012-11-13 13:37 ` Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 04/11] mtd: nandsim: use prandom_bytes Akinobu Mita
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Akinobu Mita @ 2012-11-13 13:37 UTC (permalink / raw)
To: linux-kernel, akpm; +Cc: Akinobu Mita, Eilon Greenstein, netdev
Use prandom_bytes() to fill rss key with pseudo-random bytes.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Eilon Greenstein <eilong@broadcom.com>
Cc: netdev@vger.kernel.org
---
* v3
- rename random32_get_bytes to prandom_bytes
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index 4833b6a..257d38b 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -1741,7 +1741,6 @@ int bnx2x_config_rss_pf(struct bnx2x *bp, struct bnx2x_rss_config_obj *rss_obj,
bool config_hash)
{
struct bnx2x_config_rss_params params = {NULL};
- int i;
/* Although RSS is meaningless when there is a single HW queue we
* still need it enabled in order to have HW Rx hash generated.
@@ -1773,9 +1772,7 @@ int bnx2x_config_rss_pf(struct bnx2x *bp, struct bnx2x_rss_config_obj *rss_obj,
if (config_hash) {
/* RSS keys */
- for (i = 0; i < sizeof(params.rss_key) / 4; i++)
- params.rss_key[i] = random32();
-
+ prandom_bytes(params.rss_key, sizeof(params.rss_key));
__set_bit(BNX2X_RSS_SET_SRCH, ¶ms.rss_flags);
}
--
1.7.11.7
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v3 04/11] mtd: nandsim: use prandom_bytes
2012-11-13 13:36 [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Akinobu Mita
` (2 preceding siblings ...)
2012-11-13 13:37 ` [PATCH v3 03/11] bnx2x: use prandom_bytes() Akinobu Mita
@ 2012-11-13 13:37 ` Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 05/11] ubifs: " Akinobu Mita
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Akinobu Mita @ 2012-11-13 13:37 UTC (permalink / raw)
To: linux-kernel, akpm
Cc: Akinobu Mita, Artem Bityutskiy, David Woodhouse, linux-mtd
This also removes unnecessary memset call which is immediately overwritten
with random bytes.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Artem Bityutskiy <dedekind1@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
---
* v3
- rename random32_get_bytes to prandom_bytes
drivers/mtd/nand/nandsim.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
index a932c48..c3c13e6 100644
--- a/drivers/mtd/nand/nandsim.c
+++ b/drivers/mtd/nand/nandsim.c
@@ -1397,10 +1397,7 @@ int do_read_error(struct nandsim *ns, int num)
unsigned int page_no = ns->regs.row;
if (read_error(page_no)) {
- int i;
- memset(ns->buf.byte, 0xFF, num);
- for (i = 0; i < num; ++i)
- ns->buf.byte[i] = random32();
+ prandom_bytes(ns->buf.byte, num);
NS_WARN("simulating read error in page %u\n", page_no);
return 1;
}
--
1.7.11.7
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v3 05/11] ubifs: use prandom_bytes
2012-11-13 13:36 [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Akinobu Mita
` (3 preceding siblings ...)
2012-11-13 13:37 ` [PATCH v3 04/11] mtd: nandsim: use prandom_bytes Akinobu Mita
@ 2012-11-13 13:37 ` Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 06/11] mtd: mtd_nandecctest: use prandom_bytes instead of get_random_bytes() Akinobu Mita
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Akinobu Mita @ 2012-11-13 13:37 UTC (permalink / raw)
To: linux-kernel, akpm
Cc: Akinobu Mita, Artem Bityutskiy, Adrian Hunter, linux-mtd
This also converts filling memory loop to use memset.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Artem Bityutskiy <dedekind1@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: linux-mtd@lists.infradead.org
---
* v3
- rename random32_get_bytes to prandom_bytes
fs/ubifs/debug.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
index 6291163..12817ff 100644
--- a/fs/ubifs/debug.c
+++ b/fs/ubifs/debug.c
@@ -2560,7 +2560,7 @@ static int power_cut_emulated(struct ubifs_info *c, int lnum, int write)
static int corrupt_data(const struct ubifs_info *c, const void *buf,
unsigned int len)
{
- unsigned int from, to, i, ffs = chance(1, 2);
+ unsigned int from, to, ffs = chance(1, 2);
unsigned char *p = (void *)buf;
from = random32() % (len + 1);
@@ -2571,11 +2571,9 @@ static int corrupt_data(const struct ubifs_info *c, const void *buf,
ffs ? "0xFFs" : "random data");
if (ffs)
- for (i = from; i < to; i++)
- p[i] = 0xFF;
+ memset(p + from, 0xFF, to - from);
else
- for (i = from; i < to; i++)
- p[i] = random32() % 0x100;
+ prandom_bytes(p + from, to - from);
return to;
}
--
1.7.11.7
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v3 06/11] mtd: mtd_nandecctest: use prandom_bytes instead of get_random_bytes()
2012-11-13 13:36 [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Akinobu Mita
` (4 preceding siblings ...)
2012-11-13 13:37 ` [PATCH v3 05/11] ubifs: " Akinobu Mita
@ 2012-11-13 13:37 ` Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 07/11] mtd: mtd_oobtest: convert to use prandom library Akinobu Mita
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Akinobu Mita @ 2012-11-13 13:37 UTC (permalink / raw)
To: linux-kernel, akpm
Cc: Akinobu Mita, Artem Bityutskiy, David Woodhouse, linux-mtd
Using prandom_bytes() is enough. Because this data is only used
for testing, not used for cryptographic use.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Artem Bityutskiy <dedekind1@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
---
* v3
- rename random32_get_bytes to prandom_bytes
drivers/mtd/tests/mtd_nandecctest.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mtd/tests/mtd_nandecctest.c b/drivers/mtd/tests/mtd_nandecctest.c
index a5fb9b0..9b7b9fa 100644
--- a/drivers/mtd/tests/mtd_nandecctest.c
+++ b/drivers/mtd/tests/mtd_nandecctest.c
@@ -253,7 +253,7 @@ static int nand_ecc_test_run(const size_t size)
goto error;
}
- get_random_bytes(correct_data, size);
+ prandom_bytes(correct_data, size);
__nand_calculate_ecc(correct_data, size, correct_ecc);
for (i = 0; i < ARRAY_SIZE(nand_ecc_test); i++) {
--
1.7.11.7
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v3 07/11] mtd: mtd_oobtest: convert to use prandom library
2012-11-13 13:36 [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Akinobu Mita
` (5 preceding siblings ...)
2012-11-13 13:37 ` [PATCH v3 06/11] mtd: mtd_nandecctest: use prandom_bytes instead of get_random_bytes() Akinobu Mita
@ 2012-11-13 13:37 ` Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 08/11] mtd: mtd_pagetest: " Akinobu Mita
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Akinobu Mita @ 2012-11-13 13:37 UTC (permalink / raw)
To: linux-kernel, akpm
Cc: Akinobu Mita, Artem Bityutskiy, David Woodhouse, linux-mtd
This removes home-brewed pseudo-random number generator and use
prandom library.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Artem Bityutskiy <dedekind1@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
---
* v3
- rename 'random32_*' to 'prandom_*'
* v2
- rename prandom32_get_bytes to random32_get_bytes_state
drivers/mtd/tests/mtd_oobtest.c | 49 ++++++++++++++---------------------------
1 file changed, 16 insertions(+), 33 deletions(-)
diff --git a/drivers/mtd/tests/mtd_oobtest.c b/drivers/mtd/tests/mtd_oobtest.c
index ed9b628..81d02e2 100644
--- a/drivers/mtd/tests/mtd_oobtest.c
+++ b/drivers/mtd/tests/mtd_oobtest.c
@@ -27,6 +27,7 @@
#include <linux/mtd/mtd.h>
#include <linux/slab.h>
#include <linux/sched.h>
+#include <linux/random.h>
#define PRINT_PREF KERN_INFO "mtd_oobtest: "
@@ -46,26 +47,7 @@ static int use_offset;
static int use_len;
static int use_len_max;
static int vary_offset;
-static unsigned long next = 1;
-
-static inline unsigned int simple_rand(void)
-{
- next = next * 1103515245 + 12345;
- return (unsigned int)((next / 65536) % 32768);
-}
-
-static inline void simple_srand(unsigned long seed)
-{
- next = seed;
-}
-
-static void set_random_data(unsigned char *buf, size_t len)
-{
- size_t i;
-
- for (i = 0; i < len; ++i)
- buf[i] = simple_rand();
-}
+static struct rnd_state rnd_state;
static int erase_eraseblock(int ebnum)
{
@@ -130,7 +112,7 @@ static int write_eraseblock(int ebnum)
loff_t addr = ebnum * mtd->erasesize;
for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) {
- set_random_data(writebuf, use_len);
+ prandom_bytes_state(&rnd_state, writebuf, use_len);
ops.mode = MTD_OPS_AUTO_OOB;
ops.len = 0;
ops.retlen = 0;
@@ -183,7 +165,7 @@ static int verify_eraseblock(int ebnum)
loff_t addr = ebnum * mtd->erasesize;
for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) {
- set_random_data(writebuf, use_len);
+ prandom_bytes_state(&rnd_state, writebuf, use_len);
ops.mode = MTD_OPS_AUTO_OOB;
ops.len = 0;
ops.retlen = 0;
@@ -275,7 +257,7 @@ static int verify_eraseblock_in_one_go(int ebnum)
loff_t addr = ebnum * mtd->erasesize;
size_t len = mtd->ecclayout->oobavail * pgcnt;
- set_random_data(writebuf, len);
+ prandom_bytes_state(&rnd_state, writebuf, len);
ops.mode = MTD_OPS_AUTO_OOB;
ops.len = 0;
ops.retlen = 0;
@@ -426,12 +408,12 @@ static int __init mtd_oobtest_init(void)
if (err)
goto out;
- simple_srand(1);
+ prandom_seed_state(&rnd_state, 1);
err = write_whole_device();
if (err)
goto out;
- simple_srand(1);
+ prandom_seed_state(&rnd_state, 1);
err = verify_all_eraseblocks();
if (err)
goto out;
@@ -446,13 +428,13 @@ static int __init mtd_oobtest_init(void)
if (err)
goto out;
- simple_srand(3);
+ prandom_seed_state(&rnd_state, 3);
err = write_whole_device();
if (err)
goto out;
/* Check all eraseblocks */
- simple_srand(3);
+ prandom_seed_state(&rnd_state, 3);
printk(PRINT_PREF "verifying all eraseblocks\n");
for (i = 0; i < ebcnt; ++i) {
if (bbt[i])
@@ -481,7 +463,7 @@ static int __init mtd_oobtest_init(void)
use_len = mtd->ecclayout->oobavail;
use_len_max = mtd->ecclayout->oobavail;
vary_offset = 1;
- simple_srand(5);
+ prandom_seed_state(&rnd_state, 5);
err = write_whole_device();
if (err)
@@ -492,7 +474,7 @@ static int __init mtd_oobtest_init(void)
use_len = mtd->ecclayout->oobavail;
use_len_max = mtd->ecclayout->oobavail;
vary_offset = 1;
- simple_srand(5);
+ prandom_seed_state(&rnd_state, 5);
err = verify_all_eraseblocks();
if (err)
goto out;
@@ -651,7 +633,7 @@ static int __init mtd_oobtest_init(void)
goto out;
/* Write all eraseblocks */
- simple_srand(11);
+ prandom_seed_state(&rnd_state, 11);
printk(PRINT_PREF "writing OOBs of whole device\n");
for (i = 0; i < ebcnt - 1; ++i) {
int cnt = 2;
@@ -661,7 +643,7 @@ static int __init mtd_oobtest_init(void)
continue;
addr = (i + 1) * mtd->erasesize - mtd->writesize;
for (pg = 0; pg < cnt; ++pg) {
- set_random_data(writebuf, sz);
+ prandom_bytes_state(&rnd_state, writebuf, sz);
ops.mode = MTD_OPS_AUTO_OOB;
ops.len = 0;
ops.retlen = 0;
@@ -683,12 +665,13 @@ static int __init mtd_oobtest_init(void)
printk(PRINT_PREF "written %u eraseblocks\n", i);
/* Check all eraseblocks */
- simple_srand(11);
+ prandom_seed_state(&rnd_state, 11);
printk(PRINT_PREF "verifying all eraseblocks\n");
for (i = 0; i < ebcnt - 1; ++i) {
if (bbt[i] || bbt[i + 1])
continue;
- set_random_data(writebuf, mtd->ecclayout->oobavail * 2);
+ prandom_bytes_state(&rnd_state, writebuf,
+ mtd->ecclayout->oobavail * 2);
addr = (i + 1) * mtd->erasesize - mtd->writesize;
ops.mode = MTD_OPS_AUTO_OOB;
ops.len = 0;
--
1.7.11.7
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v3 08/11] mtd: mtd_pagetest: convert to use prandom library
2012-11-13 13:36 [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Akinobu Mita
` (6 preceding siblings ...)
2012-11-13 13:37 ` [PATCH v3 07/11] mtd: mtd_oobtest: convert to use prandom library Akinobu Mita
@ 2012-11-13 13:37 ` Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 09/11] mtd: mtd_speedtest: use prandom_bytes Akinobu Mita
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Akinobu Mita @ 2012-11-13 13:37 UTC (permalink / raw)
To: linux-kernel, akpm
Cc: Akinobu Mita, Artem Bityutskiy, David Woodhouse, linux-mtd
This removes home-brewed pseudo-random number generator and use
prandom library.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Artem Bityutskiy <dedekind1@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
---
* v3
- rename 'random32_*' to 'prandom_*'
* v2
- rename prandom32_get_bytes to random32_get_bytes_state
drivers/mtd/tests/mtd_pagetest.c | 43 ++++++++++++----------------------------
1 file changed, 13 insertions(+), 30 deletions(-)
diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c
index 252ddb0..4197280 100644
--- a/drivers/mtd/tests/mtd_pagetest.c
+++ b/drivers/mtd/tests/mtd_pagetest.c
@@ -27,6 +27,7 @@
#include <linux/mtd/mtd.h>
#include <linux/slab.h>
#include <linux/sched.h>
+#include <linux/random.h>
#define PRINT_PREF KERN_INFO "mtd_pagetest: "
@@ -45,26 +46,7 @@ static int bufsize;
static int ebcnt;
static int pgcnt;
static int errcnt;
-static unsigned long next = 1;
-
-static inline unsigned int simple_rand(void)
-{
- next = next * 1103515245 + 12345;
- return (unsigned int)((next / 65536) % 32768);
-}
-
-static inline void simple_srand(unsigned long seed)
-{
- next = seed;
-}
-
-static void set_random_data(unsigned char *buf, size_t len)
-{
- size_t i;
-
- for (i = 0; i < len; ++i)
- buf[i] = simple_rand();
-}
+static struct rnd_state rnd_state;
static int erase_eraseblock(int ebnum)
{
@@ -98,7 +80,7 @@ static int write_eraseblock(int ebnum)
size_t written;
loff_t addr = ebnum * mtd->erasesize;
- set_random_data(writebuf, mtd->erasesize);
+ prandom_bytes_state(&rnd_state, writebuf, mtd->erasesize);
cond_resched();
err = mtd_write(mtd, addr, mtd->erasesize, &written, writebuf);
if (err || written != mtd->erasesize)
@@ -124,7 +106,7 @@ static int verify_eraseblock(int ebnum)
for (i = 0; i < ebcnt && bbt[ebcnt - i - 1]; ++i)
addrn -= mtd->erasesize;
- set_random_data(writebuf, mtd->erasesize);
+ prandom_bytes_state(&rnd_state, writebuf, mtd->erasesize);
for (j = 0; j < pgcnt - 1; ++j, addr += pgsize) {
/* Do a read to set the internal dataRAMs to different data */
err = mtd_read(mtd, addr0, bufsize, &read, twopages);
@@ -160,7 +142,8 @@ static int verify_eraseblock(int ebnum)
}
/* Check boundary between eraseblocks */
if (addr <= addrn - pgsize - pgsize && !bbt[ebnum + 1]) {
- unsigned long oldnext = next;
+ struct rnd_state old_state = rnd_state;
+
/* Do a read to set the internal dataRAMs to different data */
err = mtd_read(mtd, addr0, bufsize, &read, twopages);
if (mtd_is_bitflip(err))
@@ -188,13 +171,13 @@ static int verify_eraseblock(int ebnum)
return err;
}
memcpy(boundary, writebuf + mtd->erasesize - pgsize, pgsize);
- set_random_data(boundary + pgsize, pgsize);
+ prandom_bytes_state(&rnd_state, boundary + pgsize, pgsize);
if (memcmp(twopages, boundary, bufsize)) {
printk(PRINT_PREF "error: verify failed at %#llx\n",
(long long)addr);
errcnt += 1;
}
- next = oldnext;
+ rnd_state = old_state;
}
return err;
}
@@ -326,7 +309,7 @@ static int erasecrosstest(void)
return err;
printk(PRINT_PREF "writing 1st page of block %d\n", ebnum);
- set_random_data(writebuf, pgsize);
+ prandom_bytes_state(&rnd_state, writebuf, pgsize);
strcpy(writebuf, "There is no data like this!");
err = mtd_write(mtd, addr0, pgsize, &written, writebuf);
if (err || written != pgsize) {
@@ -359,7 +342,7 @@ static int erasecrosstest(void)
return err;
printk(PRINT_PREF "writing 1st page of block %d\n", ebnum);
- set_random_data(writebuf, pgsize);
+ prandom_bytes_state(&rnd_state, writebuf, pgsize);
strcpy(writebuf, "There is no data like this!");
err = mtd_write(mtd, addr0, pgsize, &written, writebuf);
if (err || written != pgsize) {
@@ -417,7 +400,7 @@ static int erasetest(void)
return err;
printk(PRINT_PREF "writing 1st page of block %d\n", ebnum);
- set_random_data(writebuf, pgsize);
+ prandom_bytes_state(&rnd_state, writebuf, pgsize);
err = mtd_write(mtd, addr0, pgsize, &written, writebuf);
if (err || written != pgsize) {
printk(PRINT_PREF "error: write failed at %#llx\n",
@@ -565,7 +548,7 @@ static int __init mtd_pagetest_init(void)
printk(PRINT_PREF "erased %u eraseblocks\n", i);
/* Write all eraseblocks */
- simple_srand(1);
+ prandom_seed_state(&rnd_state, 1);
printk(PRINT_PREF "writing whole device\n");
for (i = 0; i < ebcnt; ++i) {
if (bbt[i])
@@ -580,7 +563,7 @@ static int __init mtd_pagetest_init(void)
printk(PRINT_PREF "written %u eraseblocks\n", i);
/* Check all eraseblocks */
- simple_srand(1);
+ prandom_seed_state(&rnd_state, 1);
printk(PRINT_PREF "verifying all eraseblocks\n");
for (i = 0; i < ebcnt; ++i) {
if (bbt[i])
--
1.7.11.7
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v3 09/11] mtd: mtd_speedtest: use prandom_bytes
2012-11-13 13:36 [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Akinobu Mita
` (7 preceding siblings ...)
2012-11-13 13:37 ` [PATCH v3 08/11] mtd: mtd_pagetest: " Akinobu Mita
@ 2012-11-13 13:37 ` Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 10/11] mtd: mtd_subpagetest: convert to use prandom library Akinobu Mita
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Akinobu Mita @ 2012-11-13 13:37 UTC (permalink / raw)
To: linux-kernel, akpm
Cc: Akinobu Mita, Artem Bityutskiy, David Woodhouse, linux-mtd
Use prandom_bytes instead of equivalent local function.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Artem Bityutskiy <dedekind1@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
---
* v3
- rename random32_get_bytes to prandom_bytes
drivers/mtd/tests/mtd_speedtest.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/drivers/mtd/tests/mtd_speedtest.c b/drivers/mtd/tests/mtd_speedtest.c
index 42b0f74..73e205d 100644
--- a/drivers/mtd/tests/mtd_speedtest.c
+++ b/drivers/mtd/tests/mtd_speedtest.c
@@ -49,13 +49,6 @@ static int pgcnt;
static int goodebcnt;
static struct timeval start, finish;
-static void set_random_data(unsigned char *buf, size_t len)
-{
- size_t i;
-
- for (i = 0; i < len; ++i)
- buf[i] = random32();
-}
static int erase_eraseblock(int ebnum)
{
@@ -396,7 +389,7 @@ static int __init mtd_speedtest_init(void)
goto out;
}
- set_random_data(iobuf, mtd->erasesize);
+ prandom_bytes(iobuf, mtd->erasesize);
err = scan_for_bad_eraseblocks();
if (err)
--
1.7.11.7
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v3 10/11] mtd: mtd_subpagetest: convert to use prandom library
2012-11-13 13:36 [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Akinobu Mita
` (8 preceding siblings ...)
2012-11-13 13:37 ` [PATCH v3 09/11] mtd: mtd_speedtest: use prandom_bytes Akinobu Mita
@ 2012-11-13 13:37 ` Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 11/11] mtd: mtd_stresstest: use prandom_bytes() Akinobu Mita
2012-11-13 19:55 ` [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Andrew Morton
11 siblings, 0 replies; 13+ messages in thread
From: Akinobu Mita @ 2012-11-13 13:37 UTC (permalink / raw)
To: linux-kernel, akpm
Cc: Akinobu Mita, Artem Bityutskiy, David Woodhouse, linux-mtd
This removes home-brewed pseudo-random number generator and use
prandom library.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Artem Bityutskiy <dedekind1@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
---
* v3
- rename 'random32_*' to 'prandom_*'
* v2
- rename prandom32_get_bytes to random32_get_bytes_state
drivers/mtd/tests/mtd_subpagetest.c | 42 +++++++++++--------------------------
1 file changed, 12 insertions(+), 30 deletions(-)
diff --git a/drivers/mtd/tests/mtd_subpagetest.c b/drivers/mtd/tests/mtd_subpagetest.c
index 9667bf5..5b47e2b 100644
--- a/drivers/mtd/tests/mtd_subpagetest.c
+++ b/drivers/mtd/tests/mtd_subpagetest.c
@@ -26,6 +26,7 @@
#include <linux/mtd/mtd.h>
#include <linux/slab.h>
#include <linux/sched.h>
+#include <linux/random.h>
#define PRINT_PREF KERN_INFO "mtd_subpagetest: "
@@ -43,26 +44,7 @@ static int bufsize;
static int ebcnt;
static int pgcnt;
static int errcnt;
-static unsigned long next = 1;
-
-static inline unsigned int simple_rand(void)
-{
- next = next * 1103515245 + 12345;
- return (unsigned int)((next / 65536) % 32768);
-}
-
-static inline void simple_srand(unsigned long seed)
-{
- next = seed;
-}
-
-static void set_random_data(unsigned char *buf, size_t len)
-{
- size_t i;
-
- for (i = 0; i < len; ++i)
- buf[i] = simple_rand();
-}
+static struct rnd_state rnd_state;
static inline void clear_data(unsigned char *buf, size_t len)
{
@@ -119,7 +101,7 @@ static int write_eraseblock(int ebnum)
int err = 0;
loff_t addr = ebnum * mtd->erasesize;
- set_random_data(writebuf, subpgsize);
+ prandom_bytes_state(&rnd_state, writebuf, subpgsize);
err = mtd_write(mtd, addr, subpgsize, &written, writebuf);
if (unlikely(err || written != subpgsize)) {
printk(PRINT_PREF "error: write failed at %#llx\n",
@@ -133,7 +115,7 @@ static int write_eraseblock(int ebnum)
addr += subpgsize;
- set_random_data(writebuf, subpgsize);
+ prandom_bytes_state(&rnd_state, writebuf, subpgsize);
err = mtd_write(mtd, addr, subpgsize, &written, writebuf);
if (unlikely(err || written != subpgsize)) {
printk(PRINT_PREF "error: write failed at %#llx\n",
@@ -157,7 +139,7 @@ static int write_eraseblock2(int ebnum)
for (k = 1; k < 33; ++k) {
if (addr + (subpgsize * k) > (ebnum + 1) * mtd->erasesize)
break;
- set_random_data(writebuf, subpgsize * k);
+ prandom_bytes_state(&rnd_state, writebuf, subpgsize * k);
err = mtd_write(mtd, addr, subpgsize * k, &written, writebuf);
if (unlikely(err || written != subpgsize * k)) {
printk(PRINT_PREF "error: write failed at %#llx\n",
@@ -193,7 +175,7 @@ static int verify_eraseblock(int ebnum)
int err = 0;
loff_t addr = ebnum * mtd->erasesize;
- set_random_data(writebuf, subpgsize);
+ prandom_bytes_state(&rnd_state, writebuf, subpgsize);
clear_data(readbuf, subpgsize);
err = mtd_read(mtd, addr, subpgsize, &read, readbuf);
if (unlikely(err || read != subpgsize)) {
@@ -220,7 +202,7 @@ static int verify_eraseblock(int ebnum)
addr += subpgsize;
- set_random_data(writebuf, subpgsize);
+ prandom_bytes_state(&rnd_state, writebuf, subpgsize);
clear_data(readbuf, subpgsize);
err = mtd_read(mtd, addr, subpgsize, &read, readbuf);
if (unlikely(err || read != subpgsize)) {
@@ -257,7 +239,7 @@ static int verify_eraseblock2(int ebnum)
for (k = 1; k < 33; ++k) {
if (addr + (subpgsize * k) > (ebnum + 1) * mtd->erasesize)
break;
- set_random_data(writebuf, subpgsize * k);
+ prandom_bytes_state(&rnd_state, writebuf, subpgsize * k);
clear_data(readbuf, subpgsize * k);
err = mtd_read(mtd, addr, subpgsize * k, &read, readbuf);
if (unlikely(err || read != subpgsize * k)) {
@@ -430,7 +412,7 @@ static int __init mtd_subpagetest_init(void)
goto out;
printk(PRINT_PREF "writing whole device\n");
- simple_srand(1);
+ prandom_seed_state(&rnd_state, 1);
for (i = 0; i < ebcnt; ++i) {
if (bbt[i])
continue;
@@ -443,7 +425,7 @@ static int __init mtd_subpagetest_init(void)
}
printk(PRINT_PREF "written %u eraseblocks\n", i);
- simple_srand(1);
+ prandom_seed_state(&rnd_state, 1);
printk(PRINT_PREF "verifying all eraseblocks\n");
for (i = 0; i < ebcnt; ++i) {
if (bbt[i])
@@ -466,7 +448,7 @@ static int __init mtd_subpagetest_init(void)
goto out;
/* Write all eraseblocks */
- simple_srand(3);
+ prandom_seed_state(&rnd_state, 3);
printk(PRINT_PREF "writing whole device\n");
for (i = 0; i < ebcnt; ++i) {
if (bbt[i])
@@ -481,7 +463,7 @@ static int __init mtd_subpagetest_init(void)
printk(PRINT_PREF "written %u eraseblocks\n", i);
/* Check all eraseblocks */
- simple_srand(3);
+ prandom_seed_state(&rnd_state, 3);
printk(PRINT_PREF "verifying all eraseblocks\n");
for (i = 0; i < ebcnt; ++i) {
if (bbt[i])
--
1.7.11.7
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v3 11/11] mtd: mtd_stresstest: use prandom_bytes()
2012-11-13 13:36 [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Akinobu Mita
` (9 preceding siblings ...)
2012-11-13 13:37 ` [PATCH v3 10/11] mtd: mtd_subpagetest: convert to use prandom library Akinobu Mita
@ 2012-11-13 13:37 ` Akinobu Mita
2012-11-13 19:55 ` [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Andrew Morton
11 siblings, 0 replies; 13+ messages in thread
From: Akinobu Mita @ 2012-11-13 13:37 UTC (permalink / raw)
To: linux-kernel, akpm
Cc: Akinobu Mita, Artem Bityutskiy, David Woodhouse, linux-mtd
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Artem Bityutskiy <dedekind1@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
---
* v3
- rename random32_get_bytes to prandom_bytes
drivers/mtd/tests/mtd_stresstest.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/mtd/tests/mtd_stresstest.c b/drivers/mtd/tests/mtd_stresstest.c
index cb268ce..3edc79e 100644
--- a/drivers/mtd/tests/mtd_stresstest.c
+++ b/drivers/mtd/tests/mtd_stresstest.c
@@ -282,8 +282,7 @@ static int __init mtd_stresstest_init(void)
}
for (i = 0; i < ebcnt; i++)
offsets[i] = mtd->erasesize;
- for (i = 0; i < bufsize; i++)
- writebuf[i] = random32();
+ prandom_bytes(writebuf, bufsize);
err = scan_for_bad_eraseblocks();
if (err)
--
1.7.11.7
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes()
2012-11-13 13:36 [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Akinobu Mita
` (10 preceding siblings ...)
2012-11-13 13:37 ` [PATCH v3 11/11] mtd: mtd_stresstest: use prandom_bytes() Akinobu Mita
@ 2012-11-13 19:55 ` Andrew Morton
11 siblings, 0 replies; 13+ messages in thread
From: Andrew Morton @ 2012-11-13 19:55 UTC (permalink / raw)
To: Akinobu Mita
Cc: linux-kernel, Theodore Ts'o, Artem Bityutskiy, Adrian Hunter,
David Woodhouse, linux-mtd, Eilon Greenstein, netdev,
Robert Love, devel, Michel Lespinasse
On Tue, 13 Nov 2012 22:36:59 +0900
Akinobu Mita <akinobu.mita@gmail.com> wrote:
> This patchset introduces new functions into random32 library for
> getting the requested number of pseudo-random bytes.
>
> Before introducing these new functions into random32 library,
> rename all random32 functions to have 'prandom_' prefix. As a result
> the function prototypes are as follows:
>
> void prandom_seed(u32 seed); /* rename from srandom32() */
> u32 prandom_u32(void); /* rename from random32() */
> void prandom_bytes(void *buf, int nbytes);
>
> 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() */
> void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
>
> 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.
There were a large number of rejects in MTD code, due to pending
changes in linux-next. It's all quite mechanical stuff which I
fixed up. Please check the result.
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2012-11-13 19:56 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-13 13:36 [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 01/11] random32: rename random32 to prandom Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 02/11] prandom: introduce prandom_bytes() and prandom_bytes_state() Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 03/11] bnx2x: use prandom_bytes() Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 04/11] mtd: nandsim: use prandom_bytes Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 05/11] ubifs: " Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 06/11] mtd: mtd_nandecctest: use prandom_bytes instead of get_random_bytes() Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 07/11] mtd: mtd_oobtest: convert to use prandom library Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 08/11] mtd: mtd_pagetest: " Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 09/11] mtd: mtd_speedtest: use prandom_bytes Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 10/11] mtd: mtd_subpagetest: convert to use prandom library Akinobu Mita
2012-11-13 13:37 ` [PATCH v3 11/11] mtd: mtd_stresstest: use prandom_bytes() Akinobu Mita
2012-11-13 19:55 ` [PATCH v3 00/11] rename random32 to prandom and introduce prandom_bytes() Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).