diff options
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/net.h | 2 | ||||
| -rw-r--r-- | include/linux/once.h | 2 | ||||
| -rw-r--r-- | include/linux/random.h | 26 |
3 files changed, 30 insertions, 0 deletions
diff --git a/include/linux/net.h b/include/linux/net.h index abcfa46a2bd9..dda2cc939a53 100644 --- a/include/linux/net.h +++ b/include/linux/net.h | |||
| @@ -274,6 +274,8 @@ do { \ | |||
| 274 | 274 | ||
| 275 | #define net_get_random_once(buf, nbytes) \ | 275 | #define net_get_random_once(buf, nbytes) \ |
| 276 | get_random_once((buf), (nbytes)) | 276 | get_random_once((buf), (nbytes)) |
| 277 | #define net_get_random_once_wait(buf, nbytes) \ | ||
| 278 | get_random_once_wait((buf), (nbytes)) | ||
| 277 | 279 | ||
| 278 | int kernel_sendmsg(struct socket *sock, struct msghdr *msg, struct kvec *vec, | 280 | int kernel_sendmsg(struct socket *sock, struct msghdr *msg, struct kvec *vec, |
| 279 | size_t num, size_t len); | 281 | size_t num, size_t len); |
diff --git a/include/linux/once.h b/include/linux/once.h index 285f12cb40e6..9c98aaa87cbc 100644 --- a/include/linux/once.h +++ b/include/linux/once.h | |||
| @@ -53,5 +53,7 @@ void __do_once_done(bool *done, struct static_key *once_key, | |||
| 53 | 53 | ||
| 54 | #define get_random_once(buf, nbytes) \ | 54 | #define get_random_once(buf, nbytes) \ |
| 55 | DO_ONCE(get_random_bytes, (buf), (nbytes)) | 55 | DO_ONCE(get_random_bytes, (buf), (nbytes)) |
| 56 | #define get_random_once_wait(buf, nbytes) \ | ||
| 57 | DO_ONCE(get_random_bytes_wait, (buf), (nbytes)) \ | ||
| 56 | 58 | ||
| 57 | #endif /* _LINUX_ONCE_H */ | 59 | #endif /* _LINUX_ONCE_H */ |
diff --git a/include/linux/random.h b/include/linux/random.h index 1fa0dc880bd7..eafea6a09361 100644 --- a/include/linux/random.h +++ b/include/linux/random.h | |||
| @@ -34,6 +34,7 @@ extern void add_input_randomness(unsigned int type, unsigned int code, | |||
| 34 | extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy; | 34 | extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy; |
| 35 | 35 | ||
| 36 | extern void get_random_bytes(void *buf, int nbytes); | 36 | extern void get_random_bytes(void *buf, int nbytes); |
| 37 | extern int wait_for_random_bytes(void); | ||
| 37 | extern int add_random_ready_callback(struct random_ready_callback *rdy); | 38 | extern int add_random_ready_callback(struct random_ready_callback *rdy); |
| 38 | extern void del_random_ready_callback(struct random_ready_callback *rdy); | 39 | extern void del_random_ready_callback(struct random_ready_callback *rdy); |
| 39 | extern void get_random_bytes_arch(void *buf, int nbytes); | 40 | extern void get_random_bytes_arch(void *buf, int nbytes); |
| @@ -78,6 +79,31 @@ static inline unsigned long get_random_canary(void) | |||
| 78 | return val & CANARY_MASK; | 79 | return val & CANARY_MASK; |
| 79 | } | 80 | } |
| 80 | 81 | ||
| 82 | /* Calls wait_for_random_bytes() and then calls get_random_bytes(buf, nbytes). | ||
| 83 | * Returns the result of the call to wait_for_random_bytes. */ | ||
| 84 | static inline int get_random_bytes_wait(void *buf, int nbytes) | ||
| 85 | { | ||
| 86 | int ret = wait_for_random_bytes(); | ||
| 87 | if (unlikely(ret)) | ||
| 88 | return ret; | ||
| 89 | get_random_bytes(buf, nbytes); | ||
| 90 | return 0; | ||
| 91 | } | ||
| 92 | |||
| 93 | #define declare_get_random_var_wait(var) \ | ||
| 94 | static inline int get_random_ ## var ## _wait(var *out) { \ | ||
| 95 | int ret = wait_for_random_bytes(); \ | ||
| 96 | if (unlikely(ret)) \ | ||
| 97 | return ret; \ | ||
| 98 | *out = get_random_ ## var(); \ | ||
| 99 | return 0; \ | ||
| 100 | } | ||
| 101 | declare_get_random_var_wait(u32) | ||
| 102 | declare_get_random_var_wait(u64) | ||
| 103 | declare_get_random_var_wait(int) | ||
| 104 | declare_get_random_var_wait(long) | ||
| 105 | #undef declare_get_random_var | ||
| 106 | |||
| 81 | unsigned long randomize_page(unsigned long start, unsigned long range); | 107 | unsigned long randomize_page(unsigned long start, unsigned long range); |
| 82 | 108 | ||
| 83 | u32 prandom_u32(void); | 109 | u32 prandom_u32(void); |
