Skip to content

Commit

Permalink
random32: add prandom_init_once helper for own rngs
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Hannes Frederic Sowa <[email protected]>
Acked-by: Alexei Starovoitov <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
borkmann authored and davem330 committed Oct 8, 2015
1 parent 0dd50d1 commit 897ece5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions include/linux/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#define _LINUX_RANDOM_H

#include <linux/list.h>
#include <linux/once.h>

#include <uapi/linux/random.h>

struct random_ready_callback {
Expand Down Expand Up @@ -45,6 +47,10 @@ struct rnd_state {

u32 prandom_u32_state(struct rnd_state *state);
void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes);
void prandom_seed_full_state(struct rnd_state __percpu *pcpu_state);

#define prandom_init_once(pcpu_state) \
DO_ONCE(prandom_seed_full_state, (pcpu_state))

/**
* prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
Expand Down
2 changes: 1 addition & 1 deletion lib/random32.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ static void __init __prandom_start_seed_timer(void)
add_timer(&seed_timer);
}

static void prandom_seed_full_state(struct rnd_state __percpu *pcpu_state)
void prandom_seed_full_state(struct rnd_state __percpu *pcpu_state)
{
int i;

Expand Down

0 comments on commit 897ece5

Please sign in to comment.