diff options
Diffstat (limited to 'include/linux/random.h')
-rw-r--r-- | include/linux/random.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/include/linux/random.h b/include/linux/random.h index 25d02fe5c9b5..fb7ab9de5f36 100644 --- a/include/linux/random.h +++ b/include/linux/random.h | |||
@@ -40,6 +40,10 @@ struct rand_pool_info { | |||
40 | __u32 buf[0]; | 40 | __u32 buf[0]; |
41 | }; | 41 | }; |
42 | 42 | ||
43 | struct rnd_state { | ||
44 | __u32 s1, s2, s3; | ||
45 | }; | ||
46 | |||
43 | /* Exported functions */ | 47 | /* Exported functions */ |
44 | 48 | ||
45 | #ifdef __KERNEL__ | 49 | #ifdef __KERNEL__ |
@@ -74,6 +78,30 @@ unsigned long randomize_range(unsigned long start, unsigned long end, unsigned l | |||
74 | u32 random32(void); | 78 | u32 random32(void); |
75 | void srandom32(u32 seed); | 79 | void srandom32(u32 seed); |
76 | 80 | ||
81 | u32 prandom32(struct rnd_state *); | ||
82 | |||
83 | /* | ||
84 | * Handle minimum values for seeds | ||
85 | */ | ||
86 | static inline u32 __seed(u32 x, u32 m) | ||
87 | { | ||
88 | return (x < m) ? x + m : x; | ||
89 | } | ||
90 | |||
91 | /** | ||
92 | * prandom32_seed - set seed for prandom32(). | ||
93 | * @state: pointer to state structure to receive the seed. | ||
94 | * @seed: arbitrary 64-bit value to use as a seed. | ||
95 | */ | ||
96 | static inline void prandom32_seed(struct rnd_state *state, u64 seed) | ||
97 | { | ||
98 | u32 i = (seed >> 32) ^ (seed << 10) ^ seed; | ||
99 | |||
100 | state->s1 = __seed(i, 1); | ||
101 | state->s2 = __seed(i, 7); | ||
102 | state->s3 = __seed(i, 15); | ||
103 | } | ||
104 | |||
77 | #endif /* __KERNEL___ */ | 105 | #endif /* __KERNEL___ */ |
78 | 106 | ||
79 | #endif /* _LINUX_RANDOM_H */ | 107 | #endif /* _LINUX_RANDOM_H */ |