Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * include/linux/random.h |
| 3 | * |
| 4 | * Include file for the random number generator. |
| 5 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #ifndef _LINUX_RANDOM_H |
| 7 | #define _LINUX_RANDOM_H |
| 8 | |
Herbert Xu | 205a525 | 2015-06-09 18:19:39 +0800 | [diff] [blame] | 9 | #include <linux/list.h> |
Daniel Borkmann | 897ece5 | 2015-10-08 01:20:38 +0200 | [diff] [blame] | 10 | #include <linux/once.h> |
| 11 | |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 12 | #include <uapi/linux/random.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
Herbert Xu | 205a525 | 2015-06-09 18:19:39 +0800 | [diff] [blame] | 14 | struct random_ready_callback { |
| 15 | struct list_head list; |
| 16 | void (*func)(struct random_ready_callback *rdy); |
| 17 | struct module *owner; |
| 18 | }; |
| 19 | |
Linus Torvalds | a2080a6 | 2012-07-04 11:16:01 -0400 | [diff] [blame] | 20 | extern void add_device_randomness(const void *, unsigned int); |
Emese Revfy | 38addce | 2016-06-20 20:41:19 +0200 | [diff] [blame] | 21 | |
| 22 | #if defined(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) && !defined(__CHECKER__) |
| 23 | static inline void add_latent_entropy(void) |
| 24 | { |
| 25 | add_device_randomness((const void *)&latent_entropy, |
| 26 | sizeof(latent_entropy)); |
| 27 | } |
| 28 | #else |
| 29 | static inline void add_latent_entropy(void) {} |
| 30 | #endif |
| 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | extern void add_input_randomness(unsigned int type, unsigned int code, |
Emese Revfy | 0766f78 | 2016-06-20 20:42:34 +0200 | [diff] [blame] | 33 | unsigned int value) __latent_entropy; |
| 34 | extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | extern void get_random_bytes(void *buf, int nbytes); |
Herbert Xu | 205a525 | 2015-06-09 18:19:39 +0800 | [diff] [blame] | 37 | extern int add_random_ready_callback(struct random_ready_callback *rdy); |
| 38 | extern void del_random_ready_callback(struct random_ready_callback *rdy); |
Theodore Ts'o | c2557a3 | 2012-07-05 10:35:23 -0400 | [diff] [blame] | 39 | extern void get_random_bytes_arch(void *buf, int nbytes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #ifndef MODULE |
Arjan van de Ven | 5404732 | 2007-02-12 00:55:28 -0800 | [diff] [blame] | 42 | extern const struct file_operations random_fops, urandom_fops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #endif |
| 44 | |
| 45 | unsigned int get_random_int(void); |
Daniel Cashman | ec9ee4a | 2016-02-26 15:19:34 -0800 | [diff] [blame] | 46 | unsigned long get_random_long(void); |
Jason Cooper | 99fdafd | 2016-10-11 13:53:52 -0700 | [diff] [blame] | 47 | unsigned long randomize_page(unsigned long start, unsigned long range); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Joe Eykholt | 5960164 | 2010-05-26 14:44:13 -0700 | [diff] [blame] | 49 | /* |
Linus Torvalds | 8246164 | 2020-07-31 07:51:14 +0200 | [diff] [blame] | 50 | * This is designed to be standalone for just prandom |
| 51 | * users, but for now we include it from <linux/random.h> |
| 52 | * for legacy reasons. |
Joe Eykholt | 5960164 | 2010-05-26 14:44:13 -0700 | [diff] [blame] | 53 | */ |
Linus Torvalds | 8246164 | 2020-07-31 07:51:14 +0200 | [diff] [blame] | 54 | #include <linux/prandom.h> |
Joe Eykholt | 5960164 | 2010-05-26 14:44:13 -0700 | [diff] [blame] | 55 | |
H. Peter Anvin | 63d7717 | 2011-07-31 13:54:50 -0700 | [diff] [blame] | 56 | #ifdef CONFIG_ARCH_RANDOM |
| 57 | # include <asm/archrandom.h> |
| 58 | #else |
H. Peter Anvin | 117780e | 2016-06-08 12:38:38 -0700 | [diff] [blame] | 59 | static inline bool arch_get_random_long(unsigned long *v) |
H. Peter Anvin | 63d7717 | 2011-07-31 13:54:50 -0700 | [diff] [blame] | 60 | { |
| 61 | return 0; |
| 62 | } |
H. Peter Anvin | 117780e | 2016-06-08 12:38:38 -0700 | [diff] [blame] | 63 | static inline bool arch_get_random_int(unsigned int *v) |
H. Peter Anvin | 63d7717 | 2011-07-31 13:54:50 -0700 | [diff] [blame] | 64 | { |
| 65 | return 0; |
| 66 | } |
H. Peter Anvin | 117780e | 2016-06-08 12:38:38 -0700 | [diff] [blame] | 67 | static inline bool arch_has_random(void) |
H. Peter Anvin | 7b878d4 | 2014-03-17 16:36:30 -0700 | [diff] [blame] | 68 | { |
| 69 | return 0; |
| 70 | } |
H. Peter Anvin | 117780e | 2016-06-08 12:38:38 -0700 | [diff] [blame] | 71 | static inline bool arch_get_random_seed_long(unsigned long *v) |
H. Peter Anvin | d20f78d | 2014-03-17 16:36:27 -0700 | [diff] [blame] | 72 | { |
| 73 | return 0; |
| 74 | } |
H. Peter Anvin | 117780e | 2016-06-08 12:38:38 -0700 | [diff] [blame] | 75 | static inline bool arch_get_random_seed_int(unsigned int *v) |
H. Peter Anvin | d20f78d | 2014-03-17 16:36:27 -0700 | [diff] [blame] | 76 | { |
| 77 | return 0; |
| 78 | } |
H. Peter Anvin | 117780e | 2016-06-08 12:38:38 -0700 | [diff] [blame] | 79 | static inline bool arch_has_random_seed(void) |
H. Peter Anvin | 7b878d4 | 2014-03-17 16:36:30 -0700 | [diff] [blame] | 80 | { |
| 81 | return 0; |
| 82 | } |
H. Peter Anvin | 63d7717 | 2011-07-31 13:54:50 -0700 | [diff] [blame] | 83 | #endif |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | #endif /* _LINUX_RANDOM_H */ |