diff options
author | Daniel Borkmann <daniel@iogearbox.net> | 2015-10-07 19:20:38 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-10-08 08:26:38 -0400 |
commit | 897ece56e714a2cc64e6914cb89a362d7021b36e (patch) | |
tree | c965cddb6a87f0bc6d96cceaa36efe42af8158da /include | |
parent | 0dd50d1b0c003ab4f17597fe1198bb57a2fadc06 (diff) |
random32: add prandom_init_once helper for own rngs
Add a prandom_init_once() facility that works on the rnd_state, so that
users that are keeping their own state independent from prandom_u32() can
initialize their taus113 per cpu states.
The motivation here is similar to net_get_random_once(): initialize the
state as late as possible in the hope that enough entropy has been
collected for the seeding. prandom_init_once() makes use of the recently
introduced prandom_seed_full_state() helper and is generic enough so that
it could also be used on fast-paths due to the DO_ONCE().
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/random.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/include/linux/random.h b/include/linux/random.h index e651874df2c9..a75840c1aa71 100644 --- a/include/linux/random.h +++ b/include/linux/random.h | |||
@@ -7,6 +7,8 @@ | |||
7 | #define _LINUX_RANDOM_H | 7 | #define _LINUX_RANDOM_H |
8 | 8 | ||
9 | #include <linux/list.h> | 9 | #include <linux/list.h> |
10 | #include <linux/once.h> | ||
11 | |||
10 | #include <uapi/linux/random.h> | 12 | #include <uapi/linux/random.h> |
11 | 13 | ||
12 | struct random_ready_callback { | 14 | struct random_ready_callback { |
@@ -45,6 +47,10 @@ struct rnd_state { | |||
45 | 47 | ||
46 | u32 prandom_u32_state(struct rnd_state *state); | 48 | u32 prandom_u32_state(struct rnd_state *state); |
47 | void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes); | 49 | void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes); |
50 | void prandom_seed_full_state(struct rnd_state __percpu *pcpu_state); | ||
51 | |||
52 | #define prandom_init_once(pcpu_state) \ | ||
53 | DO_ONCE(prandom_seed_full_state, (pcpu_state)) | ||
48 | 54 | ||
49 | /** | 55 | /** |
50 | * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro) | 56 | * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro) |